{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/elastix/json-schema/elastix-chat-completion-schema.json",
  "title": "ChatCompletion",
  "x-generated": "2026-11-29",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/elastix-openapi.json#/components/schemas/ChatCompletion",
  "type": "object",
  "required": [
    "id",
    "object",
    "created",
    "model",
    "choices"
  ],
  "properties": {
    "id": {
      "type": "string"
    },
    "object": {
      "type": "string",
      "const": "chat.completion"
    },
    "created": {
      "type": "integer",
      "description": "Unix timestamp (seconds)."
    },
    "model": {
      "type": "string"
    },
    "choices": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "index",
          "message",
          "finish_reason"
        ],
        "properties": {
          "index": {
            "type": "integer"
          },
          "message": {
            "$ref": "#/$defs/ChatMessage"
          },
          "finish_reason": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "stop",
              "length",
              "tool_calls",
              null
            ],
            "description": "Why generation stopped. `tool_calls` means the model wants to call one or more tools (see `message.tool_calls`)."
          }
        }
      }
    },
    "usage": {
      "$ref": "#/$defs/Usage"
    }
  },
  "$defs": {
    "ChatMessage": {
      "type": "object",
      "required": [
        "role",
        "content"
      ],
      "properties": {
        "role": {
          "type": "string",
          "enum": [
            "system",
            "developer",
            "user",
            "assistant",
            "tool"
          ],
          "description": "The author of the message. `\"developer\"` is an alias for `\"system\"` and is treated identically. A system/developer message is optional, but if present it must be the first message in the array. Use `\"tool\"` to return the result of a tool call back to the model."
        },
        "content": {
          "type": [
            "string",
            "null"
          ],
          "description": "The message text. Text only — image (vision) and audio content are not supported yet (both planned). May be `null` on an assistant message that only requests tool calls (see `tool_calls`)."
        },
        "tool_calls": {
          "type": "array",
          "description": "Tool calls the model wants to make. Present only on an assistant message; when set, `content` is typically `null`.",
          "items": {
            "$ref": "#/$defs/ToolCall"
          }
        },
        "tool_call_id": {
          "type": "string",
          "description": "Required on a `\"tool\"` message: the `id` of the tool call this message provides the result for."
        }
      }
    },
    "ToolCall": {
      "type": "object",
      "required": [
        "id",
        "type",
        "function"
      ],
      "description": "A tool call requested by the model.",
      "properties": {
        "id": {
          "type": "string",
          "description": "Identifier for this call. Echo it back as `tool_call_id` on the `\"tool\"` message that carries the result."
        },
        "type": {
          "type": "string",
          "const": "function"
        },
        "function": {
          "type": "object",
          "required": [
            "name",
            "arguments"
          ],
          "properties": {
            "name": {
              "type": "string"
            },
            "arguments": {
              "type": "string",
              "description": "The call arguments as a JSON-encoded string (not a JSON object). Parse it before use; the model may occasionally emit invalid JSON."
            }
          }
        }
      }
    },
    "Usage": {
      "type": "object",
      "properties": {
        "prompt_tokens": {
          "type": "integer"
        },
        "completion_tokens": {
          "type": "integer"
        },
        "total_tokens": {
          "type": "integer"
        }
      }
    }
  }
}