{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://raw.githubusercontent.com/api-evangelist/apipass/main/json-schema/apipass-chat-completion-request-schema.json",
  "title": "ChatCompletionRequest",
  "description": "OpenAI兼容的聊天补全请求",
  "x-generated": "2026-10-16",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/apipass-openapi.json#/components/schemas/ChatCompletionRequest",
  "properties": {
    "model": {
      "type": "string",
      "title": "Model",
      "description": "模型名称"
    },
    "messages": {
      "items": {
        "$ref": "#/$defs/Message"
      },
      "type": "array",
      "title": "Messages",
      "description": "消息列表"
    },
    "stream": {
      "type": "boolean",
      "title": "Stream",
      "description": "是否流式返回",
      "default": false
    },
    "temperature": {
      "anyOf": [
        {
          "type": "number",
          "maximum": 2.0,
          "minimum": 0.0
        },
        {
          "type": "null"
        }
      ],
      "title": "Temperature",
      "description": "温度参数"
    },
    "max_tokens": {
      "anyOf": [
        {
          "type": "integer",
          "exclusiveMinimum": 0.0
        },
        {
          "type": "null"
        }
      ],
      "title": "Max Tokens",
      "description": "最大token数"
    },
    "max_completion_tokens": {
      "anyOf": [
        {
          "type": "integer",
          "exclusiveMinimum": 0.0
        },
        {
          "type": "null"
        }
      ],
      "title": "Max Completion Tokens",
      "description": "最大输出 token 数（max_tokens 的兼容别名）"
    },
    "top_p": {
      "anyOf": [
        {
          "type": "number",
          "maximum": 1.0,
          "minimum": 0.0
        },
        {
          "type": "null"
        }
      ],
      "title": "Top P",
      "description": "核采样参数"
    },
    "frequency_penalty": {
      "anyOf": [
        {
          "type": "number",
          "maximum": 2.0,
          "minimum": -2.0
        },
        {
          "type": "null"
        }
      ],
      "title": "Frequency Penalty",
      "description": "频率惩罚"
    },
    "presence_penalty": {
      "anyOf": [
        {
          "type": "number",
          "maximum": 2.0,
          "minimum": -2.0
        },
        {
          "type": "null"
        }
      ],
      "title": "Presence Penalty",
      "description": "存在惩罚"
    },
    "tools": {
      "anyOf": [
        {
          "items": {
            "$ref": "#/$defs/Tool"
          },
          "type": "array"
        },
        {
          "type": "null"
        }
      ],
      "title": "Tools",
      "description": "工具列表（如 Google Search）"
    },
    "tool_choice": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "additionalProperties": true,
          "type": "object"
        },
        {
          "type": "null"
        }
      ],
      "title": "Tool Choice",
      "description": "工具选择策略"
    },
    "parallel_tool_calls": {
      "anyOf": [
        {
          "type": "boolean"
        },
        {
          "type": "null"
        }
      ],
      "title": "Parallel Tool Calls",
      "description": "是否允许并行工具调用"
    },
    "memory": {
      "anyOf": [
        {
          "type": "boolean"
        },
        {
          "type": "null"
        }
      ],
      "title": "Memory",
      "description": "是否启用对话记忆",
      "default": false
    },
    "include_thoughts": {
      "anyOf": [
        {
          "type": "boolean"
        },
        {
          "type": "null"
        }
      ],
      "title": "Include Thoughts",
      "description": "是否包含思考过程",
      "default": false
    },
    "reasoning_effort": {
      "anyOf": [
        {
          "type": "string",
          "enum": [
            "low",
            "medium",
            "high",
            "xhigh"
          ]
        },
        {
          "type": "null"
        }
      ],
      "title": "Reasoning Effort",
      "description": "推理强度"
    },
    "response_format": {
      "anyOf": [
        {
          "$ref": "#/$defs/ResponseFormat"
        },
        {
          "type": "null"
        }
      ],
      "description": "响应格式（如结构化输出）"
    },
    "channel": {
      "anyOf": [
        {
          "type": "string",
          "enum": [
            "auto",
            "regular",
            "official"
          ]
        },
        {
          "type": "null"
        }
      ],
      "title": "Channel",
      "description": "ApiPass API channel: auto tries regular then official; explicit channels disable fallback",
      "default": "auto"
    },
    "channel_type": {
      "anyOf": [
        {
          "type": "string",
          "enum": [
            "auto",
            "regular",
            "official"
          ]
        },
        {
          "type": "null"
        }
      ],
      "title": "Channel Type",
      "description": "Alias for channel"
    },
    "_provider_config_id": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Provider Config Id",
      "description": "可选，指定 provider_model_configs.id 强制路由到某个 Provider 配置"
    },
    "_provider_route_id": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Provider Route Id",
      "description": "指定 provider_model_routes.id；不可用时直接失败，不回退其他路由"
    }
  },
  "type": "object",
  "required": [
    "model",
    "messages"
  ],
  "$defs": {
    "ImageUrl": {
      "properties": {
        "url": {
          "type": "string",
          "title": "Url"
        }
      },
      "type": "object",
      "required": [
        "url"
      ],
      "title": "ImageUrl",
      "description": "图片URL"
    },
    "ImageUrlContent": {
      "properties": {
        "type": {
          "type": "string",
          "const": "image_url",
          "title": "Type",
          "default": "image_url"
        },
        "image_url": {
          "$ref": "#/$defs/ImageUrl"
        }
      },
      "type": "object",
      "required": [
        "image_url"
      ],
      "title": "ImageUrlContent",
      "description": "图片URL内容（也可用于视频/音频URL）"
    },
    "InputAudio": {
      "properties": {
        "data": {
          "type": "string",
          "title": "Data"
        },
        "format": {
          "type": "string",
          "title": "Format"
        }
      },
      "type": "object",
      "required": [
        "data",
        "format"
      ],
      "title": "InputAudio",
      "description": "音频输入"
    },
    "InputAudioContent": {
      "properties": {
        "type": {
          "type": "string",
          "const": "input_audio",
          "title": "Type",
          "default": "audio_url"
        },
        "input_audio": {
          "$ref": "#/$defs/InputAudio"
        }
      },
      "type": "object",
      "required": [
        "input_audio"
      ],
      "title": "InputAudioContent",
      "description": "音频内容"
    },
    "Message": {
      "properties": {
        "role": {
          "type": "string",
          "enum": [
            "developer",
            "system",
            "user",
            "assistant",
            "tool"
          ],
          "title": "Role",
          "description": "角色"
        },
        "content": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "items": {
                "anyOf": [
                  {
                    "$ref": "#/$defs/TextContent"
                  },
                  {
                    "$ref": "#/$defs/ImageUrlContent"
                  },
                  {
                    "$ref": "#/$defs/VideoUrlContent"
                  },
                  {
                    "$ref": "#/$defs/InputAudioContent"
                  }
                ]
              },
              "type": "array"
            },
            {
              "type": "null"
            }
          ],
          "title": "Content",
          "description": "内容（字符串或多模态数组）"
        },
        "name": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Name",
          "description": "可选的消息名称"
        },
        "tool_calls": {
          "anyOf": [
            {
              "items": {
                "additionalProperties": true,
                "type": "object"
              },
              "type": "array"
            },
            {
              "type": "null"
            }
          ],
          "title": "Tool Calls",
          "description": "助手发起的工具调用"
        },
        "tool_call_id": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Tool Call Id",
          "description": "工具消息对应的调用 ID"
        }
      },
      "type": "object",
      "required": [
        "role"
      ],
      "title": "Message",
      "description": "聊天消息（支持多模态）"
    },
    "ResponseFormat": {
      "properties": {
        "type": {
          "type": "string",
          "title": "Type",
          "description": "格式类型，如 'json_schema'"
        },
        "json_schema": {
          "anyOf": [
            {
              "additionalProperties": true,
              "type": "object"
            },
            {
              "type": "null"
            }
          ],
          "title": "Json Schema",
          "description": "JSON Schema 定义"
        }
      },
      "type": "object",
      "required": [
        "type"
      ],
      "title": "ResponseFormat",
      "description": "响应格式定义"
    },
    "TextContent": {
      "properties": {
        "type": {
          "type": "string",
          "const": "text",
          "title": "Type",
          "default": "text"
        },
        "text": {
          "type": "string",
          "title": "Text"
        }
      },
      "type": "object",
      "required": [
        "text"
      ],
      "title": "TextContent",
      "description": "文本内容"
    },
    "Tool": {
      "properties": {
        "type": {
          "type": "string",
          "title": "Type",
          "description": "工具类型，如 'function'"
        },
        "function": {
          "anyOf": [
            {
              "additionalProperties": true,
              "type": "object"
            },
            {
              "type": "null"
            }
          ],
          "title": "Function",
          "description": "函数定义"
        }
      },
      "type": "object",
      "required": [
        "type"
      ],
      "title": "Tool",
      "description": "工具定义"
    },
    "VideoUrl": {
      "properties": {
        "url": {
          "type": "string",
          "title": "Url"
        }
      },
      "type": "object",
      "required": [
        "url"
      ],
      "title": "VideoUrl",
      "description": "视频URL"
    },
    "VideoUrlContent": {
      "properties": {
        "type": {
          "type": "string",
          "const": "video_url",
          "title": "Type",
          "default": "video_url"
        },
        "video_url": {
          "$ref": "#/$defs/VideoUrl"
        }
      },
      "type": "object",
      "required": [
        "video_url"
      ],
      "title": "VideoUrlContent",
      "description": "视频URL内容"
    }
  }
}