Output Schema

The following section describes the structure and fields returned by the Chat Completions API response in JSON Schema format. It includes details about completion metadata, generated choices, token usage statistics, log probabilities, tool calls, and other response-related information.

{
    "definitions": {
        "ChatCompletionAssistantMessage": {
            "properties": {
                "cache_control": {
                    "additionalProperties": true,
                    "description": "Cache control for prompt caching",
                    "title": "Prompt Cache Control",
                    "type": "object"
                },
                "role": {
                    "const": "assistant",
                    "default": "assistant",
                    "description": "The role of the author of this message",
                    "title": "Role",
                    "type": "string"
                },
                "content": {
                    "anyOf": [
                        {
                            "type": "string"
                        },
                        {
                            "items": {
                                "$ref": "#/definitions/ChatCompletionContentPartText"
                            },
                            "type": "array"
                        }
                    ],
                    "description": "The message content",
                    "title": "Content"
                },
                "reasoning_content": {
                    "description": "The reasoning content",
                    "title": "Reasoning Content",
                    "type": "string"
                },
                "name": {
                    "title": "Name",
                    "type": "string"
                },
                "tool_calls": {
                    "description": "The tool calls generated by the mode",
                    "items": {
                        "$ref": "#/definitions/ChatCompletionMessageToolCall"
                    },
                    "title": "Tool Calls",
                    "type": "array"
                }
            },
            "title": "ChatCompletionAssistantMessage",
            "type": "object"
        },
        "ChatCompletionContentPartText": {
            "properties": {
                "type": {
                    "const": "text",
                    "title": "Type",
                    "type": "string"
                },
                "text": {
                    "title": "Text",
                    "type": "string"
                }
            },
            "required": [
                "type",
                "text"
            ],
            "title": "ChatCompletionContentPartText",
            "type": "object"
        },
        "ChatCompletionMessageToolCall": {
            "properties": {
                "id": {
                    "description": "The id of the tool call",
                    "title": "Tools Id",
                    "type": "string"
                },
                "type": {
                    "description": "The type of the tool call. only function is supported currently",
                    "title": "Type",
                    "type": "string"
                },
                "function": {
                    "$ref": "#/definitions/Function",
                    "description": "The function that the model called"
                }
            },
            "required": [
                "id",
                "type",
                "function"
            ],
            "title": "ChatCompletionMessageToolCall",
            "type": "object"
        },
        "FinishReason": {
            "enum": [
                "stop",
                "length",
                "tool_calls",
                "content_filter",
                "malformed_function_call"
            ],
            "title": "FinishReason",
            "type": "string"
        },
        "Function": {
            "properties": {
                "name": {
                    "description": "The name of the function to call",
                    "title": "Name",
                    "type": "string"
                },
                "arguments": {
                    "description": "The function arguments, generated by the model in JSON format. the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema",
                    "title": "Arguments",
                    "type": "string"
                }
            },
            "required": [
                "name",
                "arguments"
            ],
            "title": "Function",
            "type": "object"
        },
        "OpenAIChatCompletionChoice": {
            "properties": {
                "index": {
                    "description": "Index of the choice in th list of choices",
                    "title": "Index",
                    "type": "integer"
                },
                "message": {
                    "$ref": "#/definitions/ChatCompletionAssistantMessage",
                    "description": "a chat completion message generated by the model"
                },
                "finish_reason": {
                    "$ref": "#/definitions/FinishReason",
                    "description": "the reason the model stopped generating tokens. stop if the model hit a natural stop point or a provided stop sequence, length if the maximum number of tokens specified in the request was reached, tool_calls if the model called a tool."
                },
                "logprobs": {
                    "$ref": "#/definitions/OpenAIChoiceLogProbs",
                    "description": "Log probability information for the choice."
                }
            },
            "required": [
                "index",
                "message"
            ],
            "title": "OpenAIChatCompletionChoice",
            "type": "object"
        },
        "OpenAIChatCompletionTokenLogprob": {
            "properties": {
                "token": {
                    "description": "The token.",
                    "title": "Token",
                    "type": "string"
                },
                "bytes": {
                    "description": "A list of integers representing the UTF-8 bytes representation of the token.",
                    "items": {
                        "type": "integer"
                    },
                    "title": "Bytes",
                    "type": "array"
                },
                "logprob": {
                    "description": "The log probability of the tokens",
                    "title": "Logprob",
                    "type": "number"
                }
            },
            "required": [
                "token",
                "logprob"
            ],
            "title": "OpenAIChatCompletionTokenLogprob",
            "type": "object"
        },
        "OpenAIChoiceLogProbs": {
            "properties": {
                "content": {
                    "description": "A list of message content tokens with log probability information.",
                    "items": {
                        "$ref": "#/definitions/OpenAIChatCompletionTokenLogprob"
                    },
                    "title": "Content",
                    "type": "array"
                }
            },
            "title": "OpenAIChoiceLogProbs",
            "type": "object"
        },
        "PromptTokensDetails": {
            "properties": {
                "cached_tokens": {
                    "description": "The number of input tokens read from cache",
                    "title": "Cached Tokens",
                    "type": "integer"
                },
                "cache_write_tokens": {
                    "description": "number of input tokens used to create cache entry",
                    "title": "Cache Write Tokens",
                    "type": "integer"
                }
            },
            "title": "PromptTokensDetails",
            "type": "object"
        },
        "ServiceTier": {
            "enum": [
                "default",
                "priority"
            ],
            "title": "ServiceTier",
            "type": "string"
        },
        "UsageInfo": {
            "additionalProperties": true,
            "properties": {
                "prompt_tokens": {
                    "default": 0,
                    "description": "The number of tokens in the prompt",
                    "title": "Prompt Tokens",
                    "type": "integer"
                },
                "total_tokens": {
                    "default": 0,
                    "description": "The total number of tokens in completion (prompt + completion)",
                    "title": "Total Tokens",
                    "type": "integer"
                },
                "completion_tokens": {
                    "default": 0,
                    "description": "number of tokens generated in the completion",
                    "title": "Completion Tokens",
                    "type": "integer"
                },
                "estimated_cost": {
                    "description": "estimated cost of the completion in USD",
                    "title": "Estimated Cost",
                    "type": "number"
                },
                "prompt_tokens_details": {
                    "$ref": "#/definitions/PromptTokensDetails",
                    "description": "breakdown of prompt tokens usage"
                }
            },
            "title": "UsageInfo",
            "type": "object"
        }
    },
    "required": [
        "model",
        "choices",
        "usage"
    ],
    "title": "OpenAIChatCompletionOut",
    "type": "object",
    "properties": {
        "service_tier": {
            "$ref": "#/definitions/ServiceTier",
            "description": "Service tier the request was processed with",
            "type": "string",
            "title": "ServiceTier"
        },
        "id": {
            "description": "Unique identifier for the completion",
            "title": "Id",
            "type": "string"
        },
        "object": {
            "default": "chat.completion",
            "description": "Object type, which is always chat.completion",
            "title": "Object",
            "type": "string"
        },
        "created": {
            "description": "Unix timestamp of the completion",
            "title": "Created",
            "type": "integer"
        },
        "model": {
            "description": "model name",
            "title": "Model",
            "type": "string",
            "example": "meta-llama/Llama-2-70b-chat-hf"
        },
        "choices": {
            "description": "List of chat completion choices, can be more than one",
            "items": {
                "$ref": "#/definitions/OpenAIChatCompletionChoice"
            },
            "title": "Choices",
            "type": "array"
        },
        "usage": {
            "$ref": "#/definitions/UsageInfo",
            "description": "The usage data for the completion request",
            "type": "object",
            "title": "UsageInfo"
        }
    }
}