Streaming Schema

This section provides a detailed description of the parameters returned in streaming responses, using JSON Schema format.

{
    "definitions": {
        "ChatMessageRole": {
            "enum": [
                "system",
                "user",
                "assistant",
                "tool"
            ],
            "title": "ChatMessageRole",
            "type": "string"
        },
        "FinishReason": {
            "enum": [
                "stop",
                "length",
                "tool_calls",
                "content_filter",
                "malformed_function_call"
            ],
            "title": "FinishReason",
            "type": "string"
        },
        "OpenAIChatCompletionStreamChoice": {
            "properties": {
                "index": {
                    "description": "The position of this choice within list of generated completions",
                    "title": "Index",
                    "type": "integer"
                },
                "delta": {
                    "$ref": "#/definitions/OpenAIDeltaMessage",
                    "description": "Chat completion data generated by streamed model responses"
                },
                "logprobs": {
                    "$ref": "#/definitions/OpenAIChoiceLogProbs",
                    "description": "Log probability information for the choice."
                },
                "finish_reason": {
                    "$ref": "#/definitions/FinishReason",
                    "description": "The reason generation was terminated, such as reaching a stop sequence, hitting the token limit, or invoking a tool."
                }
            },
            "required": [
                "index",
                "delta"
            ],
            "title": "OpenAIChatCompletionStreamChoice",
            "type": "object"
        },
        "OpenAIChatCompletionTokenLogprob": {
            "properties": {
                "token": {
                    "description": "The unit Token",
                    "title": "Token",
                    "type": "string"
                },
                "bytes": {
                    "description": "List of int representing the UTF-8 bytes representation of tokens.",
                    "items": {
                        "type": "integer"
                    },
                    "title": "Bytes",
                    "type": "array"
                },
                "logprob": {
                    "description": "Log probability of the tokens",
                    "title": "Logprob",
                    "type": "number"
                }
            },
            "required": [
                "token",
                "logprob"
            ],
            "title": "OpenAIChatCompletionTokenLogprob",
            "type": "object"
        },
        "OpenAIChoiceLogProbs": {
            "properties": {
                "content": {
                    "description": "List of message content tokens with log probability information.",
                    "items": {
                        "$ref": "#/definitions/OpenAIChatCompletionTokenLogprob"
                    },
                    "title": "Content",
                    "type": "array"
                }
            },
            "title": "OpenAIChoiceLogProbs",
            "type": "object"
        },
        "OpenAIDeltaMessage": {
            "properties": {
                "role": {
                    "$ref": "#/definitions/ChatMessageRole",
                    "description": "Role of the author of this message"
                },
                "content": {
                    "description": "Chunk message content",
                    "title": "Content",
                    "type": "string"
                },
                "reasoning_content": {
                    "description": "Reasoning content",
                    "title": "Reasoning Content",
                    "type": "string"
                },
                "tool_calls": {
                    "description": "Tool calls generated by the model",
                    "items": {
                        "$ref": "#/definitions/OpenAIDeltaToolCall"
                    },
                    "title": "Tools Called",
                    "type": "array"
                }
            },
            "title": "OpenAIDeltaMessage",
            "type": "object"
        },
        "OpenAIDeltaToolCall": {
            "properties": {
                "index": {
                    "title": "Index",
                    "type": "integer"
                },
                "id": {
                    "title": "Tool Id",
                    "type": "string"
                },
                "function": {
                    "$ref": "#/definitions/OpenAIDeltaToolCallFunction"
                },
                "type": {
                    "const": "function",
                    "title": "Type",
                    "type": "string"
                }
            },
            "required": [
                "index"
            ],
            "title": "OpenAIDeltaToolCall",
            "type": "object"
        },
        "OpenAIDeltaToolCallFunction": {
            "properties": {
                "arguments": {
                    "title": "Arguments",
                    "type": "string"
                },
                "name": {
                    "title": "Name",
                    "type": "string"
                }
            },
            "title": "OpenAIDeltaToolCallFunction",
            "type": "object"
        },
        "PromptTokensDetails": {
            "properties": {
                "cached_tokens": {
                    "description": "Total number of input tokens read from cache",
                    "title": "Cached Tokens",
                    "type": "integer"
                },
                "cache_write_tokens": {
                    "description": "Total 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": "Total number of tokens in the prompt",
                    "title": "Prompt Tokens",
                    "type": "integer"
                },
                "total_tokens": {
                    "default": 0,
                    "description": "Total number of tokens in the completion (prompt + completion)",
                    "title": "Total Tokens",
                    "type": "integer"
                },
                "completion_tokens": {
                    "default": 0,
                    "description": "Total number of tokens generated in the completion",
                    "title": "Completion Tokens",
                    "type": "integer"
                },
                "estimated_cost": {
                    "description": "Total 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"
    ],
    "title": "OpenAIChatCompletionStreamOut",
    "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.chunk",
            "description": "Object type, which is always chat.completion.chunk",
            "title": "Object",
            "type": "string"
        },
        "created": {
            "description": "Unix system 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/OpenAIChatCompletionStreamChoice"
            },
            "title": "Choices",
            "type": "array"
        },
        "usage": {
            "$ref": "#/definitions/UsageInfo",
            "description": "Usage info about request and response",
            "type": "object",
            "title": "UsageInfo"
        }
    }
}