{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/hubris-pw/json-schema/hubris-pw-chat-completion-request-schema.json",
  "title": "ChatCompletionRequest",
  "x-generated": "2026-11-12",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/hubris-pw-openapi.json#/components/schemas/ChatCompletionRequest",
  "type": "object",
  "properties": {
    "model": {
      "type": "string",
      "minLength": 1
    },
    "models": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "minItems": 1,
      "maxItems": 10,
      "description": "Список fallback-моделей. Если основная (`model`) недоступна — попробует следующие по порядку. Биллинг по фактически использованной (см. `model` в ответе)."
    },
    "messages": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/Message"
      },
      "minItems": 1
    },
    "tools": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/ToolDefinition"
      }
    },
    "tool_choice": {
      "$ref": "#/$defs/ToolChoice"
    },
    "parallel_tool_calls": {
      "type": "boolean"
    },
    "response_format": {
      "$ref": "#/$defs/ResponseFormat"
    },
    "temperature": {
      "type": "number",
      "minimum": 0,
      "maximum": 2
    },
    "top_p": {
      "type": "number",
      "minimum": 0,
      "maximum": 1
    },
    "n": {
      "type": "integer",
      "minimum": 1
    },
    "stop": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      ]
    },
    "max_tokens": {
      "type": "integer",
      "minimum": 0,
      "exclusiveMinimum": true
    },
    "max_completion_tokens": {
      "type": "integer",
      "minimum": 0,
      "exclusiveMinimum": true
    },
    "frequency_penalty": {
      "type": "number",
      "minimum": -2,
      "maximum": 2
    },
    "presence_penalty": {
      "type": "number",
      "minimum": -2,
      "maximum": 2
    },
    "logit_bias": {
      "type": "object",
      "additionalProperties": {
        "type": "number"
      }
    },
    "seed": {
      "type": "integer"
    },
    "logprobs": {
      "type": "boolean"
    },
    "top_logprobs": {
      "type": "integer",
      "minimum": 0,
      "maximum": 20
    },
    "modalities": {
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "text",
          "image",
          "audio"
        ]
      },
      "description": "Какие модальности должна вернуть модель. По умолчанию `[\"text\"]`. Для генерации изображений: `[\"image\",\"text\"]` (модели типа gemini-flash-image) либо `[\"image\"]` (модели типа flux/sdxl). Для голосового ответа: `[\"text\",\"audio\"]` вместе с полем `audio` и обязательным `stream: true`. Поддерживается только моделями, у которых соответствующая модальность есть в `output_modalities`."
    },
    "audio": {
      "type": "object",
      "properties": {
        "voice": {
          "type": "string",
          "description": "Голос озвучки, например `alloy`."
        },
        "format": {
          "type": "string",
          "description": "Формат аудио ответа: `wav`, `mp3`, `pcm16` и т.п."
        }
      },
      "required": [
        "voice",
        "format"
      ],
      "description": "Настройки голосового ответа. Требует `modalities: [\"text\",\"audio\"]` и `stream: true`."
    },
    "image_config": {
      "type": "object",
      "additionalProperties": {
        "nullable": true
      },
      "description": "Параметры image-gen моделей: aspect_ratio (`1:1`, `16:9`, `9:16` и т.д.), image_size (`0.5K`, `1K`, `2K`, `4K`), а также model-specific поля. Конкретный набор зависит от модели — см. карточку модели в каталоге."
    },
    "stream": {
      "type": "boolean"
    },
    "stream_options": {
      "$ref": "#/$defs/StreamOptions"
    },
    "user": {
      "type": "string"
    },
    "reasoning_effort": {
      "type": "string",
      "enum": [
        "none",
        "minimal",
        "low",
        "medium",
        "high",
        "xhigh",
        "max"
      ]
    }
  },
  "required": [
    "model",
    "messages"
  ],
  "$defs": {
    "AssistantMessage": {
      "type": "object",
      "properties": {
        "role": {
          "type": "string",
          "enum": [
            "assistant"
          ]
        },
        "content": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "array",
              "items": {
                "$ref": "#/$defs/TextContentPart"
              }
            },
            {
              "nullable": true
            }
          ]
        },
        "tool_calls": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/ToolCall"
          }
        },
        "name": {
          "type": "string"
        },
        "refusal": {
          "type": [
            "string",
            "null"
          ]
        },
        "images": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/GeneratedImage"
          }
        },
        "audio": {
          "$ref": "#/$defs/AudioOutput"
        }
      },
      "required": [
        "role"
      ]
    },
    "AssistantMessageInput": {
      "allOf": [
        {
          "$ref": "#/$defs/AssistantMessage"
        },
        {
          "type": "object",
          "properties": {
            "tool_calls": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/ToolCallInput"
              }
            },
            "cache_control": {
              "type": [
                "object",
                "null"
              ],
              "properties": {
                "type": {
                  "type": "string",
                  "enum": [
                    "ephemeral"
                  ]
                },
                "ttl": {
                  "type": "string",
                  "enum": [
                    "5m",
                    "1h"
                  ]
                }
              },
              "required": [
                "type"
              ],
              "description": "Маркер кеша на весь элемент — для клиентов, которые ставят его сюда. Основное место — `cache_control` на content-блоке."
            }
          }
        }
      ]
    },
    "AudioOutput": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "data": {
          "type": "string",
          "description": "Аудио ответа в base64 (формат — из запроса `audio.format`)."
        },
        "transcript": {
          "type": "string",
          "description": "Текстовая расшифровка сказанного."
        },
        "expires_at": {
          "type": "number"
        }
      }
    },
    "CacheControl": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "ephemeral"
          ]
        },
        "ttl": {
          "type": "string",
          "enum": [
            "5m",
            "1h"
          ]
        }
      },
      "required": [
        "type"
      ]
    },
    "ContentPart": {
      "oneOf": [
        {
          "$ref": "#/$defs/TextContentPart"
        },
        {
          "$ref": "#/$defs/ImageUrlContentPart"
        },
        {
          "$ref": "#/$defs/InputAudioContentPart"
        },
        {
          "$ref": "#/$defs/VideoUrlContentPart"
        }
      ]
    },
    "FunctionToolDefinition": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "function"
          ]
        },
        "function": {
          "type": "object",
          "properties": {
            "name": {
              "type": "string"
            },
            "description": {
              "type": "string"
            },
            "parameters": {
              "type": "object",
              "additionalProperties": {
                "nullable": true
              },
              "default": {
                "type": "object",
                "properties": {}
              },
              "description": "JSON Schema объект с описанием параметров функции. Без него — функция без аргументов."
            },
            "strict": {
              "type": [
                "boolean",
                "null"
              ]
            }
          },
          "required": [
            "name"
          ]
        },
        "cache_control": {
          "type": [
            "object",
            "null"
          ],
          "properties": {
            "type": {
              "type": "string",
              "enum": [
                "ephemeral"
              ]
            },
            "ttl": {
              "type": "string",
              "enum": [
                "5m",
                "1h"
              ]
            }
          },
          "required": [
            "type"
          ],
          "description": "Маркер кеша на весь элемент — для клиентов, которые ставят его сюда. Основное место — `cache_control` на content-блоке."
        }
      },
      "required": [
        "type",
        "function"
      ]
    },
    "GeneratedImage": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "image_url"
          ]
        },
        "image_url": {
          "type": "object",
          "properties": {
            "url": {
              "type": "string",
              "description": "Base64 data URL вида `data:image/png;base64,...`"
            }
          },
          "required": [
            "url"
          ]
        }
      },
      "required": [
        "type",
        "image_url"
      ]
    },
    "ImageUrlContentPart": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "image_url"
          ]
        },
        "image_url": {
          "type": "object",
          "properties": {
            "url": {
              "type": "string",
              "description": "URL изображения или data:image/<mime>;base64,..."
            },
            "detail": {
              "type": "string",
              "enum": [
                "auto",
                "low",
                "high"
              ]
            }
          },
          "required": [
            "url"
          ]
        },
        "cache_control": {
          "$ref": "#/$defs/CacheControl"
        }
      },
      "required": [
        "type",
        "image_url"
      ]
    },
    "InputAudioContentPart": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "input_audio"
          ]
        },
        "input_audio": {
          "type": "object",
          "properties": {
            "data": {
              "type": "string",
              "minLength": 1,
              "description": "Аудио в base64 БЕЗ префикса `data:` — только сами данные."
            },
            "format": {
              "type": "string",
              "enum": [
                "wav",
                "mp3",
                "aiff",
                "aac",
                "ogg",
                "flac",
                "m4a",
                "pcm16",
                "pcm24"
              ],
              "description": "Формат присланного аудио."
            }
          },
          "required": [
            "data",
            "format"
          ]
        },
        "cache_control": {
          "$ref": "#/$defs/CacheControl"
        }
      },
      "required": [
        "type",
        "input_audio"
      ]
    },
    "Message": {
      "oneOf": [
        {
          "$ref": "#/$defs/SystemMessage"
        },
        {
          "$ref": "#/$defs/UserMessage"
        },
        {
          "$ref": "#/$defs/AssistantMessageInput"
        },
        {
          "$ref": "#/$defs/ToolMessage"
        }
      ]
    },
    "ResponseFormat": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "enum": [
                "text"
              ]
            }
          },
          "required": [
            "type"
          ]
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "enum": [
                "json_object"
              ]
            }
          },
          "required": [
            "type"
          ]
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "enum": [
                "json_schema"
              ]
            },
            "json_schema": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string"
                },
                "description": {
                  "type": "string"
                },
                "schema": {
                  "type": "object",
                  "additionalProperties": {
                    "nullable": true
                  }
                },
                "strict": {
                  "type": "boolean"
                }
              },
              "required": [
                "name",
                "schema"
              ]
            }
          },
          "required": [
            "type",
            "json_schema"
          ]
        }
      ]
    },
    "ServerToolDefinition": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "type"
      ]
    },
    "StreamOptions": {
      "type": "object",
      "properties": {
        "include_usage": {
          "type": "boolean",
          "description": "Hubris автоматически выставляет true для всех stream-запросов. Указывать необязательно."
        }
      }
    },
    "SystemMessage": {
      "type": "object",
      "properties": {
        "role": {
          "type": "string",
          "enum": [
            "system"
          ]
        },
        "content": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "array",
              "items": {
                "$ref": "#/$defs/ContentPart"
              }
            }
          ]
        },
        "name": {
          "type": "string"
        },
        "cache_control": {
          "type": [
            "object",
            "null"
          ],
          "properties": {
            "type": {
              "type": "string",
              "enum": [
                "ephemeral"
              ]
            },
            "ttl": {
              "type": "string",
              "enum": [
                "5m",
                "1h"
              ]
            }
          },
          "required": [
            "type"
          ],
          "description": "Маркер кеша на весь элемент — для клиентов, которые ставят его сюда. Основное место — `cache_control` на content-блоке."
        }
      },
      "required": [
        "role",
        "content"
      ]
    },
    "TextContentPart": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "text"
          ]
        },
        "text": {
          "type": "string"
        },
        "cache_control": {
          "$ref": "#/$defs/CacheControl"
        }
      },
      "required": [
        "type",
        "text"
      ]
    },
    "ToolCall": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "type": {
          "type": "string",
          "enum": [
            "function"
          ]
        },
        "function": {
          "type": "object",
          "properties": {
            "name": {
              "type": "string"
            },
            "arguments": {
              "type": "string",
              "description": "JSON-строка с аргументами функции."
            }
          },
          "required": [
            "name",
            "arguments"
          ]
        }
      },
      "required": [
        "id",
        "type",
        "function"
      ]
    },
    "ToolCallInput": {
      "allOf": [
        {
          "$ref": "#/$defs/ToolCall"
        },
        {
          "type": "object",
          "properties": {
            "cache_control": {
              "type": [
                "object",
                "null"
              ],
              "properties": {
                "type": {
                  "type": "string",
                  "enum": [
                    "ephemeral"
                  ]
                },
                "ttl": {
                  "type": "string",
                  "enum": [
                    "5m",
                    "1h"
                  ]
                }
              },
              "required": [
                "type"
              ],
              "description": "Маркер кеша на весь элемент — для клиентов, которые ставят его сюда. Основное место — `cache_control` на content-блоке."
            }
          }
        }
      ]
    },
    "ToolChoice": {
      "anyOf": [
        {
          "type": "string",
          "enum": [
            "none",
            "auto",
            "required"
          ]
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "enum": [
                "function"
              ]
            },
            "function": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string"
                }
              },
              "required": [
                "name"
              ]
            }
          },
          "required": [
            "type",
            "function"
          ]
        }
      ]
    },
    "ToolDefinition": {
      "anyOf": [
        {
          "$ref": "#/$defs/FunctionToolDefinition"
        },
        {
          "$ref": "#/$defs/ServerToolDefinition"
        }
      ]
    },
    "ToolMessage": {
      "type": "object",
      "properties": {
        "role": {
          "type": "string",
          "enum": [
            "tool"
          ]
        },
        "content": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "array",
              "items": {
                "$ref": "#/$defs/TextContentPart"
              }
            }
          ]
        },
        "tool_call_id": {
          "type": "string"
        },
        "cache_control": {
          "type": [
            "object",
            "null"
          ],
          "properties": {
            "type": {
              "type": "string",
              "enum": [
                "ephemeral"
              ]
            },
            "ttl": {
              "type": "string",
              "enum": [
                "5m",
                "1h"
              ]
            }
          },
          "required": [
            "type"
          ],
          "description": "Маркер кеша на весь элемент — для клиентов, которые ставят его сюда. Основное место — `cache_control` на content-блоке."
        }
      },
      "required": [
        "role",
        "content",
        "tool_call_id"
      ]
    },
    "UserMessage": {
      "type": "object",
      "properties": {
        "role": {
          "type": "string",
          "enum": [
            "user"
          ]
        },
        "content": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "array",
              "items": {
                "$ref": "#/$defs/ContentPart"
              }
            }
          ]
        },
        "name": {
          "type": "string"
        },
        "cache_control": {
          "type": [
            "object",
            "null"
          ],
          "properties": {
            "type": {
              "type": "string",
              "enum": [
                "ephemeral"
              ]
            },
            "ttl": {
              "type": "string",
              "enum": [
                "5m",
                "1h"
              ]
            }
          },
          "required": [
            "type"
          ],
          "description": "Маркер кеша на весь элемент — для клиентов, которые ставят его сюда. Основное место — `cache_control` на content-блоке."
        }
      },
      "required": [
        "role",
        "content"
      ]
    },
    "VideoUrlContentPart": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "video_url"
          ]
        },
        "video_url": {
          "type": "object",
          "properties": {
            "url": {
              "type": "string",
              "minLength": 1,
              "description": "Ссылка на публичный ролик YouTube или `data:video/<mime>;base64,...`."
            },
            "processing": {
              "type": "string",
              "enum": [
                "agentic",
                "static"
              ],
              "description": "Режим обработки видео у Gemini: `agentic` — модель сама перемещается по ролику (дешевле на длинных видео), `static` — просмотр целиком с фиксированной частотой кадров."
            }
          },
          "required": [
            "url"
          ]
        }
      },
      "required": [
        "type",
        "video_url"
      ]
    }
  }
}