{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/kymaapi-com/json-schema/kymaapi-com-chat-completion-response-schema.json",
  "title": "ChatCompletionResponse",
  "x-generated": "2026-10-30",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/kymaapi-com-openapi.json#/components/schemas/ChatCompletionResponse",
  "type": "object",
  "properties": {
    "id": {
      "type": "string"
    },
    "object": {
      "type": "string",
      "enum": [
        "chat.completion"
      ]
    },
    "created": {
      "type": "integer"
    },
    "model": {
      "type": "string",
      "description": "Actual model used"
    },
    "choices": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "index": {
            "type": "integer"
          },
          "message": {
            "$ref": "#/$defs/Message"
          },
          "finish_reason": {
            "type": "string",
            "enum": [
              "stop",
              "length",
              "tool_calls"
            ]
          }
        },
        "required": [
          "index",
          "message",
          "finish_reason"
        ]
      }
    },
    "usage": {
      "type": "object",
      "properties": {
        "prompt_tokens": {
          "type": "integer"
        },
        "completion_tokens": {
          "type": "integer"
        },
        "total_tokens": {
          "type": "integer"
        },
        "cached_tokens": {
          "type": "integer",
          "description": "Number of prompt tokens served from cache"
        },
        "cost": {
          "type": "number",
          "description": "Cost in USD for this request"
        },
        "cache_discount": {
          "type": "number",
          "description": "Amount saved from prompt caching in USD"
        }
      },
      "required": [
        "prompt_tokens",
        "completion_tokens",
        "total_tokens"
      ]
    }
  },
  "required": [
    "id",
    "object",
    "created",
    "model",
    "choices",
    "usage"
  ],
  "$defs": {
    "Message": {
      "type": "object",
      "properties": {
        "role": {
          "type": "string",
          "enum": [
            "system",
            "user",
            "assistant",
            "tool"
          ]
        },
        "content": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {}
              },
              "description": "Multimodal content (text + images)"
            }
          ]
        },
        "tool_calls": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {}
          },
          "description": "Tool calls made by the assistant"
        },
        "tool_call_id": {
          "type": "string",
          "description": "ID of the tool call this message is responding to"
        }
      },
      "required": [
        "role",
        "content"
      ]
    }
  }
}