{ "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://platform.openai.com/schemas/chat-completion.json", "title": "ChatGPT Chat Completion", "description": "Schema for an OpenAI Chat Completion response object. Represents a chat completion generated by the model, including the generated message choices, token usage, and metadata.", "type": "object", "required": ["id", "object", "created", "model", "choices"], "properties": { "id": { "type": "string", "description": "A unique identifier for the chat completion, prefixed with 'chatcmpl-'", "pattern": "^chatcmpl-" }, "object": { "type": "string", "description": "The object type, which is always 'chat.completion'", "const": "chat.completion" }, "created": { "type": "integer", "description": "The Unix timestamp (in seconds) of when the chat completion was created", "minimum": 0 }, "model": { "type": "string", "description": "The model used for the chat completion (e.g., 'gpt-4o-2024-08-06')", "minLength": 1 }, "choices": { "type": "array", "description": "A list of chat completion choices. Can be more than one if n is greater than 1.", "minItems": 1, "items": { "$ref": "#/$defs/Choice" } }, "usage": { "$ref": "#/$defs/Usage", "description": "Usage statistics for the completion request" }, "system_fingerprint": { "type": "string", "description": "Fingerprint representing the backend configuration the model runs with. Can be used with the seed parameter to understand when backend changes have been made.", "nullable": true }, "service_tier": { "type": "string", "description": "The service tier used for processing the request", "nullable": true } }, "$defs": { "Choice": { "type": "object", "description": "A single completion choice generated by the model", "required": ["index", "message", "finish_reason"], "properties": { "index": { "type": "integer", "description": "The index of the choice in the list of choices", "minimum": 0 }, "message": { "$ref": "#/$defs/AssistantMessage", "description": "A chat completion message generated by the model" }, "finish_reason": { "type": "string", "description": "The reason the model stopped generating tokens", "enum": ["stop", "length", "tool_calls", "content_filter"], "nullable": true }, "logprobs": { "$ref": "#/$defs/Logprobs", "description": "Log probability information for the choice", "nullable": true } } }, "AssistantMessage": { "type": "object", "description": "A message generated by the model in response to the conversation", "required": ["role"], "properties": { "role": { "type": "string", "description": "The role of the author of this message", "const": "assistant" }, "content": { "type": "string", "description": "The contents of the message", "nullable": true }, "tool_calls": { "type": "array", "description": "The tool calls generated by the model, such as function calls", "items": { "$ref": "#/$defs/ToolCall" } }, "refusal": { "type": "string", "description": "The refusal message generated by the model if it declines to respond", "nullable": true }, "audio": { "$ref": "#/$defs/AudioOutput", "description": "Audio response from the model when audio output is requested", "nullable": true } } }, "ToolCall": { "type": "object", "description": "A tool call generated by the model", "required": ["id", "type", "function"], "properties": { "id": { "type": "string", "description": "The ID of the tool call" }, "type": { "type": "string", "description": "The type of the tool. Currently, only 'function' is supported.", "const": "function" }, "function": { "$ref": "#/$defs/FunctionCall", "description": "The function that the model called" } } }, "FunctionCall": { "type": "object", "description": "The function that the model called", "required": ["name", "arguments"], "properties": { "name": { "type": "string", "description": "The name of the function to call", "maxLength": 64 }, "arguments": { "type": "string", "description": "The arguments to call the function with, as generated by the model in JSON format" } } }, "AudioOutput": { "type": "object", "description": "Audio output from the model", "properties": { "id": { "type": "string", "description": "Unique identifier for the audio response" }, "data": { "type": "string", "description": "Base64-encoded audio data" }, "expires_at": { "type": "integer", "description": "Unix timestamp for when the audio expires" }, "transcript": { "type": "string", "description": "Transcript of the audio" } } }, "Logprobs": { "type": "object", "description": "Log probability information for the completion", "properties": { "content": { "type": "array", "description": "A list of message content tokens with log probability information", "nullable": true, "items": { "$ref": "#/$defs/TokenLogprob" } }, "refusal": { "type": "array", "description": "A list of refusal message tokens with log probability information", "nullable": true, "items": { "$ref": "#/$defs/TokenLogprob" } } } }, "TokenLogprob": { "type": "object", "description": "Token with its associated log probability information", "required": ["token", "logprob", "bytes"], "properties": { "token": { "type": "string", "description": "The token string" }, "logprob": { "type": "number", "description": "The log probability of this token" }, "bytes": { "type": "array", "description": "A list of integers representing the UTF-8 bytes of the token", "nullable": true, "items": { "type": "integer" } }, "top_logprobs": { "type": "array", "description": "List of the most likely tokens and their log probabilities at this position", "items": { "type": "object", "required": ["token", "logprob", "bytes"], "properties": { "token": { "type": "string" }, "logprob": { "type": "number" }, "bytes": { "type": "array", "nullable": true, "items": { "type": "integer" } } } } } } }, "Usage": { "type": "object", "description": "Token usage statistics for the completion request", "required": ["prompt_tokens", "completion_tokens", "total_tokens"], "properties": { "prompt_tokens": { "type": "integer", "description": "Number of tokens in the prompt", "minimum": 0 }, "completion_tokens": { "type": "integer", "description": "Number of tokens in the generated completion", "minimum": 0 }, "total_tokens": { "type": "integer", "description": "Total number of tokens used in the request (prompt + completion)", "minimum": 0 }, "completion_tokens_details": { "type": "object", "description": "Breakdown of completion token usage", "properties": { "reasoning_tokens": { "type": "integer", "description": "Tokens generated by the model for internal reasoning", "minimum": 0 }, "accepted_prediction_tokens": { "type": "integer", "description": "Tokens from a prediction that appeared in the completion", "minimum": 0 }, "rejected_prediction_tokens": { "type": "integer", "description": "Tokens from a prediction that did not appear in the completion", "minimum": 0 } } }, "prompt_tokens_details": { "type": "object", "description": "Breakdown of prompt token usage", "properties": { "cached_tokens": { "type": "integer", "description": "Number of cached prompt tokens", "minimum": 0 }, "audio_tokens": { "type": "integer", "description": "Number of audio tokens in the prompt", "minimum": 0 } } } } }, "Message": { "type": "object", "description": "A message in a chat conversation used as input to the model", "required": ["role"], "properties": { "role": { "type": "string", "description": "The role of the message author", "enum": ["system", "user", "assistant", "tool"] }, "content": { "description": "The contents of the message, either a string or an array of content parts", "oneOf": [ { "type": "string" }, { "type": "array", "items": { "$ref": "#/$defs/ContentPart" } } ], "nullable": true }, "name": { "type": "string", "description": "An optional name for the participant to differentiate between participants of the same role" }, "tool_calls": { "type": "array", "description": "Tool calls generated by the model (assistant messages only)", "items": { "$ref": "#/$defs/ToolCall" } }, "tool_call_id": { "type": "string", "description": "The ID of the tool call this message responds to (tool messages only)" }, "refusal": { "type": "string", "description": "The refusal message generated by the model", "nullable": true } } }, "ContentPart": { "type": "object", "description": "A content part within a multi-part message, supporting text and image inputs", "required": ["type"], "properties": { "type": { "type": "string", "description": "The type of content part", "enum": ["text", "image_url", "input_audio"] }, "text": { "type": "string", "description": "The text content (when type is 'text')" }, "image_url": { "type": "object", "description": "The image URL object (when type is 'image_url')", "properties": { "url": { "type": "string", "format": "uri", "description": "The URL of the image or base64-encoded image data" }, "detail": { "type": "string", "description": "The detail level of the image", "enum": ["auto", "low", "high"], "default": "auto" } }, "required": ["url"] }, "input_audio": { "type": "object", "description": "The audio input object (when type is 'input_audio')", "properties": { "data": { "type": "string", "description": "Base64-encoded audio data" }, "format": { "type": "string", "description": "The format of the encoded audio data", "enum": ["wav", "mp3"] } }, "required": ["data", "format"] } } }, "Tool": { "type": "object", "description": "A tool available for the model to call", "required": ["type", "function"], "properties": { "type": { "type": "string", "description": "The type of the tool", "const": "function" }, "function": { "$ref": "#/$defs/FunctionDefinition", "description": "The function definition" } } }, "FunctionDefinition": { "type": "object", "description": "Definition of a function that the model may call", "required": ["name"], "properties": { "name": { "type": "string", "description": "The name of the function", "maxLength": 64, "pattern": "^[a-zA-Z0-9_-]+$" }, "description": { "type": "string", "description": "A description of what the function does" }, "parameters": { "type": "object", "description": "The parameters the function accepts, described as a JSON Schema object" }, "strict": { "type": "boolean", "description": "Whether to enable strict schema adherence when generating the function call", "default": false } } } } }