{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/hubris-pw/json-schema/hubris-pw-anthropic-messages-request-schema.json",
  "title": "AnthropicMessagesRequest",
  "x-generated": "2026-11-12",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/hubris-pw-openapi.json#/components/schemas/AnthropicMessagesRequest",
  "type": "object",
  "properties": {
    "model": {
      "type": "string",
      "minLength": 1,
      "description": "Имя модели. Принимаются и Anthropic-имена (`claude-sonnet-4-5`, `claude-3-5-sonnet-20241022`, `claude-haiku-4-5-latest`), и каноничные OR-имена (`anthropic/claude-sonnet-4.6`). См. /docs/integrations/claude-code."
    },
    "models": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "minItems": 1,
      "maxItems": 10,
      "description": "Список резервных моделей (расширение Hubris). Если `model` отвечает 429/5xx или не начинает ответ вовремя — запрос уходит к следующей по порядку. Модель, не принимающая содержимое запроса (картинки, документы), пропускается. Биллинг по фактически ответившей модели."
    },
    "max_tokens": {
      "type": "integer",
      "minimum": 0,
      "exclusiveMinimum": true,
      "description": "Максимальное число токенов в ответе. Обязательное поле."
    },
    "messages": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/AnthropicMessage"
      },
      "minItems": 1,
      "description": "Массив сообщений диалога. Чередование ролей user/assistant."
    },
    "system": {
      "$ref": "#/$defs/AnthropicSystem"
    },
    "metadata": {
      "type": "object",
      "properties": {
        "user_id": {
          "type": "string"
        }
      }
    },
    "stop_sequences": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "stream": {
      "type": "boolean"
    },
    "temperature": {
      "type": "number",
      "minimum": 0,
      "maximum": 1
    },
    "top_p": {
      "type": "number",
      "minimum": 0,
      "maximum": 1
    },
    "top_k": {
      "type": "integer",
      "minimum": 0,
      "exclusiveMinimum": true
    },
    "tools": {
      "type": "array",
      "items": {
        "anyOf": [
          {
            "$ref": "#/$defs/AnthropicServerTool"
          },
          {
            "$ref": "#/$defs/AnthropicTool"
          }
        ]
      }
    },
    "tool_choice": {
      "$ref": "#/$defs/AnthropicToolChoice"
    },
    "thinking": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "enabled",
            "disabled",
            "adaptive"
          ]
        },
        "budget_tokens": {
          "type": "integer",
          "minimum": 0
        }
      },
      "required": [
        "type"
      ],
      "description": "Extended thinking (Claude 4+). enabled + budget_tokens — бюджет на размышления; adaptive — режим Claude 5."
    },
    "service_tier": {
      "type": "string"
    }
  },
  "required": [
    "model",
    "max_tokens",
    "messages"
  ],
  "$defs": {
    "AnthropicCacheControl": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "ephemeral"
          ]
        },
        "ttl": {
          "type": "string",
          "enum": [
            "5m",
            "1h"
          ]
        }
      },
      "required": [
        "type"
      ]
    },
    "AnthropicContentBlock": {
      "anyOf": [
        {
          "$ref": "#/$defs/AnthropicTextBlock"
        },
        {
          "$ref": "#/$defs/AnthropicImageBlock"
        },
        {
          "$ref": "#/$defs/AnthropicToolUseBlock"
        },
        {
          "$ref": "#/$defs/AnthropicToolResultBlock"
        },
        {
          "$ref": "#/$defs/AnthropicDocumentBlock"
        },
        {
          "$ref": "#/$defs/AnthropicThinkingBlock"
        },
        {
          "$ref": "#/$defs/AnthropicRedactedThinkingBlock"
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string"
            }
          },
          "required": [
            "type"
          ]
        }
      ]
    },
    "AnthropicDocumentBlock": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "document"
          ]
        },
        "source": {
          "type": "object",
          "additionalProperties": {
            "nullable": true
          }
        },
        "title": {
          "type": "string"
        },
        "context": {
          "type": "string"
        },
        "citations": {
          "type": "object",
          "additionalProperties": {
            "nullable": true
          }
        },
        "cache_control": {
          "$ref": "#/$defs/AnthropicCacheControl"
        }
      },
      "required": [
        "type",
        "source"
      ]
    },
    "AnthropicImageBlock": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "image"
          ]
        },
        "source": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "type": {
                  "type": "string",
                  "enum": [
                    "base64"
                  ]
                },
                "media_type": {
                  "type": "string",
                  "enum": [
                    "image/jpeg",
                    "image/png",
                    "image/gif",
                    "image/webp"
                  ]
                },
                "data": {
                  "type": "string"
                }
              },
              "required": [
                "type",
                "media_type",
                "data"
              ]
            },
            {
              "type": "object",
              "properties": {
                "type": {
                  "type": "string",
                  "enum": [
                    "url"
                  ]
                },
                "url": {
                  "type": "string",
                  "format": "uri"
                }
              },
              "required": [
                "type",
                "url"
              ]
            }
          ]
        },
        "cache_control": {
          "$ref": "#/$defs/AnthropicCacheControl"
        }
      },
      "required": [
        "type",
        "source"
      ]
    },
    "AnthropicMessage": {
      "type": "object",
      "properties": {
        "role": {
          "type": "string",
          "enum": [
            "user",
            "assistant",
            "system"
          ]
        },
        "content": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "array",
              "items": {
                "$ref": "#/$defs/AnthropicContentBlock"
              }
            }
          ]
        }
      },
      "required": [
        "role",
        "content"
      ]
    },
    "AnthropicRedactedThinkingBlock": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "redacted_thinking"
          ]
        },
        "data": {
          "type": "string"
        }
      },
      "required": [
        "type",
        "data"
      ]
    },
    "AnthropicServerTool": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "pattern": "^[a-z_]+_\\d{8}$"
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128
        },
        "max_uses": {
          "type": "integer",
          "minimum": 0,
          "exclusiveMinimum": true
        },
        "allowed_domains": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "blocked_domains": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "user_location": {
          "type": "object",
          "additionalProperties": {
            "nullable": true
          }
        },
        "cache_control": {
          "$ref": "#/$defs/AnthropicCacheControl"
        }
      },
      "required": [
        "type",
        "name"
      ]
    },
    "AnthropicSystem": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "array",
          "items": {
            "$ref": "#/$defs/AnthropicTextBlock"
          }
        }
      ],
      "description": "Системный промпт. Строка или массив text-блоков (для гибкого cache_control)."
    },
    "AnthropicTextBlock": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "text"
          ]
        },
        "text": {
          "type": "string"
        },
        "cache_control": {
          "$ref": "#/$defs/AnthropicCacheControl"
        },
        "citations": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": {
              "nullable": true
            }
          }
        }
      },
      "required": [
        "type",
        "text"
      ]
    },
    "AnthropicThinkingBlock": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "thinking"
          ]
        },
        "thinking": {
          "type": "string"
        },
        "signature": {
          "type": "string"
        }
      },
      "required": [
        "type",
        "thinking"
      ]
    },
    "AnthropicTool": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128,
          "pattern": "^[a-zA-Z0-9_-]+$"
        },
        "description": {
          "type": "string"
        },
        "input_schema": {
          "type": "object",
          "additionalProperties": {
            "nullable": true
          }
        },
        "cache_control": {
          "$ref": "#/$defs/AnthropicCacheControl"
        },
        "type": {
          "type": "string"
        }
      },
      "required": [
        "name",
        "input_schema"
      ]
    },
    "AnthropicToolChoice": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "enum": [
                "auto"
              ]
            },
            "disable_parallel_tool_use": {
              "type": "boolean"
            }
          },
          "required": [
            "type"
          ]
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "enum": [
                "any"
              ]
            },
            "disable_parallel_tool_use": {
              "type": "boolean"
            }
          },
          "required": [
            "type"
          ]
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "enum": [
                "tool"
              ]
            },
            "name": {
              "type": "string"
            },
            "disable_parallel_tool_use": {
              "type": "boolean"
            }
          },
          "required": [
            "type",
            "name"
          ]
        },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "enum": [
                "none"
              ]
            }
          },
          "required": [
            "type"
          ]
        }
      ]
    },
    "AnthropicToolResultBlock": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "tool_result"
          ]
        },
        "tool_use_id": {
          "type": "string"
        },
        "content": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "array",
              "items": {
                "anyOf": [
                  {
                    "$ref": "#/$defs/AnthropicTextBlock"
                  },
                  {
                    "$ref": "#/$defs/AnthropicImageBlock"
                  }
                ]
              }
            }
          ]
        },
        "is_error": {
          "type": "boolean"
        },
        "cache_control": {
          "$ref": "#/$defs/AnthropicCacheControl"
        }
      },
      "required": [
        "type",
        "tool_use_id"
      ]
    },
    "AnthropicToolUseBlock": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "tool_use"
          ]
        },
        "id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "input": {
          "nullable": true
        },
        "cache_control": {
          "$ref": "#/$defs/AnthropicCacheControl"
        }
      },
      "required": [
        "type",
        "id",
        "name"
      ]
    }
  }
}