Creating a project
The Justice Data Platform uses a project-based system which will help keep your data assets secure, reproducible and scalable. For the first version of the Justice Data Platform, a project helps you organise and control access to models from the service’s AI gateway.
When you create a project, you can:
- add members to it (optional)
- create an API key
- set the business unit it’s associated with
You can only add members with an @justice.gov.uk email address.
Once you have a working API key, you can use it to access AI models.
Create an API key for your project
After creating your project, follow the steps on the Justice Data Platform to create an API key. Make sure you save the API key in a secure place.
Check your API key works
After you’ve created your API key, make a basic request to the Justice Data Platform’s AI gateway to check it works. You can do this by completing the steps below.
Test your API key in your IDE
Follow OpenAI’s documentation to install an official SDK for your language.
Set your API key as an environment variable using the following command:
export AI_GATEWAY_API_KEY="<your-api-key>"Send an API request in your IDE. You can use the Python example request below, replacing
<model-name>with the model you want to use.import os from openai import OpenAI client = OpenAI( api_key=os.environ["AI_GATEWAY_API_KEY"], base_url="https://ai-gateway.justice.gov.uk/", ) response = client.responses.create( model="<model-name>", input="Reply with: Your API key is working", ) print(response.output_text)Check the response. If successful, you’ll receive
Your API key is workingor a similar response.
Test your API key with curl
If the request in your IDE is successful, you do not need to do this step. You can use it to help identify whether a problem is with your API key or the Justice Data Platform.
Set your API key as an environment variable using the following command:
export AI_GATEWAY_API_KEY="<your-api-key>"Send a request using
curl, replacing placeholders in the example below with your API key and the model you want to use.curl https://ai-gateway.justice.gov.uk/responses \ -H "Authorization: Bearer $AI_GATEWAY_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "<model-name>", "input": "Reply with: Your API key is working" }'Check the response. If successful, you’ll receive
Your API key is workingor a similar response.