Get chat completion
get /chat/completions/{completion_id}
Get a stored chat completion. Only Chat Completions that have been created
with the store parameter set to true will be returned.
Path Parameters
completion_id: string
Returns
-
ChatCompletion object { id, choices, created, 6 more }Represents a chat completion response returned by model, based on the provided input.
-
id: stringA unique identifier for the chat completion.
-
choices: array of object { finish_reason, index, logprobs, message }A list of chat completion choices. Can be more than one if
nis greater than 1.-
finish_reason: "stop" or "length" or "tool_calls" or 2 moreThe reason the model stopped generating tokens. This will be
stopif the model hit a natural stop point or a provided stop sequence,lengthif the maximum number of tokens specified in the request was reached,content_filterif content was omitted due to a flag from our content filters,tool_callsif the model called a tool, orfunction_call(deprecated) if the model called a function. Read the Model Spec for more.-
"stop" -
"length" -
"tool_calls" -
"content_filter" -
"function_call"
-
-
index: numberThe index of the choice in the list of choices.
-
logprobs: object { content, refusal }Log probability information for the choice.
-
content: array of ChatCompletionTokenLogprobA list of message content tokens with log probability information.
-
token: stringThe token.
-
bytes: array of numberA list of integers representing the UTF-8 bytes representation of the token. Useful in instances where characters are represented by multiple tokens and their byte representations must be combined to generate the correct text representation. Can be
nullif there is no bytes representation for the token. -
logprob: numberThe log probability of this token, if it is within the top 20 most likely tokens. Otherwise, the value
-9999.0is used to signify that the token is very unlikely. -
top_logprobs: array of object { token, bytes, logprob }List of the most likely tokens and their log probability, at this token position. The number of entries may be fewer than the requested
top_logprobs.-
token: stringThe token.
-
bytes: array of numberA list of integers representing the UTF-8 bytes representation of the token. Useful in instances where characters are represented by multiple tokens and their byte representations must be combined to generate the correct text representation. Can be
nullif there is no bytes representation for the token. -
logprob: numberThe log probability of this token, if it is within the top 20 most likely tokens. Otherwise, the value
-9999.0is used to signify that the token is very unlikely.
-
-
-
refusal: array of ChatCompletionTokenLogprobA list of message refusal tokens with log probability information.
-
token: stringThe token.
-
bytes: array of numberA list of integers representing the UTF-8 bytes representation of the token. Useful in instances where characters are represented by multiple tokens and their byte representations must be combined to generate the correct text representation. Can be
nullif there is no bytes representation for the token. -
logprob: numberThe log probability of this token, if it is within the top 20 most likely tokens. Otherwise, the value
-9999.0is used to signify that the token is very unlikely. -
top_logprobs: array of object { token, bytes, logprob }List of the most likely tokens and their log probability, at this token position. The number of entries may be fewer than the requested
top_logprobs.
-
-
-
message: ChatCompletionMessageA chat completion message generated by the model.
-
content: stringThe contents of the message.
-
refusal: stringThe refusal message generated by the model.
-
role: "assistant"The role of the author of this message.
"assistant"
-
annotations: optional array of object { type, url_citation }Annotations for the message, when applicable, as when using the web search tool.
-
type: "url_citation"The type of the URL citation. Always
url_citation."url_citation"
-
url_citation: object { end_index, start_index, title, url }A URL citation when using web search.
-
end_index: numberThe index of the last character of the URL citation in the message.
-
start_index: numberThe index of the first character of the URL citation in the message.
-
title: stringThe title of the web resource.
-
url: stringThe URL of the web resource.
-
-
-
audio: optional ChatCompletionAudioIf the audio output modality is requested, this object contains data about the audio response from the model. Learn more.
-
id: stringUnique identifier for this audio response.
-
data: stringBase64 encoded audio bytes generated by the model, in the format specified in the request.
-
expires_at: numberThe Unix timestamp (in seconds) for when this audio response will no longer be accessible on the server for use in multi-turn conversations.
-
transcript: stringTranscript of the audio generated by the model.
-
-
function_call: optional object { arguments, name }Deprecated and replaced by
tool_calls. The name and arguments of a function that should be called, as generated by the model.-
arguments: stringThe arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function.
-
name: stringThe name of the function to call.
-
-
tool_calls: optional array of ChatCompletionMessageToolCallThe tool calls generated by the model, such as function calls.
-
ChatCompletionMessageFunctionToolCall object { id, function, type }A call to a function tool created by the model.
-
id: stringThe ID of the tool call.
-
function: object { arguments, name }The function that the model called.
-
arguments: stringThe arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function.
-
name: stringThe name of the function to call.
-
-
type: "function"The type of the tool. Currently, only
functionis supported."function"
-
-
ChatCompletionMessageCustomToolCall object { id, custom, type }A call to a custom tool created by the model.
-
id: stringThe ID of the tool call.
-
custom: object { input, name }The custom tool that the model called.
-
input: stringThe input for the custom tool call generated by the model.
-
name: stringThe name of the custom tool to call.
-
-
type: "custom"The type of the tool. Always
custom."custom"
-
-
-
-
-
created: numberThe Unix timestamp (in seconds) of when the chat completion was created.
-
model: stringThe model used for the chat completion.
-
object: "chat.completion"The object type, which is always
chat.completion."chat.completion"
-
moderation: optional object { input, output }Moderation results for the request input and generated output, if moderated completions were requested.
-
input: object { model, results, type } or object { code, message, type }Moderation for the request input.
-
ModerationResults object { model, results, type }Successful moderation results for the request input or generated output.
-
model: stringThe moderation model used to generate the results.
-
results: array of object { categories, category_applied_input_types, category_scores, 3 more }A list of moderation results.
-
categories: map[boolean]A dictionary of moderation categories to booleans, True if the input is flagged under this category.
-
category_applied_input_types: map[array of "text" or "image"]Which modalities of input are reflected by the score for each category.
-
"text" -
"image"
-
-
category_scores: map[number]A dictionary of moderation categories to scores.
-
flagged: booleanA boolean indicating whether the content was flagged by any category.
-
model: stringThe moderation model that produced this result.
-
type: "moderation_result"The object type, which was always
moderation_resultfor successful moderation results."moderation_result"
-
-
type: "moderation_results"The object type, which is always
moderation_results."moderation_results"
-
-
Error object { code, message, type }An error produced while attempting moderation.
-
code: stringThe error code.
-
message: stringThe error message.
-
type: "error"The object type, which is always
error."error"
-
-
-
output: object { model, results, type } or object { code, message, type }Moderation for the generated output.
-
ModerationResults object { model, results, type }Successful moderation results for the request input or generated output.
-
model: stringThe moderation model used to generate the results.
-
results: array of object { categories, category_applied_input_types, category_scores, 3 more }A list of moderation results.
-
categories: map[boolean]A dictionary of moderation categories to booleans, True if the input is flagged under this category.
-
category_applied_input_types: map[array of "text" or "image"]Which modalities of input are reflected by the score for each category.
-
"text" -
"image"
-
-
category_scores: map[number]A dictionary of moderation categories to scores.
-
flagged: booleanA boolean indicating whether the content was flagged by any category.
-
model: stringThe moderation model that produced this result.
-
type: "moderation_result"The object type, which was always
moderation_resultfor successful moderation results."moderation_result"
-
-
type: "moderation_results"The object type, which is always
moderation_results."moderation_results"
-
-
Error object { code, message, type }An error produced while attempting moderation.
-
code: stringThe error code.
-
message: stringThe error message.
-
type: "error"The object type, which is always
error."error"
-
-
-
-
service_tier: optional "auto" or "default" or "flex" or 2 moreSpecifies the processing type used for serving the request.
- If set to 'auto', then the request will be processed with the service tier configured in the Project settings. Unless otherwise configured, the Project will use 'default'.
- If set to 'default', then the request will be processed with the standard pricing and performance for the selected model.
- If set to 'flex' or 'priority', then the request will be processed with the corresponding service tier.
- When not set, the default behavior is 'auto'.
When the
service_tierparameter is set, the response body will include theservice_tiervalue based on the processing mode actually used to serve the request. This response value may be different from the value set in the parameter.-
"auto" -
"default" -
"flex" -
"scale" -
"priority"
-
system_fingerprint: optional stringThis fingerprint represents the backend configuration that the model runs with.
Can be used in conjunction with the
seedrequest parameter to understand when backend changes have been made that might impact determinism. -
usage: optional CompletionUsageUsage statistics for the completion request.
-
completion_tokens: numberNumber of tokens in the generated completion.
-
prompt_tokens: numberNumber of tokens in the prompt.
-
total_tokens: numberTotal number of tokens used in the request (prompt + completion).
-
completion_tokens_details: optional object { accepted_prediction_tokens, audio_tokens, reasoning_tokens, rejected_prediction_tokens }Breakdown of tokens used in a completion.
-
accepted_prediction_tokens: optional numberWhen using Predicted Outputs, the number of tokens in the prediction that appeared in the completion.
-
audio_tokens: optional numberAudio input tokens generated by the model.
-
reasoning_tokens: optional numberTokens generated by the model for reasoning.
-
rejected_prediction_tokens: optional numberWhen using Predicted Outputs, the number of tokens in the prediction that did not appear in the completion. However, like reasoning tokens, these tokens are still counted in the total completion tokens for purposes of billing, output, and context window limits.
-
-
prompt_tokens_details: optional object { audio_tokens, cached_tokens }Breakdown of tokens used in the prompt.
-
audio_tokens: optional numberAudio input tokens present in the prompt.
-
cached_tokens: optional numberCached tokens present in the prompt.
-
-
-
Example
curl https://api.openai.com/v1/chat/completions/$COMPLETION_ID \
-H "Authorization: Bearer $OPENAI_API_KEY"
Response
{
"id": "id",
"choices": [
{
"finish_reason": "stop",
"index": 0,
"logprobs": {
"content": [
{
"token": "token",
"bytes": [
0
],
"logprob": 0,
"top_logprobs": [
{
"token": "token",
"bytes": [
0
],
"logprob": 0
}
]
}
],
"refusal": [
{
"token": "token",
"bytes": [
0
],
"logprob": 0,
"top_logprobs": [
{
"token": "token",
"bytes": [
0
],
"logprob": 0
}
]
}
]
},
"message": {
"content": "content",
"refusal": "refusal",
"role": "assistant",
"annotations": [
{
"type": "url_citation",
"url_citation": {
"end_index": 0,
"start_index": 0,
"title": "title",
"url": "https://example.com"
}
}
],
"audio": {
"id": "id",
"data": "data",
"expires_at": 0,
"transcript": "transcript"
},
"function_call": {
"arguments": "arguments",
"name": "name"
},
"tool_calls": [
{
"id": "id",
"function": {
"arguments": "arguments",
"name": "name"
},
"type": "function"
}
]
}
}
],
"created": 0,
"model": "model",
"object": "chat.completion",
"moderation": {
"input": {
"model": "model",
"results": [
{
"categories": {
"foo": true
},
"category_applied_input_types": {
"foo": [
"text"
]
},
"category_scores": {
"foo": 0
},
"flagged": true,
"model": "model",
"type": "moderation_result"
}
],
"type": "moderation_results"
},
"output": {
"model": "model",
"results": [
{
"categories": {
"foo": true
},
"category_applied_input_types": {
"foo": [
"text"
]
},
"category_scores": {
"foo": 0
},
"flagged": true,
"model": "model",
"type": "moderation_result"
}
],
"type": "moderation_results"
}
},
"service_tier": "auto",
"system_fingerprint": "system_fingerprint",
"usage": {
"completion_tokens": 0,
"prompt_tokens": 0,
"total_tokens": 0,
"completion_tokens_details": {
"accepted_prediction_tokens": 0,
"audio_tokens": 0,
"reasoning_tokens": 0,
"rejected_prediction_tokens": 0
},
"prompt_tokens_details": {
"audio_tokens": 0,
"cached_tokens": 0
}
}
}
Example
curl https://api.openai.com/v1/chat/completions/chatcmpl-abc123 \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json"
Response
{
"object": "chat.completion",
"id": "chatcmpl-abc123",
"model": "gpt-4o-2024-08-06",
"created": 1738960610,
"request_id": "req_ded8ab984ec4bf840f37566c1011c417",
"tool_choice": null,
"usage": {
"total_tokens": 31,
"completion_tokens": 18,
"prompt_tokens": 13
},
"seed": 4944116822809979520,
"top_p": 1.0,
"temperature": 1.0,
"presence_penalty": 0.0,
"frequency_penalty": 0.0,
"system_fingerprint": "fp_50cad350e4",
"input_user": null,
"service_tier": "default",
"tools": null,
"metadata": {},
"choices": [
{
"index": 0,
"message": {
"content": "Mind of circuits hum, \nLearning patterns in silence— \nFuture's quiet spark.",
"role": "assistant",
"tool_calls": null,
"function_call": null
},
"finish_reason": "stop",
"logprobs": null
}
],
"response_format": null
}