API Reference - OpenAI API
API Reference - OpenAI API
Introduction
You can interact with the API through HTTP requests from any language, via our official
Python bindings, our official Node.js library, or a community-maintained library.
To install the official Node.js library, run the following command in your Node.js project
directory:
Authentication
The OpenAI API uses API keys for authentication. Visit your API Keys page to retrieve the
API key you'll use in your requests.
Remember that your API key is a secret! Do not share it with others or expose it in any
client-side code (browsers, apps). Production requests must be routed through your own
backend server where your API key can be securely loaded from an environment variable
or key management service.
All API requests should include your API key in an Authorization HTTP header as
follows:
Organization (optional)
https://platform.openai.com/docs/api-reference/chat/object 1/116
11/23/23, 7:33 PM API Reference - OpenAI API
For users who belong to multiple organizations, you can pass a header to specify which
organization is used for an API request. Usage from these API requests will count as usage
for the specified organization.
1 curl https://api.openai.com/v1/models \
2 -H "Authorization: Bearer $OPENAI_API_KEY" \
3 -H "OpenAI-Organization: org-l9tegHQ5p4LkViUOfcSPjQWo"
Making requests
You can paste the command below into your terminal to run your first API request. Make
sure to replace $OPENAI_API_KEY with your secret API key.
https://platform.openai.com/docs/api-reference/chat/object 2/116
11/23/23, 7:33 PM API Reference - OpenAI API
1 curl https://api.openai.com/v1/chat/completions \
2 -H "Content-Type: application/json" \
3 -H "Authorization: Bearer $OPENAI_API_KEY" \
4 -d '{
5 "model": "gpt-3.5-turbo",
6 "messages": [{"role": "user", "content": "Say this is a test!
7 "temperature": 0.7
8 }'
This request queries the gpt-3.5-turbo model (which under the hood points to the latest
gpt-3.5-turbo model variant) to complete the text starting with a prompt of "Say this is a
test". You should get a response back that resembles the following:
1 {
2 "id": "chatcmpl-abc123",
3 "object": "chat.completion",
4 "created": 1677858242,
5 "model": "gpt-3.5-turbo-1106",
6 "usage": {
7 "prompt_tokens": 13,
8 "completion_tokens": 7,
9 "total_tokens": 20
10 },
11 "choices": [
12 {
13 "message": {
14 "role": "assistant",
15 "content": "\n\nThis is a test!"
16 },
17 "finish_reason": "stop",
18 "index": 0
19 }
20 ]
21 }
Now that you've generated your first chat completion, let's break down the response
object. We can see the finish_reason is stop which means the API returned the full
chat completion generated by the model without running into any limits. In the choices
https://platform.openai.com/docs/api-reference/chat/object 3/116
11/23/23, 7:33 PM API Reference - OpenAI API
list, we only generated a single message but you can set the n parameter to generate
multiple messages choices.
Audio
Learn how to turn audio into text or text into audio.
Create speech
POST https://api.openai.com/v1/audio/speech
Request body
Returns
https://platform.openai.com/docs/api-reference/chat/object 4/116
11/23/23, 7:33 PM API Reference - OpenAI API
1 curl https://api.openai.com/v1/audio/speech \
2 -H "Authorization: Bearer $OPENAI_API_KEY" \
3 -H "Content-Type: application/json" \
4 -d '{
5 "model": "tts-1",
6 "input": "The quick brown fox jumped over the lazy dog.",
7 "voice": "alloy"
8 }' \
9 --output speech.mp3
Create transcription
POST https://api.openai.com/v1/audio/transcriptions
Request body
https://platform.openai.com/docs/api-reference/chat/object 5/116
11/23/23, 7:33 PM API Reference - OpenAI API
Returns
1 curl https://api.openai.com/v1/audio/transcriptions \
2 -H "Authorization: Bearer $OPENAI_API_KEY" \
3 -H "Content-Type: multipart/form-data" \
4 -F file="@/path/to/file/audio.mp3" \
5 -F model="whisper-1"
Response Copy
1 {
2 "text": "Imagine the wildest idea that you've ever had, and you're curious
3 }
Create translation
POST https://api.openai.com/v1/audio/translations
Request body
https://platform.openai.com/docs/api-reference/chat/object 6/116
11/23/23, 7:33 PM API Reference - OpenAI API
Returns
1 curl https://api.openai.com/v1/audio/translations \
2 -H "Authorization: Bearer $OPENAI_API_KEY" \
3 -H "Content-Type: multipart/form-data" \
4 -F file="@/path/to/file/german.m4a" \
5 -F model="whisper-1"
Response Copy
1 {
2 "text": "Hello, my name is Wolfgang and I come from Germany. Where are you
3 }
https://platform.openai.com/docs/api-reference/chat/object 7/116
11/23/23, 7:33 PM API Reference - OpenAI API
Chat
Given a list of messages comprising a conversation, the model will return a response.
id string
A unique identifier for the chat completion.
choices array
A list of chat completion choices. Can be more than one if n is greater than 1.
Show properties
created integer
The Unix timestamp (in seconds) of when the chat completion was created.
model string
The model used for the chat completion.
system_fingerprint string
This fingerprint represents the backend configuration that the model runs with.
Can be used in conjunction with the seed request parameter to understand when backend
changes have been made that might impact determinism.
object string
The object type, which is always chat.completion .
usage object
Usage statistics for the completion request.
Show properties
https://platform.openai.com/docs/api-reference/chat/object 8/116
11/23/23, 7:33 PM API Reference - OpenAI API
1 {
2 "id": "chatcmpl-123",
3 "object": "chat.completion",
4 "created": 1677652288,
5 "model": "gpt-3.5-turbo-0613",
6 "system_fingerprint": "fp_44709d6fcb",
7 "choices": [{
8 "index": 0,
9 "message": {
10 "role": "assistant",
11 "content": "\n\nHello there, how may I assist you today?",
12 },
13 "finish_reason": "stop"
14 }],
15 "usage": {
16 "prompt_tokens": 9,
17 "completion_tokens": 12,
18 "total_tokens": 21
19 }
20 }
id string
A unique identifier for the chat completion. Each chunk has the same ID.
choices array
A list of chat completion choices. Can be more than one if n is greater than 1.
Show properties
created integer
The Unix timestamp (in seconds) of when the chat completion was created. Each chunk has the
same timestamp.
model string
https://platform.openai.com/docs/api-reference/chat/object 9/116
11/23/23, 7:33 PM API Reference - OpenAI API
system_fingerprint string
This fingerprint represents the backend configuration that the model runs with. Can be used in
conjunction with the seed request parameter to understand when backend changes have been
made that might impact determinism.
object string
The object type, which is always chat.completion.chunk .
1 {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"
2
3 {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"
4
5 {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"
6
7 ....
8
9 {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"
10
11 {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"
12
13 {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"
Request body
https://platform.openai.com/docs/api-reference/chat/object 10/116
11/23/23, 7:33 PM API Reference - OpenAI API
Accepts a JSON object that maps tokens (specified by their token ID in the tokenizer) to an
associated bias value from -100 to 100. Mathematically, the bias is added to the logits generated
by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1
should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or
exclusive selection of the relevant token.
The total length of input tokens and generated tokens is limited by the model's context length.
Example Python code for counting tokens.
Setting to { "type": "json_object" } enables JSON mode, which guarantees the message
the model generates is valid JSON.
Important: when using JSON mode, you must also instruct the model to produce JSON yourself
via a system or user message. Without this, the model may generate an unending stream of
whitespace until the generation reaches the token limit, resulting in a long-running and seemingly
"stuck" request. Also note that the message content may be partially cut off if
https://platform.openai.com/docs/api-reference/chat/object 11/116
11/23/23, 7:33 PM API Reference - OpenAI API
none is the default when no functions are present. auto is the default if functions are present.
https://platform.openai.com/docs/api-reference/chat/object 12/116
11/23/23, 7:33 PM API Reference - OpenAI API
Controls which (if any) function is called by the model. none means the model will not call a
function and instead generates a message. auto means the model can pick between
generating a message or calling a function. Specifying a particular function via {"name":
"my_function"} forces the model to call that function.
none is the default when no functions are present. `auto`` is the default if functions are
present.
Show possible types
Returns
Returns a chat completion object, or a streamed sequence of chat completion chunk objects if
the request is streamed.
1 curl https://api.openai.com/v1/chat/completions \
2 -H "Content-Type: application/json" \
3 -H "Authorization: Bearer $OPENAI_API_KEY" \
4 -d '{
5 "model": "gpt-3.5-turbo",
6 "messages": [
7 {
8 "role": "system",
9 "content": "You are a helpful assistant."
10 },
https://platform.openai.com/docs/api-reference/chat/object 13/116
11/23/23, 7:33 PM API Reference - OpenAI API
11 {
12 "role": "user",
13 "content": "Hello!"
14 }
15 ]
16 }'
Response Copy
1 {
2 "id": "chatcmpl-123",
3 "object": "chat.completion",
4 "created": 1677652288,
5 "model": "gpt-3.5-turbo-0613",
6 "system_fingerprint": "fp_44709d6fcb",
7 "choices": [{
8 "index": 0,
9 "message": {
10 "role": "assistant",
11 "content": "\n\nHello there, how may I assist you today?",
12 },
13 "finish_reason": "stop"
14 }],
15 "usage": {
16 "prompt_tokens": 9,
17 "completion_tokens": 12,
18 "total_tokens": 21
19 }
20 }
Embeddings
Get a vector representation of a given input that can be easily consumed by machine
learning models and algorithms.
index integer
The index of the embedding in the list of embeddings.
embedding array
The embedding vector, which is a list of floats. The length of vector depends on the model as
listed in the embedding guide.
object string
The object type, which is always "embedding".
1 {
2 "object": "embedding",
3 "embedding": [
4 0.0023064255,
5 -0.009327292,
6 .... (1536 floats total for ada-002)
7 -0.0028842222,
8 ],
9 "index": 0
10 }
Create embeddings
POST https://api.openai.com/v1/embeddings
Request body
https://platform.openai.com/docs/api-reference/chat/object 15/116
11/23/23, 7:33 PM API Reference - OpenAI API
Returns
1 curl https://api.openai.com/v1/embeddings \
2 -H "Authorization: Bearer $OPENAI_API_KEY" \
3 -H "Content-Type: application/json" \
4 -d '{
5 "input": "The food was delicious and the waiter...",
6 "model": "text-embedding-ada-002",
7 "encoding_format": "float"
8 }'
Response Copy
1 {
2 "object": "list",
3 "data": [
4 {
5 "object": "embedding",
6 "embedding": [
7 0.0023064255,
8 -0.009327292,
9 .... (1536 floats total for ada-002)
10 -0.0028842222,
11 ],
12 "index": 0
13 }
https://platform.openai.com/docs/api-reference/chat/object 16/116
11/23/23, 7:33 PM API Reference - OpenAI API
14 ],
15 "model": "text-embedding-ada-002",
16 "usage": {
17 "prompt_tokens": 8,
18 "total_tokens": 8
19 }
20 }
Fine-tuning
Manage fine-tuning jobs to tailor a model to your specific training data.
id string
The object identifier, which can be referenced in the API endpoints.
created_at integer
The Unix timestamp (in seconds) for when the fine-tuning job was created.
https://platform.openai.com/docs/api-reference/chat/object 17/116
11/23/23, 7:33 PM API Reference - OpenAI API
hyperparameters object
The hyperparameters used for the fine-tuning job. See the fine-tuning guide for more details.
Show properties
model string
The base model that is being fine-tuned.
object string
The object type, which is always "fine_tuning.job".
organization_id string
The organization that owns the fine-tuning job.
result_files array
The compiled results file ID(s) for the fine-tuning job. You can retrieve the results with the Files
API.
status string
The current status of the fine-tuning job, which can be either validating_files , queued ,
running , succeeded , failed , or cancelled .
training_file string
The file ID used for training. You can retrieve the training data with the Files API.
1 {
2 "object": "fine_tuning.job",
3 "id": "ftjob-abc123",
4 "model": "davinci-002",
5 "created_at": 1692661014,
6 "finished_at": 1692661190,
7 "fine_tuned_model": "ft:davinci-002:my-org:custom_suffix:7q8mpxmy",
8 "organization_id": "org-123",
https://platform.openai.com/docs/api-reference/chat/object 18/116
11/23/23, 7:33 PM API Reference - OpenAI API
9 "result_files": [
10 "file-abc123"
11 ],
12 "status": "succeeded",
13 "validation_file": null,
14 "training_file": "file-abc123",
15 "hyperparameters": {
16 "n_epochs": 4,
17 },
18 "trained_tokens": 5768
19 }
Response includes details of the enqueued job including job status and the name of
the fine-tuned models once complete.
Request body
Your dataset must be formatted as a JSONL file. Additionally, you must upload your file with the
purpose fine-tune .
https://platform.openai.com/docs/api-reference/chat/object 19/116
11/23/23, 7:33 PM API Reference - OpenAI API
For example, a suffix of "custom-model-name" would produce a model name like ft:gpt-
3.5-turbo:openai:custom-model-name:7p4lURel .
If you provide this file, the data is used to generate validation metrics periodically during fine-
tuning. These metrics can be viewed in the fine-tuning results file. The same data should not be
present in both train and validation files.
Your dataset must be formatted as a JSONL file. You must upload your file with the purpose
fine-tune .
Returns
A fine-tuning.job object.
1 curl https://api.openai.com/v1/fine_tuning/jobs \
2 -H "Content-Type: application/json" \
3 -H "Authorization: Bearer $OPENAI_API_KEY" \
4 -d '{
5 "training_file": "file-BK7bzQj3FfZFXr7DbL6xJwfo",
6 "model": "gpt-3.5-turbo"
7 }'
Response Copy
1 {
2 "object": "fine_tuning.job",
3 "id": "ftjob-abc123",
4 "model": "gpt-3.5-turbo-0613",
5 "created_at": 1614807352,
6 "fine_tuned_model": null,
7 "organization_id": "org-123",
8 "result_files": [],
https://platform.openai.com/docs/api-reference/chat/object 20/116
11/23/23, 7:33 PM API Reference - OpenAI API
9 "status": "queued",
10 "validation_file": null,
11 "training_file": "file-abc123",
12 }
Query parameters
Returns
1 curl https://api.openai.com/v1/fine_tuning/jobs?limit=2 \
2 -H "Authorization: Bearer $OPENAI_API_KEY"
Response Copy
1 {
2 "object": "list",
3 "data": [
4 {
5 "object": "fine_tuning.job.event",
6 "id": "ft-event-TjX0lMfOniCZX64t9PUQT5hn",
7 "created_at": 1689813489,
https://platform.openai.com/docs/api-reference/chat/object 21/116
11/23/23, 7:33 PM API Reference - OpenAI API
8 "level": "warn",
9 "message": "Fine tuning process stopping due to job cancellation",
10 "data": null,
11 "type": "message"
12 },
13 { ... },
14 { ... }
15 ], "has_more": true
16 }
Path parameters
Returns
1 curl https://api.openai.com/v1/fine_tuning/jobs/ft-AF1WoRqd3aJAHsqc9NY7iL8F \
2 -H "Authorization: Bearer $OPENAI_API_KEY"
Response Copy
1 {
2 "object": "fine_tuning.job",
3 "id": "ftjob-abc123",
https://platform.openai.com/docs/api-reference/chat/object 22/116
11/23/23, 7:33 PM API Reference - OpenAI API
4 "model": "davinci-002",
5 "created_at": 1692661014,
6 "finished_at": 1692661190,
7 "fine_tuned_model": "ft:davinci-002:my-org:custom_suffix:7q8mpxmy",
8 "organization_id": "org-123",
9 "result_files": [
10 "file-abc123"
11 ],
12 "status": "succeeded",
13 "validation_file": null,
14 "training_file": "file-abc123",
15 "hyperparameters": {
16 "n_epochs": 4,
17 },
18 "trained_tokens": 5768
19 }
Cancel fine-tuning
POST https://api.openai.com/v1/fine_tuning/jobs/{fine_tuning_job_id}/cancel
Path parameters
Returns
https://platform.openai.com/docs/api-reference/chat/object 23/116
11/23/23, 7:33 PM API Reference - OpenAI API
Response Copy
1 {
2 "object": "fine_tuning.job",
3 "id": "ftjob-abc123",
4 "model": "gpt-3.5-turbo-0613",
5 "created_at": 1689376978,
6 "fine_tuned_model": null,
7 "organization_id": "org-123",
8 "result_files": [],
9 "hyperparameters": {
10 "n_epochs": "auto"
11 },
12 "status": "cancelled",
13 "validation_file": "file-abc123",
14 "training_file": "file-abc123"
15 }
id string
created_at integer
level string
message string
object string
1 {
2 "object": "fine_tuning.job.event",
3 "id": "ftevent-abc123"
4 "created_at": 1677610602,
5 "level": "info",
https://platform.openai.com/docs/api-reference/chat/object 24/116
11/23/23, 7:33 PM API Reference - OpenAI API
Path parameters
Query parameters
Returns
1 curl https://api.openai.com/v1/fine_tuning/jobs/ftjob-abc123/events \
2 -H "Authorization: Bearer $OPENAI_API_KEY"
Response Copy
1 {
2 "object": "list",
https://platform.openai.com/docs/api-reference/chat/object 25/116
11/23/23, 7:33 PM API Reference - OpenAI API
3 "data": [
4 {
5 "object": "fine_tuning.job.event",
6 "id": "ft-event-ddTJfwuMVpfLXseO0Am0Gqjm",
7 "created_at": 1692407401,
8 "level": "info",
9 "message": "Fine tuning job successfully completed",
10 "data": null,
11 "type": "message"
12 },
13 {
14 "object": "fine_tuning.job.event",
15 "id": "ft-event-tyiGuB72evQncpH87xe505Sv",
16 "created_at": 1692407400,
17 "level": "info",
18 "message": "New fine-tuned model created: ft:gpt-3.5-turbo:openai::7p4
19 "data": null,
20 "type": "message"
21 }
22 ],
23 "has_more": true
24 }
Files
Files are used to upload documents that can be used with features like Assistants and
Fine-tuning.
id string
The file identifier, which can be referenced in the API endpoints.
bytes integer
The size of the file, in bytes.
https://platform.openai.com/docs/api-reference/chat/object 26/116
11/23/23, 7:33 PM API Reference - OpenAI API
created_at integer
The Unix timestamp (in seconds) for when the file was created.
filename string
The name of the file.
object string
The object type, which is always file .
purpose string
The intended purpose of the file. Supported values are fine-tune , fine-tune-results ,
assistants , and assistants_output .
1 {
2 "id": "file-abc123",
3 "object": "file",
4 "bytes": 120000,
5 "created_at": 1677610602,
6 "filename": "salesOverview.pdf",
7 "purpose": "assistants",
8 }
List files
GET https://api.openai.com/v1/files
https://platform.openai.com/docs/api-reference/chat/object 27/116
11/23/23, 7:33 PM API Reference - OpenAI API
Query parameters
Returns
1 curl https://api.openai.com/v1/files \
2 -H "Authorization: Bearer $OPENAI_API_KEY"
Response Copy
1 {
2 "data": [
3 {
4 "id": "file-abc123",
5 "object": "file",
6 "bytes": 175,
7 "created_at": 1613677385,
8 "filename": "salesOverview.pdf",
9 "purpose": "assistants",
10 },
11 {
12 "id": "file-abc123",
13 "object": "file",
14 "bytes": 140,
15 "created_at": 1613779121,
16 "filename": "puppy.jsonl",
17 "purpose": "fine-tune",
18 }
19 ],
20 "object": "list"
21 }
https://platform.openai.com/docs/api-reference/chat/object 28/116
11/23/23, 7:33 PM API Reference - OpenAI API
Upload file
POST https://api.openai.com/v1/files
Upload a file that can be used across various endpoints. The size of all the files
uploaded by one organization can be up to 100 GB.
The size of individual files can be a maximum of 512 MB. See the Assistants Tools
guide to learn more about the types of files supported. The Fine-tuning API only
supports .jsonl files.
Request body
Use "fine-tune" for Fine-tuning and "assistants" for Assistants and Messages. This allows us to
validate the format of the uploaded file is correct for fine-tuning.
Returns
1 curl https://api.openai.com/v1/files \
2 -H "Authorization: Bearer $OPENAI_API_KEY" \
3 -F purpose="fine-tune" \
4 -F file="@mydata.jsonl"
Response Copy
1 {
2 "id": "file-abc123",
https://platform.openai.com/docs/api-reference/chat/object 29/116
11/23/23, 7:33 PM API Reference - OpenAI API
3 "object": "file",
4 "bytes": 120000,
5 "created_at": 1677610602,
6 "filename": "mydata.jsonl",
7 "purpose": "fine-tune",
8 }
Delete file
DELETE https://api.openai.com/v1/files/{file_id}
Delete a file.
Path parameters
Returns
Deletion status.
1 curl https://api.openai.com/v1/files/file-abc123 \
2 -X DELETE \
3 -H "Authorization: Bearer $OPENAI_API_KEY"
Response Copy
1 {
2 "id": "file-abc123",
3 "object": "file",
4 "deleted": true
5 }
https://platform.openai.com/docs/api-reference/chat/object 30/116
11/23/23, 7:33 PM API Reference - OpenAI API
Retrieve file
GET https://api.openai.com/v1/files/{file_id}
Path parameters
Returns
1 curl https://api.openai.com/v1/files/file-abc123 \
2 -H "Authorization: Bearer $OPENAI_API_KEY"
Response Copy
1 {
2 "id": "file-abc123",
3 "object": "file",
4 "bytes": 120000,
5 "created_at": 1677610602,
6 "filename": "mydata.jsonl",
7 "purpose": "fine-tune",
8 }
https://platform.openai.com/docs/api-reference/chat/object 31/116
11/23/23, 7:33 PM API Reference - OpenAI API
Path parameters
Returns
1 curl https://api.openai.com/v1/files/file-abc123/content \
2 -H "Authorization: Bearer $OPENAI_API_KEY" > file.jsonl
Images
Given a prompt and/or an input image, the model will generate a new image.
b64_json string
The base64-encoded JSON of the generated image, if response_format is b64_json .
url string
The URL of the generated image, if response_format is url (default).
revised_prompt string
https://platform.openai.com/docs/api-reference/chat/object 32/116
11/23/23, 7:33 PM API Reference - OpenAI API
The prompt that was used to generate the image, if there was any revision to the prompt.
1 {
2 "url": "...",
3 "revised_prompt": "..."
4 }
Create image
POST https://api.openai.com/v1/images/generations
Request body
https://platform.openai.com/docs/api-reference/chat/object 33/116
11/23/23, 7:33 PM API Reference - OpenAI API
models.
Returns
1 curl https://api.openai.com/v1/images/generations \
2 -H "Content-Type: application/json" \
3 -H "Authorization: Bearer $OPENAI_API_KEY" \
4 -d '{
5 "model": "dall-e-3",
6 "prompt": "A cute baby sea otter",
7 "n": 1,
8 "size": "1024x1024"
9 }'
Response Copy
1 {
2 "created": 1589478378,
3 "data": [
4 {
5 "url": "https://..."
6 },
7 {
8 "url": "https://..."
9 }
10 ]
11 }
https://platform.openai.com/docs/api-reference/chat/object 34/116
11/23/23, 7:33 PM API Reference - OpenAI API
Request body
Returns
https://platform.openai.com/docs/api-reference/chat/object 35/116
11/23/23, 7:33 PM API Reference - OpenAI API
1 curl https://api.openai.com/v1/images/edits \
2 -H "Authorization: Bearer $OPENAI_API_KEY" \
3 -F image="@otter.png" \
4 -F mask="@mask.png" \
5 -F prompt="A cute baby sea otter wearing a beret" \
6 -F n=2 \
7 -F size="1024x1024"
Response Copy
1 {
2 "created": 1589478378,
3 "data": [
4 {
5 "url": "https://..."
6 },
7 {
8 "url": "https://..."
9 }
10 ]
11 }
Request body
https://platform.openai.com/docs/api-reference/chat/object 36/116
11/23/23, 7:33 PM API Reference - OpenAI API
Returns
1 curl https://api.openai.com/v1/images/variations \
2 -H "Authorization: Bearer $OPENAI_API_KEY" \
3 -F image="@otter.png" \
4 -F n=2 \
5 -F size="1024x1024"
Response Copy
1 {
2 "created": 1589478378,
3 "data": [
4 {
5 "url": "https://..."
6 },
7 {
8 "url": "https://..."
9 }
https://platform.openai.com/docs/api-reference/chat/object 37/116
11/23/23, 7:33 PM API Reference - OpenAI API
10 ]
11 }
Models
List and describe the various models available in the API. You can refer to the Models
documentation to understand what models are available and the differences between
them.
id string
The model identifier, which can be referenced in the API endpoints.
created integer
The Unix timestamp (in seconds) when the model was created.
object string
The object type, which is always "model".
owned_by string
The organization that owns the model.
1 {
2 "id": "davinci",
3 "object": "model",
4 "created": 1686935002,
5 "owned_by": "openai"
6 }
https://platform.openai.com/docs/api-reference/chat/object 38/116
11/23/23, 7:33 PM API Reference - OpenAI API
List models
GET https://api.openai.com/v1/models
Lists the currently available models, and provides basic information about each one
such as the owner and availability.
Returns
1 curl https://api.openai.com/v1/models \
2 -H "Authorization: Bearer $OPENAI_API_KEY"
Response Copy
1 {
2 "object": "list",
3 "data": [
4 {
5 "id": "model-id-0",
6 "object": "model",
7 "created": 1686935002,
8 "owned_by": "organization-owner"
9 },
10 {
11 "id": "model-id-1",
12 "object": "model",
13 "created": 1686935002,
14 "owned_by": "organization-owner",
15 },
16 {
17 "id": "model-id-2",
18 "object": "model",
19 "created": 1686935002,
20 "owned_by": "openai"
21 },
22 ],
https://platform.openai.com/docs/api-reference/chat/object 39/116
11/23/23, 7:33 PM API Reference - OpenAI API
23 "object": "list"
24 }
Retrieve model
GET https://api.openai.com/v1/models/{model}
Retrieves a model instance, providing basic information about the model such as the
owner and permissioning.
Path parameters
Returns
1 curl https://api.openai.com/v1/models/gpt-3.5-turbo-instruct \
2 -H "Authorization: Bearer $OPENAI_API_KEY"
1 {
2 "id": "gpt-3.5-turbo-instruct",
3 "object": "model",
4 "created": 1686935002,
5 "owned_by": "openai"
6 }
https://platform.openai.com/docs/api-reference/chat/object 40/116
11/23/23, 7:33 PM API Reference - OpenAI API
Delete a fine-tuned model. You must have the Owner role in your organization to
delete a model.
Path parameters
Returns
Deletion status.
1 curl https://api.openai.com/v1/models/ft:gpt-3.5-turbo:acemeco:suffix:abc123
2 -X DELETE \
3 -H "Authorization: Bearer $OPENAI_API_KEY"
Response Copy
1 {
2 "id": "ft:gpt-3.5-turbo:acemeco:suffix:abc123",
3 "object": "model",
4 "deleted": true
5 }
Moderations
Given a input text, outputs if the model classifies it as violating OpenAI's content policy.
https://platform.openai.com/docs/api-reference/chat/object 41/116
11/23/23, 7:33 PM API Reference - OpenAI API
id string
The unique identifier for the moderation request.
model string
The model used to generate the moderation results.
results array
A list of moderation objects.
Show properties
1 {
2 "id": "modr-XXXXX",
3 "model": "text-moderation-005",
4 "results": [
5 {
6 "flagged": true,
7 "categories": {
8 "sexual": false,
9 "hate": false,
10 "harassment": false,
11 "self-harm": false,
12 "sexual/minors": false,
13 "hate/threatening": false,
14 "violence/graphic": false,
15 "self-harm/intent": false,
16 "self-harm/instructions": false,
17 "harassment/threatening": true,
18 "violence": true,
19 },
20 "category_scores": {
21 "sexual": 1.2282071e-06,
22 "hate": 0.010696256,
https://platform.openai.com/docs/api-reference/chat/object 42/116
11/23/23, 7:33 PM API Reference - OpenAI API
23 "harassment": 0.29842457,
24 "self-harm": 1.5236925e-08,
25 "sexual/minors": 5.7246268e-08,
26 "hate/threatening": 0.0060676364,
27 "violence/graphic": 4.435014e-06,
28 "self-harm/intent": 8.098441e-10,
29 "self-harm/instructions": 2.8498655e-11,
30 "harassment/threatening": 0.63055265,
31 "violence": 0.99011886,
32 }
33 }
34 ]
35 }
Create moderation
POST https://api.openai.com/v1/moderations
Request body
The default is text-moderation-latest which will be automatically upgraded over time. This
ensures you are always using our most accurate model. If you use text-moderation-stable ,
we will provide advanced notice before updating the model. Accuracy of text-moderation-
stable may be slightly lower than for text-moderation-latest .
Returns
A moderation object.
https://platform.openai.com/docs/api-reference/chat/object 43/116
11/23/23, 7:33 PM API Reference - OpenAI API
1 curl https://api.openai.com/v1/moderations \
2 -H "Content-Type: application/json" \
3 -H "Authorization: Bearer $OPENAI_API_KEY" \
4 -d '{
5 "input": "I want to kill them."
6 }'
Response Copy
1 {
2 "id": "modr-XXXXX",
3 "model": "text-moderation-005",
4 "results": [
5 {
6 "flagged": true,
7 "categories": {
8 "sexual": false,
9 "hate": false,
10 "harassment": false,
11 "self-harm": false,
12 "sexual/minors": false,
13 "hate/threatening": false,
14 "violence/graphic": false,
15 "self-harm/intent": false,
16 "self-harm/instructions": false,
17 "harassment/threatening": true,
18 "violence": true,
19 },
20 "category_scores": {
21 "sexual": 1.2282071e-06,
22 "hate": 0.010696256,
23 "harassment": 0.29842457,
24 "self-harm": 1.5236925e-08,
25 "sexual/minors": 5.7246268e-08,
26 "hate/threatening": 0.0060676364,
27 "violence/graphic": 4.435014e-06,
28 "self-harm/intent": 8.098441e-10,
29 "self-harm/instructions": 2.8498655e-11,
30 "harassment/threatening": 0.63055265,
31 "violence": 0.99011886,
32 }
33 }
34 ]
35 }
https://platform.openai.com/docs/api-reference/chat/object 44/116
11/23/23, 7:33 PM API Reference - OpenAI API
Assistants Beta
Build assistants that can call models and use tools to perform tasks.
Represents an assistant that can call the model and use tools.
id string
The identifier, which can be referenced in API endpoints.
object string
The object type, which is always assistant .
created_at integer
The Unix timestamp (in seconds) for when the assistant was created.
model string
ID of the model to use. You can use the List models API to see all of your available models, or see
our Model overview for descriptions of them.
tools array
A list of tool enabled on the assistant. There can be a maximum of 128 tools per assistant. Tools
can be of types code_interpreter , retrieval , or function .
Show possible types
https://platform.openai.com/docs/api-reference/chat/object 45/116
11/23/23, 7:33 PM API Reference - OpenAI API
file_ids array
A list of file IDs attached to this assistant. There can be a maximum of 20 files attached to the
assistant. Files are ordered by their creation date in ascending order.
metadata map
Set of 16 key-value pairs that can be attached to an object. This can be useful for storing
additional information about the object in a structured format. Keys can be a maximum of 64
characters long and values can be a maxium of 512 characters long.
1 {
2 "id": "asst_abc123",
3 "object": "assistant",
4 "created_at": 1698984975,
5 "name": "Math Tutor",
6 "description": null,
7 "model": "gpt-4",
8 "instructions": "You are a personal math tutor. When asked a question, wri
9 "tools": [
10 {
11 "type": "code_interpreter"
12 }
13 ],
14 "file_ids": [],
15 "metadata": {}
16 }
POST https://api.openai.com/v1/assistants
Request body
model Required
https://platform.openai.com/docs/api-reference/chat/object 46/116
11/23/23, 7:33 PM API Reference - OpenAI API
ID of the model to use. You can use the List models API to see all of your available models, or see
our Model overview for descriptions of them.
Returns
An assistant object.
1 curl "https://api.openai.com/v1/assistants" \
2 -H "Content-Type: application/json" \
3 -H "Authorization: Bearer $OPENAI_API_KEY" \
4 -H "OpenAI-Beta: assistants=v1" \
5 -d '{
6 "instructions": "You are a personal math tutor. When asked a question, w
https://platform.openai.com/docs/api-reference/chat/object 47/116
11/23/23, 7:33 PM API Reference - OpenAI API
Response Copy
1 {
2 "id": "asst_abc123",
3 "object": "assistant",
4 "created_at": 1698984975,
5 "name": "Math Tutor",
6 "description": null,
7 "model": "gpt-4",
8 "instructions": "You are a personal math tutor. When asked a question, wri
9 "tools": [
10 {
11 "type": "code_interpreter"
12 }
13 ],
14 "file_ids": [],
15 "metadata": {}
16 }
GET https://api.openai.com/v1/assistants/{assistant_id}
Retrieves an assistant.
Path parameters
Returns
https://platform.openai.com/docs/api-reference/chat/object 48/116
11/23/23, 7:33 PM API Reference - OpenAI API
1 curl https://api.openai.com/v1/assistants/asst_abc123 \
2 -H "Content-Type: application/json" \
3 -H "Authorization: Bearer $OPENAI_API_KEY" \
4 -H "OpenAI-Beta: assistants=v1"
Response Copy
1 {
2 "id": "asst_abc123",
3 "object": "assistant",
4 "created_at": 1699009709,
5 "name": "HR Helper",
6 "description": null,
7 "model": "gpt-4",
8 "instructions": "You are an HR bot, and you have access to files to answer
9 "tools": [
10 {
11 "type": "retrieval"
12 }
13 ],
14 "file_ids": [
15 "file-abc123"
16 ],
17 "metadata": {}
18 }
POST https://api.openai.com/v1/assistants/{assistant_id}
Modifies an assistant.
Path parameters
https://platform.openai.com/docs/api-reference/chat/object 49/116
11/23/23, 7:33 PM API Reference - OpenAI API
Request body
model Optional
ID of the model to use. You can use the List models API to see all of your available models, or see
our Model overview for descriptions of them.
Returns
https://platform.openai.com/docs/api-reference/chat/object 50/116
11/23/23, 7:33 PM API Reference - OpenAI API
1 curl https://api.openai.com/v1/assistants/asst_abc123 \
2 -H "Content-Type: application/json" \
3 -H "Authorization: Bearer $OPENAI_API_KEY" \
4 -H "OpenAI-Beta: assistants=v1" \
5 -d '{
6 "instructions": "You are an HR bot, and you have access to files to an
7 "tools": [{"type": "retrieval"}],
8 "model": "gpt-4",
9 "file_ids": ["file-abc123", "file-abc456"]
10 }'
Response Copy
1 {
2 "id": "asst_abc123",
3 "object": "assistant",
4 "created_at": 1699009709,
5 "name": "HR Helper",
6 "description": null,
7 "model": "gpt-4",
8 "instructions": "You are an HR bot, and you have access to files to answer
9 "tools": [
10 {
11 "type": "retrieval"
12 }
13 ],
14 "file_ids": [
15 "file-abc123",
16 "file-abc456"
17 ],
18 "metadata": {}
19 }
DELETE https://api.openai.com/v1/assistants/{assistant_id}
Delete an assistant.
https://platform.openai.com/docs/api-reference/chat/object 51/116
11/23/23, 7:33 PM API Reference - OpenAI API
Path parameters
Returns
Deletion status
1 curl https://api.openai.com/v1/assistants/asst_abc123 \
2 -H "Content-Type: application/json" \
3 -H "Authorization: Bearer $OPENAI_API_KEY" \
4 -H "OpenAI-Beta: assistants=v1" \
5 -X DELETE
Response Copy
1 {
2 "id": "asst_abc123",
3 "object": "assistant.deleted",
4 "deleted": true
5 }
GET https://api.openai.com/v1/assistants
Query parameters
https://platform.openai.com/docs/api-reference/chat/object 52/116
11/23/23, 7:33 PM API Reference - OpenAI API
Returns
1 curl "https://api.openai.com/v1/assistants?order=desc&limit=20" \
2 -H "Content-Type: application/json" \
3 -H "Authorization: Bearer $OPENAI_API_KEY" \
4 -H "OpenAI-Beta: assistants=v1"
Response Copy
1 {
2 "object": "list",
3 "data": [
4 {
5 "id": "asst_abc123",
6 "object": "assistant",
7 "created_at": 1698982736,
8 "name": "Coding Tutor",
9 "description": null,
10 "model": "gpt-4",
11 "instructions": "You are a helpful assistant designed to make me bette
12 "tools": [],
13 "file_ids": [],
14 "metadata": {}
https://platform.openai.com/docs/api-reference/chat/object 53/116
11/23/23, 7:33 PM API Reference - OpenAI API
15 },
16 {
17 "id": "asst_abc456",
18 "object": "assistant",
19 "created_at": 1698982718,
20 "name": "My Assistant",
21 "description": null,
22 "model": "gpt-4",
23 "instructions": "You are a helpful assistant designed to make me bette
24 "tools": [],
25 "file_ids": [],
26 "metadata": {}
27 },
28 {
29 "id": "asst_abc789",
30 "object": "assistant",
31 "created_at": 1698982643,
32 "name": null,
33 "description": null,
34 "model": "gpt-4",
35 "instructions": null,
36 "tools": [],
37 "file_ids": [],
38 "metadata": {}
39 }
40 ],
41 "first_id": "asst_abc123",
42 "last_id": "asst_abc789",
43 "has_more": false
44 }
id string
The identifier, which can be referenced in API endpoints.
object string
The object type, which is always assistant.file .
created_at integer
https://platform.openai.com/docs/api-reference/chat/object 54/116
11/23/23, 7:33 PM API Reference - OpenAI API
The Unix timestamp (in seconds) for when the assistant file was created.
assistant_id string
The assistant ID that the file is attached to.
1 {
2 "id": "file-abc123",
3 "object": "assistant.file",
4 "created_at": 1699055364,
5 "assistant_id": "asst_abc123"
6 }
POST https://api.openai.com/v1/assistants/{assistant_id}/files
Path parameters
Request body
Returns
https://platform.openai.com/docs/api-reference/chat/object 55/116
11/23/23, 7:33 PM API Reference - OpenAI API
1 curl https://api.openai.com/v1/assistants/asst_abc123/files \
2 -H 'Authorization: Bearer $OPENAI_API_KEY"' \
3 -H 'Content-Type: application/json' \
4 -H 'OpenAI-Beta: assistants=v1' \
5 -d '{
6 "file_id": "file-abc123"
7 }'
Response Copy
1 {
2 "id": "file-abc123",
3 "object": "assistant.file",
4 "created_at": 1699055364,
5 "assistant_id": "asst_abc123"
6 }
GET https://api.openai.com/v1/assistants/{assistant_id}/files/{file_id}
Retrieves an AssistantFile.
Path parameters
Returns
https://platform.openai.com/docs/api-reference/chat/object 56/116
11/23/23, 7:33 PM API Reference - OpenAI API
1 curl https://api.openai.com/v1/assistants/asst_abc123/files/file-abc123 \
2 -H 'Authorization: Bearer $OPENAI_API_KEY"' \
3 -H 'Content-Type: application/json' \
4 -H 'OpenAI-Beta: assistants=v1'
Response Copy
1 {
2 "id": "file-abc123",
3 "object": "assistant.file",
4 "created_at": 1699055364,
5 "assistant_id": "asst_abc123"
6 }
DELETE https://api.openai.com/v1/assistants/{assistant_id}/files/{file_id}
Path parameters
Returns
Deletion status
https://platform.openai.com/docs/api-reference/chat/object 57/116
11/23/23, 7:33 PM API Reference - OpenAI API
1 curl https://api.openai.com/v1/assistants/asst_abc123/files/file-abc123 \
2 -H "Authorization: Bearer $OPENAI_API_KEY" \
3 -H "Content-Type: application/json" \
4 -H "OpenAI-Beta: assistants=v1" \
5 -X DELETE
Response Copy
1 {
2 id: "file-abc123",
3 object: "assistant.file.deleted",
4 deleted: true
5 }
GET https://api.openai.com/v1/assistants/{assistant_id}/files
Path parameters
Query parameters
https://platform.openai.com/docs/api-reference/chat/object 58/116
11/23/23, 7:33 PM API Reference - OpenAI API
call can include after=obj_foo in order to fetch the next page of the list.
Returns
1 curl https://api.openai.com/v1/assistants/asst_abc123/files \
2 -H "Authorization: Bearer $OPENAI_API_KEY" \
3 -H "Content-Type: application/json" \
4 -H "OpenAI-Beta: assistants=v1"
Response Copy
1 {
2 "object": "list",
3 "data": [
4 {
5 "id": "file-abc123",
6 "object": "assistant.file",
7 "created_at": 1699060412,
8 "assistant_id": "asst_abc123"
9 },
10 {
11 "id": "file-abc456",
12 "object": "assistant.file",
13 "created_at": 1699060412,
14 "assistant_id": "asst_abc123"
15 }
16 ],
17 "first_id": "file-abc123",
18 "last_id": "file-abc456",
19 "has_more": false
20 }
https://platform.openai.com/docs/api-reference/chat/object 59/116
11/23/23, 7:33 PM API Reference - OpenAI API
Threads Beta
id string
The identifier, which can be referenced in API endpoints.
object string
The object type, which is always thread .
created_at integer
The Unix timestamp (in seconds) for when the thread was created.
metadata map
Set of 16 key-value pairs that can be attached to an object. This can be useful for storing
additional information about the object in a structured format. Keys can be a maximum of 64
characters long and values can be a maxium of 512 characters long.
1 {
2 "id": "thread_abc123",
3 "object": "thread",
4 "created_at": 1698107661,
5 "metadata": {}
6 }
https://platform.openai.com/docs/api-reference/chat/object 60/116
11/23/23, 7:33 PM API Reference - OpenAI API
POST https://api.openai.com/v1/threads
Create a thread.
Request body
Returns
A thread object.
Empty Messages
1 curl https://api.openai.com/v1/threads \
2 -H "Content-Type: application/json" \
3 -H "Authorization: Bearer $OPENAI_API_KEY" \
4 -H "OpenAI-Beta: assistants=v1" \
5 -d ''
Response Copy
1 {
2 "id": "thread_abc123",
3 "object": "thread",
4 "created_at": 1699012949,
5 "metadata": {}
6 }
https://platform.openai.com/docs/api-reference/chat/object 61/116
11/23/23, 7:33 PM API Reference - OpenAI API
GET https://api.openai.com/v1/threads/{thread_id}
Retrieves a thread.
Path parameters
Returns
1 curl https://api.openai.com/v1/threads/thread_abc123 \
2 -H "Content-Type: application/json" \
3 -H "Authorization: Bearer $OPENAI_API_KEY" \
4 -H "OpenAI-Beta: assistants=v1"
Response Copy
1 {
2 "id": "thread_abc123",
3 "object": "thread",
4 "created_at": 1699014083,
5 "metadata": {}
6 }
POST https://api.openai.com/v1/threads/{thread_id}
https://platform.openai.com/docs/api-reference/chat/object 62/116
11/23/23, 7:33 PM API Reference - OpenAI API
Modifies a thread.
Path parameters
Request body
Returns
1 curl https://api.openai.com/v1/threads/thread_abc123 \
2 -H "Content-Type: application/json" \
3 -H "Authorization: Bearer $OPENAI_API_KEY" \
4 -H "OpenAI-Beta: assistants=v1" \
5 -d '{
6 "metadata": {
7 "modified": "true",
8 "user": "abc123"
9 }
10 }'
Response Copy
1 {
2 "id": "thread_abc123",
3 "object": "thread",
4 "created_at": 1699014083,
5 "metadata": {
6 "modified": "true",
7 "user": "abc123"
https://platform.openai.com/docs/api-reference/chat/object 63/116
11/23/23, 7:33 PM API Reference - OpenAI API
8 }
9 }
DELETE https://api.openai.com/v1/threads/{thread_id}
Delete a thread.
Path parameters
Returns
Deletion status
1 curl https://api.openai.com/v1/threads/thread_abc123 \
2 -H "Content-Type: application/json" \
3 -H "Authorization: Bearer $OPENAI_API_KEY" \
4 -H "OpenAI-Beta: assistants=v1" \
5 -X DELETE
Response Copy
1 {
2 "id": "thread_abc123",
3 "object": "thread.deleted",
4 "deleted": true
5 }
https://platform.openai.com/docs/api-reference/chat/object 64/116
11/23/23, 7:33 PM API Reference - OpenAI API
Messages Beta
id string
The identifier, which can be referenced in API endpoints.
object string
The object type, which is always thread.message .
created_at integer
The Unix timestamp (in seconds) for when the message was created.
thread_id string
The thread ID that this message belongs to.
role string
The entity that produced the message. One of user or assistant .
content array
The content of the message in array of text and/or images.
Show possible types
file_ids array
https://platform.openai.com/docs/api-reference/chat/object 65/116
11/23/23, 7:33 PM API Reference - OpenAI API
A list of file IDs that the assistant should use. Useful for tools like retrieval and code_interpreter
that can access files. A maximum of 10 files can be attached to a message.
metadata map
Set of 16 key-value pairs that can be attached to an object. This can be useful for storing
additional information about the object in a structured format. Keys can be a maximum of 64
characters long and values can be a maxium of 512 characters long.
1 {
2 "id": "msg_abc123",
3 "object": "thread.message",
4 "created_at": 1698983503,
5 "thread_id": "thread_abc123",
6 "role": "assistant",
7 "content": [
8 {
9 "type": "text",
10 "text": {
11 "value": "Hi! How can I help you today?",
12 "annotations": []
13 }
14 }
15 ],
16 "file_ids": [],
17 "assistant_id": "asst_abc123",
18 "run_id": "run_abc123",
19 "metadata": {}
20 }
POST https://api.openai.com/v1/threads/{thread_id}/messages
Create a message.
Path parameters
https://platform.openai.com/docs/api-reference/chat/object 66/116
11/23/23, 7:33 PM API Reference - OpenAI API
Request body
Returns
A message object.
1 curl https://api.openai.com/v1/threads/thread_abc123/messages \
2 -H "Content-Type: application/json" \
3 -H "Authorization: Bearer $OPENAI_API_KEY" \
4 -H "OpenAI-Beta: assistants=v1" \
5 -d '{
6 "role": "user",
7 "content": "How does AI work? Explain it in simple terms."
8 }'
Response Copy
1 {
2 "id": "msg_abc123",
3 "object": "thread.message",
https://platform.openai.com/docs/api-reference/chat/object 67/116
11/23/23, 7:33 PM API Reference - OpenAI API
4 "created_at": 1699017614,
5 "thread_id": "thread_abc123",
6 "role": "user",
7 "content": [
8 {
9 "type": "text",
10 "text": {
11 "value": "How does AI work? Explain it in simple terms.",
12 "annotations": []
13 }
14 }
15 ],
16 "file_ids": [],
17 "assistant_id": null,
18 "run_id": null,
19 "metadata": {}
20 }
GET https://api.openai.com/v1/threads/{thread_id}/messages/{message_id}
Retrieve a message.
Path parameters
Returns
https://platform.openai.com/docs/api-reference/chat/object 68/116
11/23/23, 7:33 PM API Reference - OpenAI API
1 curl https://api.openai.com/v1/threads/thread_abc123/messages/msg_abc123 \
2 -H "Content-Type: application/json" \
3 -H "Authorization: Bearer $OPENAI_API_KEY" \
4 -H "OpenAI-Beta: assistants=v1"
Response Copy
1 {
2 "id": "msg_abc123",
3 "object": "thread.message",
4 "created_at": 1699017614,
5 "thread_id": "thread_abc123",
6 "role": "user",
7 "content": [
8 {
9 "type": "text",
10 "text": {
11 "value": "How does AI work? Explain it in simple terms.",
12 "annotations": []
13 }
14 }
15 ],
16 "file_ids": [],
17 "assistant_id": null,
18 "run_id": null,
19 "metadata": {}
20 }
POST https://api.openai.com/v1/threads/{thread_id}/messages/{message_id}
Modifies a message.
Path parameters
https://platform.openai.com/docs/api-reference/chat/object 69/116
11/23/23, 7:33 PM API Reference - OpenAI API
Request body
Returns
1 curl https://api.openai.com/v1/threads/thread_abc123/messages/msg_abc123 \
2 -H "Content-Type: application/json" \
3 -H "Authorization: Bearer $OPENAI_API_KEY" \
4 -H "OpenAI-Beta: assistants=v1" \
5 -d '{
6 "metadata": {
7 "modified": "true",
8 "user": "abc123"
9 }
10 }'
Response Copy
1 {
2 "id": "msg_abc123",
3 "object": "thread.message",
4 "created_at": 1699017614,
5 "thread_id": "thread_abc123",
6 "role": "user",
7 "content": [
8 {
9 "type": "text",
10 "text": {
11 "value": "How does AI work? Explain it in simple terms.",
12 "annotations": []
https://platform.openai.com/docs/api-reference/chat/object 70/116
11/23/23, 7:33 PM API Reference - OpenAI API
13 }
14 }
15 ],
16 "file_ids": [],
17 "assistant_id": null,
18 "run_id": null,
19 "metadata": {
20 "modified": "true",
21 "user": "abc123"
22 }
23 }
GET https://api.openai.com/v1/threads/{thread_id}/messages
Path parameters
Query parameters
https://platform.openai.com/docs/api-reference/chat/object 71/116
11/23/23, 7:33 PM API Reference - OpenAI API
A cursor for use in pagination. before is an object ID that defines your place in the list. For
instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent
call can include before=obj_foo in order to fetch the previous page of the list.
Returns
1 curl https://api.openai.com/v1/threads/thread_abc123/messages \
2 -H "Content-Type: application/json" \
3 -H "Authorization: Bearer $OPENAI_API_KEY" \
4 -H "OpenAI-Beta: assistants=v1"
Response Copy
1 {
2 "object": "list",
3 "data": [
4 {
5 "id": "msg_abc123",
6 "object": "thread.message",
7 "created_at": 1699016383,
8 "thread_id": "thread_abc123",
9 "role": "user",
10 "content": [
11 {
12 "type": "text",
13 "text": {
14 "value": "How does AI work? Explain it in simple terms.",
15 "annotations": []
16 }
17 }
18 ],
19 "file_ids": [],
20 "assistant_id": null,
21 "run_id": null,
22 "metadata": {}
23 },
24 {
25 "id": "msg_abc456",
26 "object": "thread.message",
https://platform.openai.com/docs/api-reference/chat/object 72/116
11/23/23, 7:33 PM API Reference - OpenAI API
27 "created_at": 1699016383,
28 "thread_id": "thread_abc123",
29 "role": "user",
30 "content": [
31 {
32 "type": "text",
33 "text": {
34 "value": "Hello, what is AI?",
35 "annotations": []
36 }
37 }
38 ],
39 "file_ids": [
40 "file-abc123"
41 ],
42 "assistant_id": null,
43 "run_id": null,
44 "metadata": {}
45 }
46 ],
47 "first_id": "msg_abc123",
48 "last_id": "msg_abc456",
49 "has_more": false
50 }
id string
The identifier, which can be referenced in API endpoints.
object string
The object type, which is always thread.message.file .
created_at integer
The Unix timestamp (in seconds) for when the message file was created.
message_id string
The ID of the message that the File is attached to.
https://platform.openai.com/docs/api-reference/chat/object 73/116
11/23/23, 7:33 PM API Reference - OpenAI API
1 {
2 "id": "file-abc123",
3 "object": "thread.message.file",
4 "created_at": 1698107661,
5 "message_id": "message_QLoItBbqwyAJEzlTy4y9kOMM",
6 "file_id": "file-abc123"
7 }
GET https://api.openai.com/v1/threads/{thread_id}/messages/{message_id}/fil
es/{file_id}
Path parameters
Returns
1 curl https://api.openai.com/v1/threads/thread_abc123/messages/msg_abc123/file
2 -H "Authorization: Bearer $OPENAI_API_KEY" \
https://platform.openai.com/docs/api-reference/chat/object 74/116
11/23/23, 7:33 PM API Reference - OpenAI API
3 -H "Content-Type: application/json" \
4 -H "OpenAI-Beta: assistants=v1"
Response Copy
1 {
2 "id": "file-abc123",
3 "object": "thread.message.file",
4 "created_at": 1699061776,
5 "message_id": "msg_abc123"
6 }
GET https://api.openai.com/v1/threads/{thread_id}/messages/{message_id}/fil
es
Path parameters
Query parameters
https://platform.openai.com/docs/api-reference/chat/object 75/116
11/23/23, 7:33 PM API Reference - OpenAI API
Returns
1 curl https://api.openai.com/v1/threads/thread_abc123/messages/msg_abc123/file
2 -H "Authorization: Bearer $OPENAI_API_KEY" \
3 -H "Content-Type: application/json" \
4 -H "OpenAI-Beta: assistants=v1"
Response Copy
1 {
2 "object": "list",
3 "data": [
4 {
5 "id": "file-abc123",
6 "object": "thread.message.file",
7 "created_at": 1699061776,
8 "message_id": "msg_abc123"
9 },
10 {
11 "id": "file-abc123",
12 "object": "thread.message.file",
13 "created_at": 1699061776,
14 "message_id": "msg_abc123"
15 }
16 ],
17 "first_id": "file-abc123",
18 "last_id": "file-abc123",
https://platform.openai.com/docs/api-reference/chat/object 76/116
11/23/23, 7:33 PM API Reference - OpenAI API
19 "has_more": false
20 }
Runs Beta
id string
The identifier, which can be referenced in API endpoints.
object string
The object type, which is always thread.run .
created_at integer
The Unix timestamp (in seconds) for when the run was created.
thread_id string
The ID of the thread that was executed on as a part of this run.
assistant_id string
The ID of the assistant used for execution of this run.
status string
The status of the run, which can be either queued , in_progress , requires_action ,
cancelling , cancelled , failed , completed , or expired .
https://platform.openai.com/docs/api-reference/chat/object 77/116
11/23/23, 7:33 PM API Reference - OpenAI API
expires_at integer
The Unix timestamp (in seconds) for when the run will expire.
model string
The model that the assistant used for this run.
instructions string
The instructions that the assistant used for this run.
tools array
The list of tools that the assistant used for this run.
Show possible types
file_ids array
The list of File IDs the assistant used for this run.
metadata map
Set of 16 key-value pairs that can be attached to an object. This can be useful for storing
additional information about the object in a structured format. Keys can be a maximum of 64
characters long and values can be a maxium of 512 characters long.
https://platform.openai.com/docs/api-reference/chat/object 78/116
11/23/23, 7:33 PM API Reference - OpenAI API
1 {
2 "id": "run_abc123",
3 "object": "thread.run",
4 "created_at": 1698107661,
5 "assistant_id": "asst_abc123",
6 "thread_id": "thread_abc123",
7 "status": "completed",
8 "started_at": 1699073476,
9 "expires_at": null,
10 "cancelled_at": null,
11 "failed_at": null,
12 "completed_at": 1699073498,
13 "last_error": null,
14 "model": "gpt-4",
15 "instructions": null,
16 "tools": [{"type": "retrieval"}, {"type": "code_interpreter"}],
17 "file_ids": [],
18 "metadata": {}
19 }
POST https://api.openai.com/v1/threads/{thread_id}/runs
Create a run.
Path parameters
Request body
https://platform.openai.com/docs/api-reference/chat/object 79/116
11/23/23, 7:33 PM API Reference - OpenAI API
Returns
A run object.
1 curl https://api.openai.com/v1/threads/thread_abc123/runs \
2 -H "Authorization: Bearer $OPENAI_API_KEY" \
3 -H "Content-Type: application/json" \
4 -H "OpenAI-Beta: assistants=v1" \
5 -d '{
6 "assistant_id": "asst_abc123"
7 }'
Response Copy
1 {
2 "id": "run_abc123",
3 "object": "thread.run",
4 "created_at": 1699063290,
5 "assistant_id": "asst_abc123",
6 "thread_id": "thread_abc123",
7 "status": "queued",
8 "started_at": 1699063290,
9 "expires_at": null,
10 "cancelled_at": null,
11 "failed_at": null,
https://platform.openai.com/docs/api-reference/chat/object 80/116
11/23/23, 7:33 PM API Reference - OpenAI API
12 "completed_at": 1699063291,
13 "last_error": null,
14 "model": "gpt-4",
15 "instructions": null,
16 "tools": [
17 {
18 "type": "code_interpreter"
19 }
20 ],
21 "file_ids": [
22 "file-abc123",
23 "file-abc456"
24 ],
25 "metadata": {}
26 }
GET https://api.openai.com/v1/threads/{thread_id}/runs/{run_id}
Retrieves a run.
Path parameters
Returns
1 curl https://api.openai.com/v1/threads/thread_abc123/runs/run_abc123 \
2 -H "Authorization: Bearer $OPENAI_API_KEY" \
https://platform.openai.com/docs/api-reference/chat/object 81/116
11/23/23, 7:33 PM API Reference - OpenAI API
3 -H "OpenAI-Beta: assistants=v1"
Response Copy
1 {
2 "id": "run_abc123",
3 "object": "thread.run",
4 "created_at": 1699075072,
5 "assistant_id": "asst_abc123",
6 "thread_id": "thread_abc123",
7 "status": "completed",
8 "started_at": 1699075072,
9 "expires_at": null,
10 "cancelled_at": null,
11 "failed_at": null,
12 "completed_at": 1699075073,
13 "last_error": null,
14 "model": "gpt-3.5-turbo",
15 "instructions": null,
16 "tools": [
17 {
18 "type": "code_interpreter"
19 }
20 ],
21 "file_ids": [
22 "file-abc123",
23 "file-abc456"
24 ],
25 "metadata": {}
26 }
POST https://api.openai.com/v1/threads/{thread_id}/runs/{run_id}
Modifies a run.
Path parameters
https://platform.openai.com/docs/api-reference/chat/object 82/116
11/23/23, 7:33 PM API Reference - OpenAI API
Request body
Returns
1 curl https://api.openai.com/v1/threads/thread_abc123/runs/run_abc123 \
2 -H "Authorization: Bearer $OPENAI_API_KEY" \
3 -H "Content-Type: application/json" \
4 -H "OpenAI-Beta: assistants=v1" \
5 -d '{
6 "metadata": {
7 "user_id": "user_abc123"
8 }
9 }'
Response Copy
1 {
2 "id": "run_abc123",
3 "object": "thread.run",
4 "created_at": 1699075072,
5 "assistant_id": "asst_abc123",
6 "thread_id": "thread_abc123",
7 "status": "completed",
8 "started_at": 1699075072,
9 "expires_at": null,
10 "cancelled_at": null,
11 "failed_at": null,
12 "completed_at": 1699075073,
13 "last_error": null,
https://platform.openai.com/docs/api-reference/chat/object 83/116
11/23/23, 7:33 PM API Reference - OpenAI API
14 "model": "gpt-3.5-turbo",
15 "instructions": null,
16 "tools": [
17 {
18 "type": "code_interpreter"
19 }
20 ],
21 "file_ids": [
22 "file-abc123",
23 "file-abc456"
24 ],
25 "metadata": {
26 "user_id": "user_abc123"
27 }
28 }
GET https://api.openai.com/v1/threads/{thread_id}/runs
Path parameters
Query parameters
call can include after=obj_foo in order to fetch the next page of the list.
Returns
1 curl https://api.openai.com/v1/threads/thread_abc123/runs \
2 -H "Authorization: Bearer $OPENAI_API_KEY" \
3 -H "Content-Type: application/json" \
4 -H "OpenAI-Beta: assistants=v1"
Response Copy
1 {
2 "object": "list",
3 "data": [
4 {
5 "id": "run_abc123",
6 "object": "thread.run",
7 "created_at": 1699075072,
8 "assistant_id": "asst_abc123",
9 "thread_id": "thread_abc123",
10 "status": "completed",
11 "started_at": 1699075072,
12 "expires_at": null,
13 "cancelled_at": null,
14 "failed_at": null,
15 "completed_at": 1699075073,
16 "last_error": null,
17 "model": "gpt-3.5-turbo",
18 "instructions": null,
19 "tools": [
20 {
21 "type": "code_interpreter"
22 }
23 ],
https://platform.openai.com/docs/api-reference/chat/object 85/116
11/23/23, 7:33 PM API Reference - OpenAI API
24 "file_ids": [
25 "file-abc123",
26 "file-abc456"
27 ],
28 "metadata": {}
29 },
30 {
31 "id": "run_abc456",
32 "object": "thread.run",
33 "created_at": 1699063290,
34 "assistant_id": "asst_abc123",
35 "thread_id": "thread_abc123",
36 "status": "completed",
37 "started_at": 1699063290,
38 "expires_at": null,
39 "cancelled_at": null,
40 "failed_at": null,
41 "completed_at": 1699063291,
42 "last_error": null,
43 "model": "gpt-3.5-turbo",
44 "instructions": null,
45 "tools": [
46 {
47 "type": "code_interpreter"
48 }
49 ],
50 "file_ids": [
51 "file-abc123",
52 "file-abc456"
53 ],
54 "metadata": {}
55 }
56 ],
57 "first_id": "run_abc123",
58 "last_id": "run_abc456",
59 "has_more": false
60 }
POST https://api.openai.com/v1/threads/{thread_id}/runs/{run_id}/submit_too
l_outputs
https://platform.openai.com/docs/api-reference/chat/object 86/116
11/23/23, 7:33 PM API Reference - OpenAI API
Path parameters
Request body
Returns
1 curl https://api.openai.com/v1/threads/thread_abc123/runs/run_abc123/submit_
2 -H "Authorization: Bearer $OPENAI_API_KEY" \
3 -H "Content-Type: application/json" \
4 -H "OpenAI-Beta: assistants=v1" \
5 -d '{
6 "tool_outputs": [
7 {
8 "tool_call_id": "call_abc123",
9 "output": "28C"
10 }
11 ]
12 }'
https://platform.openai.com/docs/api-reference/chat/object 87/116
11/23/23, 7:33 PM API Reference - OpenAI API
Response Copy
1 {
2 "id": "run_abc123",
3 "object": "thread.run",
4 "created_at": 1699075592,
5 "assistant_id": "asst_abc123",
6 "thread_id": "thread_abc123",
7 "status": "queued",
8 "started_at": 1699075592,
9 "expires_at": 1699076192,
10 "cancelled_at": null,
11 "failed_at": null,
12 "completed_at": null,
13 "last_error": null,
14 "model": "gpt-4",
15 "instructions": "You tell the weather.",
16 "tools": [
17 {
18 "type": "function",
19 "function": {
20 "name": "get_weather",
21 "description": "Determine weather in my location",
22 "parameters": {
23 "type": "object",
24 "properties": {
25 "location": {
26 "type": "string",
27 "description": "The city and state e.g. San Francisco, CA"
28 },
29 "unit": {
30 "type": "string",
31 "enum": [
32 "c",
33 "f"
34 ]
35 }
36 },
37 "required": [
38 "location"
39 ]
40 }
41 }
42 }
43 ],
44 "file_ids": [],
45 "metadata": {}
46 }
https://platform.openai.com/docs/api-reference/chat/object 88/116
11/23/23, 7:33 PM API Reference - OpenAI API
POST https://api.openai.com/v1/threads/{thread_id}/runs/{run_id}/cancel
Path parameters
Returns
1 curl https://api.openai.com/v1/threads/thread_abc123/runs/run_abc123/cancel \
2 -H "Authorization: Bearer $OPENAI_API_KEY" \
3 -H "OpenAI-Beta: assistants=v1" \
4 -X POST
Response Copy
1 {
2 "id": "run_abc123",
3 "object": "thread.run",
4 "created_at": 1699076126,
5 "assistant_id": "asst_abc123",
6 "thread_id": "thread_abc123",
7 "status": "cancelling",
8 "started_at": 1699076126,
9 "expires_at": 1699076726,
10 "cancelled_at": null,
11 "failed_at": null,
https://platform.openai.com/docs/api-reference/chat/object 89/116
11/23/23, 7:33 PM API Reference - OpenAI API
12 "completed_at": null,
13 "last_error": null,
14 "model": "gpt-4",
15 "instructions": "You summarize books.",
16 "tools": [
17 {
18 "type": "retrieval"
19 }
20 ],
21 "file_ids": [],
22 "metadata": {}
23 }
POST https://api.openai.com/v1/threads/runs
Request body
https://platform.openai.com/docs/api-reference/chat/object 90/116
11/23/23, 7:33 PM API Reference - OpenAI API
Set of 16 key-value pairs that can be attached to an object. This can be useful for storing
additional information about the object in a structured format. Keys can be a maximum of 64
characters long and values can be a maxium of 512 characters long.
Returns
A run object.
1 curl https://api.openai.com/v1/threads/runs \
2 -H "Authorization: Bearer $OPENAI_API_KEY" \
3 -H "Content-Type: application/json" \
4 -H "OpenAI-Beta: assistants=v1" \
5 -d '{
6 "assistant_id": "asst_abc123",
7 "thread": {
8 "messages": [
9 {"role": "user", "content": "Explain deep learning to a 5 year old
10 ]
11 }
12 }'
Response Copy
1 {
2 "id": "run_abc123",
3 "object": "thread.run",
4 "created_at": 1699076792,
5 "assistant_id": "asst_abc123",
6 "thread_id": "thread_abc123",
7 "status": "queued",
8 "started_at": null,
9 "expires_at": 1699077392,
10 "cancelled_at": null,
11 "failed_at": null,
12 "completed_at": null,
13 "last_error": null,
14 "model": "gpt-4",
15 "instructions": "You are a helpful assistant.",
16 "tools": [],
17 "file_ids": [],
https://platform.openai.com/docs/api-reference/chat/object 91/116
11/23/23, 7:33 PM API Reference - OpenAI API
18 "metadata": {}
19 }
id string
The identifier of the run step, which can be referenced in API endpoints.
object string
The object type, which is always `thread.run.step``.
created_at integer
The Unix timestamp (in seconds) for when the run step was created.
assistant_id string
The ID of the assistant associated with the run step.
thread_id string
The ID of the thread that was run.
run_id string
The ID of the run that this run step is a part of.
type string
The type of run step, which can be either message_creation or tool_calls .
status string
The status of the run step, which can be either in_progress , cancelled , failed ,
completed , or expired .
step_details object
The details of the run step.
Show possible types
https://platform.openai.com/docs/api-reference/chat/object 92/116
11/23/23, 7:33 PM API Reference - OpenAI API
Show properties
metadata map
Set of 16 key-value pairs that can be attached to an object. This can be useful for storing
additional information about the object in a structured format. Keys can be a maximum of 64
characters long and values can be a maxium of 512 characters long.
1 {
2 "id": "step_abc123",
3 "object": "thread.run.step",
4 "created_at": 1699063291,
5 "run_id": "run_abc123",
6 "assistant_id": "asst_abc123",
7 "thread_id": "thread_abc123",
8 "type": "message_creation",
9 "status": "completed",
10 "cancelled_at": null,
11 "completed_at": 1699063291,
12 "expired_at": null,
13 "failed_at": null,
14 "last_error": null,
15 "step_details": {
16 "type": "message_creation",
17 "message_creation": {
18 "message_id": "msg_abc123"
19 }
20 }
21 }
https://platform.openai.com/docs/api-reference/chat/object 93/116
11/23/23, 7:33 PM API Reference - OpenAI API
GET https://api.openai.com/v1/threads/{thread_id}/runs/{run_id}/steps/{step
_id}
Path parameters
Returns
1 curl https://api.openai.com/v1/threads/thread_abc123/runs/run_abc123/steps/st
2 -H "Authorization: Bearer $OPENAI_API_KEY" \
3 -H "Content-Type: application/json" \
4 -H "OpenAI-Beta: assistants=v1"
Response Copy
1 {
2 "id": "step_abc123",
3 "object": "thread.run.step",
4 "created_at": 1699063291,
5 "run_id": "run_abc123",
6 "assistant_id": "asst_abc123",
https://platform.openai.com/docs/api-reference/chat/object 94/116
11/23/23, 7:33 PM API Reference - OpenAI API
7 "thread_id": "thread_abc123",
8 "type": "message_creation",
9 "status": "completed",
10 "cancelled_at": null,
11 "completed_at": 1699063291,
12 "expired_at": null,
13 "failed_at": null,
14 "last_error": null,
15 "step_details": {
16 "type": "message_creation",
17 "message_creation": {
18 "message_id": "msg_abc123"
19 }
20 }
21 }
GET https://api.openai.com/v1/threads/{thread_id}/runs/{run_id}/steps
Path parameters
Query parameters
https://platform.openai.com/docs/api-reference/chat/object 95/116
11/23/23, 7:33 PM API Reference - OpenAI API
Returns
1 curl https://api.openai.com/v1/threads/thread_abc123/runs/run_abc123/steps \
2 -H "Authorization: Bearer $OPENAI_API_KEY" \
3 -H "Content-Type: application/json" \
4 -H "OpenAI-Beta: assistants=v1"
Response Copy
1 {
2 "object": "list",
3 "data": [
4 {
5 "id": "step_abc123",
6 "object": "thread.run.step",
7 "created_at": 1699063291,
8 "run_id": "run_abc123",
9 "assistant_id": "asst_abc123",
10 "thread_id": "thread_abc123",
11 "type": "message_creation",
12 "status": "completed",
13 "cancelled_at": null,
14 "completed_at": 1699063291,
15 "expired_at": null,
16 "failed_at": null,
17 "last_error": null,
18 "step_details": {
https://platform.openai.com/docs/api-reference/chat/object 96/116
11/23/23, 7:33 PM API Reference - OpenAI API
19 "type": "message_creation",
20 "message_creation": {
21 "message_id": "msg_abc123"
22 }
23 }
24 }
25 ],
26 "first_id": "step_abc123",
27 "last_id": "step_abc456",
28 "has_more": false
29 }
Completions Legacy
Given a prompt, the model will return one or more predicted completions along with the
probabilities of alternative tokens at each position. Most developer should use our Chat
Completions API to leverage our best and newest models. Most models that support the
legacy Completions endpoint will be shut off on January 4th, 2024.
Represents a completion response from the API. Note: both the streamed and non-
streamed response objects share the same shape (unlike the chat endpoint).
id string
A unique identifier for the completion.
choices array
The list of completion choices the model generated for the input prompt.
Show properties
created integer
The Unix timestamp (in seconds) of when the completion was created.
model string
The model used for completion.
https://platform.openai.com/docs/api-reference/chat/object 97/116
11/23/23, 7:33 PM API Reference - OpenAI API
system_fingerprint string
This fingerprint represents the backend configuration that the model runs with.
Can be used in conjunction with the seed request parameter to understand when backend
changes have been made that might impact determinism.
object string
The object type, which is always "text_completion"
usage object
Usage statistics for the completion request.
Show properties
1 {
2 "id": "cmpl-uqkvlQyYK7bGYrRHQ0eXlWi7",
3 "object": "text_completion",
4 "created": 1589478378,
5 "model": "gpt-3.5-turbo",
6 "choices": [
7 {
8 "text": "\n\nThis is indeed a test",
9 "index": 0,
10 "logprobs": null,
11 "finish_reason": "length"
12 }
13 ],
14 "usage": {
15 "prompt_tokens": 5,
16 "completion_tokens": 7,
17 "total_tokens": 12
18 }
19 }
POST https://api.openai.com/v1/completions
https://platform.openai.com/docs/api-reference/chat/object 98/116
11/23/23, 7:33 PM API Reference - OpenAI API
Request body
Note that <|endoftext|> is the document separator that the model sees during training, so if a
prompt is not specified the model will generate as if from the beginning of a new document.
When used with n , best_of controls the number of candidate completions and n specifies
how many to return – best_of must be greater than n .
Note: Because this parameter generates many completions, it can quickly consume your token
quota. Use carefully and ensure that you have reasonable settings for max_tokens and stop .
Accepts a JSON object that maps tokens (specified by their token ID in the GPT tokenizer) to an
associated bias value from -100 to 100. You can use this tokenizer tool (which works for both GPT-
2 and GPT-3) to convert text to token IDs. Mathematically, the bias is added to the logits
generated by the model prior to sampling. The exact effect will vary per model, but values
between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should
result in a ban or exclusive selection of the relevant token.
As an example, you can pass {"50256": -100} to prevent the <|endoftext|> token from being
generated.
return the logprob of the sampled token, so there may be up to logprobs+1 elements in the
response.
The token count of your prompt plus max_tokens cannot exceed the model's context length.
Example Python code for counting tokens.
Note: Because this parameter generates many completions, it can quickly consume your token
quota. Use carefully and ensure that you have reasonable settings for max_tokens and stop .
Determinism is not guaranteed, and you should refer to the system_fingerprint response
parameter to monitor changes in the backend.
https://platform.openai.com/docs/api-reference/chat/object 100/116
11/23/23, 7:33 PM API Reference - OpenAI API
Returns
No streaming Streaming
1 curl https://api.openai.com/v1/completions \
2 -H "Content-Type: application/json" \
3 -H "Authorization: Bearer $OPENAI_API_KEY" \
4 -d '{
5 "model": "gpt-3.5-turbo-instruct",
6 "prompt": "Say this is a test",
7 "max_tokens": 7,
8 "temperature": 0
9 }'
1 {
2 "id": "cmpl-uqkvlQyYK7bGYrRHQ0eXlWi7",
3 "object": "text_completion",
4 "created": 1589478378,
5 "model": "gpt-3.5-turbo-instruct",
6 "system_fingerprint": "fp_44709d6fcb",
7 "choices": [
8 {
9 "text": "\n\nThis is indeed a test",
10 "index": 0,
11 "logprobs": null,
https://platform.openai.com/docs/api-reference/chat/object 101/116
11/23/23, 7:33 PM API Reference - OpenAI API
12 "finish_reason": "length"
13 }
14 ],
15 "usage": {
16 "prompt_tokens": 5,
17 "completion_tokens": 7,
18 "total_tokens": 12
19 }
20 }
Edits Deprecated
Given a prompt and an instruction, the model will return an edited version of the prompt.
The Edits endpoint is deprecated will be shut off on January 4th, 2024.
choices array
A list of edit choices. Can be more than one if n is greater than 1.
Show properties
object string
The object type, which is always edit .
created integer
The Unix timestamp (in seconds) of when the edit was created.
usage object
Usage statistics for the completion request.
Show properties
1 {
2 "object": "edit",
3 "created": 1589478378,
https://platform.openai.com/docs/api-reference/chat/object 102/116
11/23/23, 7:33 PM API Reference - OpenAI API
4 "choices": [
5 {
6 "text": "What day of the week is it?",
7 "index": 0,
8 }
9 ],
10 "usage": {
11 "prompt_tokens": 25,
12 "completion_tokens": 32,
13 "total_tokens": 57
14 }
15 }
POST https://api.openai.com/v1/edits
Creates a new edit for the provided input, instruction, and parameters.
Request body
An alternative to sampling with temperature, called nucleus sampling, where the model considers
the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the
top 10% probability mass are considered.
Returns
1 curl https://api.openai.com/v1/edits \
2 -H "Content-Type: application/json" \
3 -H "Authorization: Bearer $OPENAI_API_KEY" \
4 -d '{
5 "model": "text-davinci-edit-001",
6 "input": "What day of the wek is it?",
7 "instruction": "Fix the spelling mistakes"
8 }'
Response Copy
1 {
2 "object": "edit",
3 "created": 1589478378,
4 "choices": [
5 {
6 "text": "What day of the week is it?",
7 "index": 0,
8 }
9 ],
10 "usage": {
11 "prompt_tokens": 25,
12 "completion_tokens": 32,
13 "total_tokens": 57
14 }
15 }
https://platform.openai.com/docs/api-reference/chat/object 104/116
11/23/23, 7:33 PM API Reference - OpenAI API
Fine-tunes Deprecated
Manage fine-tuning jobs to tailor a model to your specific training data. The updated Fine-
tuning endpoint offers more capabilites and newer models.
The FineTune object represents a legacy fine-tune job that has been created
through the API.
id string
The object identifier, which can be referenced in the API endpoints.
created_at integer
The Unix timestamp (in seconds) for when the fine-tuning job was created.
events array
The list of events that have been observed in the lifecycle of the FineTune job.
Show properties
hyperparams object
The hyperparameters used for the fine-tuning job. See the fine-tuning guide for more details.
Show properties
model string
The base model that is being fine-tuned.
object string
The object type, which is always "fine-tune".
organization_id string
https://platform.openai.com/docs/api-reference/chat/object 105/116
11/23/23, 7:33 PM API Reference - OpenAI API
result_files array
The compiled results files for the fine-tuning job.
status string
The current status of the fine-tuning job, which can be either created , running ,
succeeded , failed , or cancelled .
training_files array
The list of files used for training.
updated_at integer
The Unix timestamp (in seconds) for when the fine-tuning job was last updated.
validation_files array
The list of files used for validation.
1 {
2 "id": "ft-abc123",
3 "object": "fine-tune",
4 "model": "curie",
5 "created_at": 1614807352,
6 "events": [
7 {
8 "object": "fine-tune-event",
9 "created_at": 1614807352,
10 "level": "info",
11 "message": "Job enqueued. Waiting for jobs ahead to complete. Queue nu
12 },
13 {
14 "object": "fine-tune-event",
15 "created_at": 1614807356,
16 "level": "info",
17 "message": "Job started."
18 },
19 {
20 "object": "fine-tune-event",
21 "created_at": 1614807861,
22 "level": "info",
23 "message": "Uploaded snapshot: curie:ft-acmeco-2021-03-03-21-44-20."
24 },
https://platform.openai.com/docs/api-reference/chat/object 106/116
11/23/23, 7:33 PM API Reference - OpenAI API
25 {
26 "object": "fine-tune-event",
27 "created_at": 1614807864,
28 "level": "info",
29 "message": "Uploaded result files: file-abc123."
30 },
31 {
32 "object": "fine-tune-event",
33 "created_at": 1614807864,
34 "level": "info",
35 "message": "Job succeeded."
36 }
37 ],
38 "fine_tuned_model": "curie:ft-acmeco-2021-03-03-21-44-20",
39 "hyperparams": {
40 "batch_size": 4,
41 "learning_rate_multiplier": 0.1,
42 "n_epochs": 4,
43 "prompt_loss_weight": 0.1,
44 },
45 "organization_id": "org-123",
46 "result_files": [
47 {
48 "id": "file-abc123",
49 "object": "file",
50 "bytes": 81509,
51 "created_at": 1614807863,
52 "filename": "compiled_results.csv",
53 "purpose": "fine-tune-results"
54 }
55 ],
56 "status": "succeeded",
57 "validation_files": [],
58 "training_files": [
59 {
60 "id": "file-abc123",
61 "object": "file",
62 "bytes": 1547276,
63 "created_at": 1610062281,
64 "filename": "my-data-train.jsonl",
65 "purpose": "fine-tune"
66 }
67 ],
68 "updated_at": 1614807865,
69 }
https://platform.openai.com/docs/api-reference/chat/object 107/116
11/23/23, 7:33 PM API Reference - OpenAI API
POST https://api.openai.com/v1/fine-tunes
Response includes details of the enqueued job including job status and the name of
the fine-tuned models once complete.
Request body
Your dataset must be formatted as a JSONL file, where each training example is a JSON object
with the keys "prompt" and "completion". Additionally, you must upload your file with the purpose
fine-tune .
By default, the batch size will be dynamically configured to be ~0.2% of the number of examples in
the training set, capped at 256 - in general, we've found that larger batch sizes tend to work better
for larger datasets.
With a beta of 1 (i.e. the F-1 score), precision and recall are given the same weight. A larger beta
score puts more weight on recall and less on precision. A smaller beta score puts more weight on
precision and less on recall.
https://platform.openai.com/docs/api-reference/chat/object 108/116
11/23/23, 7:33 PM API Reference - OpenAI API
This parameter is needed to generate precision, recall, and F1 metrics when doing binary
classification.
By default, the learning rate multiplier is the 0.05, 0.1, or 0.2 depending on final batch_size
(larger learning rates tend to perform better with larger batch sizes). We recommend
experimenting with values in the range 0.02 to 0.2 to see what produces the best results.
If prompts are extremely long (relative to completions), it may make sense to reduce this weight
so as to avoid over-prioritizing learning the prompt.
For example, a suffix of "custom-model-name" would produce a model name like ada:ft-
your-org:custom-model-name-2022-02-15-04-21-04 .
https://platform.openai.com/docs/api-reference/chat/object 109/116
11/23/23, 7:33 PM API Reference - OpenAI API
If you provide this file, the data is used to generate validation metrics periodically during fine-
tuning. These metrics can be viewed in the fine-tuning results file. Your train and validation data
should be mutually exclusive.
Your dataset must be formatted as a JSONL file, where each validation example is a JSON object
with the keys "prompt" and "completion". Additionally, you must upload your file with the purpose
fine-tune .
Returns
A fine-tune object.
1 curl https://api.openai.com/v1/fine-tunes \
2 -H "Content-Type: application/json" \
3 -H "Authorization: Bearer $OPENAI_API_KEY" \
4 -d '{
5 "training_file": "file-abc123"
6 }'
Response Copy
1 {
2 "id": "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
3 "object": "fine-tune",
4 "model": "curie",
5 "created_at": 1614807352,
6 "events": [
7 {
8 "object": "fine-tune-event",
9 "created_at": 1614807352,
10 "level": "info",
11 "message": "Job enqueued. Waiting for jobs ahead to complete. Queue nu
12 }
13 ],
14 "fine_tuned_model": null,
15 "hyperparams": {
16 "batch_size": 4,
17 "learning_rate_multiplier": 0.1,
18 "n_epochs": 4,
https://platform.openai.com/docs/api-reference/chat/object 110/116
11/23/23, 7:33 PM API Reference - OpenAI API
19 "prompt_loss_weight": 0.1,
20 },
21 "organization_id": "org-123",
22 "result_files": [],
23 "status": "pending",
24 "validation_files": [],
25 "training_files": [
26 {
27 "id": "file-abc123",
28 "object": "file",
29 "bytes": 1547276,
30 "created_at": 1610062281,
31 "filename": "my-data-train.jsonl",
32 "purpose": "fine-tune-results"
33 }
34 ],
35 "updated_at": 1614807352,
36 }
GET https://api.openai.com/v1/fine-tunes
Returns
1 curl https://api.openai.com/v1/fine-tunes \
2 -H "Authorization: Bearer $OPENAI_API_KEY"
Response Copy
1 {
2 "object": "list",
3 "data": [
https://platform.openai.com/docs/api-reference/chat/object 111/116
11/23/23, 7:33 PM API Reference - OpenAI API
4 {
5 "id": "ft-AF1WoRqd3aJAHsqc9NY7iL8F",
6 "object": "fine-tune",
7 "model": "curie",
8 "created_at": 1614807352,
9 "fine_tuned_model": null,
10 "hyperparams": { ... },
11 "organization_id": "org-123",
12 "result_files": [],
13 "status": "pending",
14 "validation_files": [],
15 "training_files": [ { ... } ],
16 "updated_at": 1614807352,
17 },
18 { ... },
19 { ... }
20 ]
21 }
GET https://api.openai.com/v1/fine-tunes/{fine_tune_id}
Path parameters
Returns
https://platform.openai.com/docs/api-reference/chat/object 112/116
11/23/23, 7:33 PM API Reference - OpenAI API
1 curl https://api.openai.com/v1/fine-tunes/ft-abc123 \
2 -H "Authorization: Bearer $OPENAI_API_KEY"
Response Copy
1 {
2 "id": "ft-abc123",
3 "object": "fine-tune",
4 "model": "curie",
5 "created_at": 1614807352,
6 "events": [
7 {
8 "object": "fine-tune-event",
9 "created_at": 1614807352,
10 "level": "info",
11 "message": "Job enqueued. Waiting for jobs ahead to complete. Queue nu
12 },
13 {
14 "object": "fine-tune-event",
15 "created_at": 1614807356,
16 "level": "info",
17 "message": "Job started."
18 },
19 {
20 "object": "fine-tune-event",
21 "created_at": 1614807861,
22 "level": "info",
23 "message": "Uploaded snapshot: curie:ft-acmeco-2021-03-03-21-44-20."
24 },
25 {
26 "object": "fine-tune-event",
27 "created_at": 1614807864,
28 "level": "info",
29 "message": "Uploaded result files: file-abc123."
30 },
31 {
32 "object": "fine-tune-event",
33 "created_at": 1614807864,
34 "level": "info",
35 "message": "Job succeeded."
36 }
37 ],
38 "fine_tuned_model": "curie:ft-acmeco-2021-03-03-21-44-20",
39 "hyperparams": {
40 "batch_size": 4,
41 "learning_rate_multiplier": 0.1,
42 "n_epochs": 4,
https://platform.openai.com/docs/api-reference/chat/object 113/116
11/23/23, 7:33 PM API Reference - OpenAI API
43 "prompt_loss_weight": 0.1,
44 },
45 "organization_id": "org-123",
46 "result_files": [
47 {
48 "id": "file-abc123",
49 "object": "file",
50 "bytes": 81509,
51 "created_at": 1614807863,
52 "filename": "compiled_results.csv",
53 "purpose": "fine-tune-results"
54 }
55 ],
56 "status": "succeeded",
57 "validation_files": [],
58 "training_files": [
59 {
60 "id": "file-abc123",
61 "object": "file",
62 "bytes": 1547276,
63 "created_at": 1610062281,
64 "filename": "my-data-train.jsonl",
65 "purpose": "fine-tune"
66 }
67 ],
68 "updated_at": 1614807865,
69 }
POST https://api.openai.com/v1/fine-tunes/{fine_tune_id}/cancel
Path parameters
Returns
https://platform.openai.com/docs/api-reference/chat/object 114/116
11/23/23, 7:33 PM API Reference - OpenAI API
1 curl https://api.openai.com/v1/fine-tunes/ft-AF1WoRqd3aJAHsqc9NY7iL8F/cancel
2 -H "Authorization: Bearer $OPENAI_API_KEY"
Response Copy
1 {
2 "id": "ft-xhrpBbvVUzYGo8oUO1FY4nI7",
3 "object": "fine-tune",
4 "model": "curie",
5 "created_at": 1614807770,
6 "events": [ { ... } ],
7 "fine_tuned_model": null,
8 "hyperparams": { ... },
9 "organization_id": "org-123",
10 "result_files": [],
11 "status": "cancelled",
12 "validation_files": [],
13 "training_files": [
14 {
15 "id": "file-abc123",
16 "object": "file",
17 "bytes": 1547276,
18 "created_at": 1610062281,
19 "filename": "my-data-train.jsonl",
20 "purpose": "fine-tune"
21 }
22 ],
23 "updated_at": 1614807789,
24 }
https://platform.openai.com/docs/api-reference/chat/object 115/116
11/23/23, 7:33 PM API Reference - OpenAI API
created_at integer
level string
message string
https://platform.openai.com/docs/api-reference/chat/object 116/116