{
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "bearerFormat": "AISA API Key",
        "description": "您的 AIsa API 密钥，作为 Bearer token 提供。",
        "scheme": "bearer",
        "type": "http"
      }
    }
  },
  "info": {
    "description": "通过 AIsa 提供的 Anthropic 兼容 Messages API。使用 Claude 模型发送结构化消息并生成响应。",
    "title": "Claude Messages API",
    "version": "1.0.0"
  },
  "openapi": "3.0.3",
  "paths": {
    "/messages": {
      "post": {
        "description": "向 Claude 模型发送结构化对话并接收响应。兼容 Anthropic Messages API。",
        "operationId": "createMessage",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "properties": {
                  "max_tokens": {
                    "description": "停止前可生成的最大词元数。",
                    "example": 1024,
                    "type": "integer"
                  },
                  "messages": {
                    "description": "对话轮次。",
                    "example": [
                      {
                        "content": "Hello, Claude",
                        "role": "user"
                      }
                    ],
                    "items": {
                      "properties": {
                        "content": {
                          "description": "字符串或内容块数组。",
                          "oneOf": [
                            {
                              "type": "string"
                            },
                            {
                              "items": {
                                "type": "object"
                              },
                              "type": "array"
                            }
                          ]
                        },
                        "role": {
                          "enum": [
                            "user",
                            "assistant"
                          ],
                          "type": "string"
                        }
                      },
                      "required": [
                        "role",
                        "content"
                      ],
                      "type": "object"
                    },
                    "type": "array"
                  },
                  "metadata": {
                    "properties": {
                      "user_id": {
                        "description": "外部用户 ID（不含个人身份信息）。",
                        "type": "string"
                      }
                    },
                    "type": "object"
                  },
                  "model": {
                    "description": "Claude 模型标识符。示例：claude-opus-4-7、claude-sonnet-4-6、claude-haiku-4-5-20251001。",
                    "example": "claude-sonnet-4-6",
                    "type": "string"
                  },
                  "service_tier": {
                    "default": "auto",
                    "enum": [
                      "auto",
                      "standard_only"
                    ],
                    "type": "string"
                  },
                  "stop_sequences": {
                    "description": "用于停止生成的自定义序列。",
                    "items": {
                      "type": "string"
                    },
                    "type": "array"
                  },
                  "stream": {
                    "default": false,
                    "description": "启用 SSE 流式传输。",
                    "type": "boolean"
                  },
                  "system": {
                    "description": "系统提示词。字符串或文本块数组。",
                    "oneOf": [
                      {
                        "type": "string"
                      },
                      {
                        "items": {
                          "type": "object"
                        },
                        "type": "array"
                      }
                    ]
                  },
                  "temperature": {
                    "default": 1.0,
                    "description": "随机性。0 = 确定性，1 = 创造性。",
                    "format": "float",
                    "maximum": 1.0,
                    "minimum": 0.0,
                    "type": "number"
                  },
                  "thinking": {
                    "description": "为复杂推理启用扩展思考。",
                    "properties": {
                      "budget_tokens": {
                        "example": 10000,
                        "type": "integer"
                      },
                      "display": {
                        "enum": [
                          "summarized",
                          "omitted"
                        ],
                        "type": "string"
                      },
                      "type": {
                        "enum": [
                          "enabled"
                        ],
                        "type": "string"
                      }
                    },
                    "type": "object"
                  },
                  "tool_choice": {
                    "description": "模型使用工具的方式。",
                    "properties": {
                      "disable_parallel_tool_use": {
                        "default": false,
                        "type": "boolean"
                      },
                      "name": {
                        "description": "当 type 为 tool 时必填。",
                        "type": "string"
                      },
                      "type": {
                        "enum": [
                          "auto",
                          "any",
                          "tool",
                          "none"
                        ],
                        "type": "string"
                      }
                    },
                    "type": "object"
                  },
                  "tools": {
                    "description": "模型可使用的工具。",
                    "items": {
                      "properties": {
                        "description": {
                          "type": "string"
                        },
                        "input_schema": {
                          "type": "object"
                        },
                        "name": {
                          "type": "string"
                        },
                        "type": {
                          "example": "custom",
                          "type": "string"
                        }
                      },
                      "required": [
                        "name",
                        "input_schema"
                      ],
                      "type": "object"
                    },
                    "type": "array"
                  },
                  "top_k": {
                    "description": "每个词元仅从概率最高的 K 个选项中采样。",
                    "type": "integer"
                  },
                  "top_p": {
                    "description": "核采样。用于替代 temperature。",
                    "format": "float",
                    "type": "number"
                  }
                },
                "required": [
                  "model",
                  "max_tokens",
                  "messages"
                ],
                "type": "object"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "properties": {
                    "content": {
                      "description": "响应内容块（text、tool_use、thinking 等）。",
                      "items": {
                        "type": "object"
                      },
                      "type": "array"
                    },
                    "id": {
                      "example": "msg_024e7cf42f5d47cfa6982b5ff8b55642",
                      "type": "string"
                    },
                    "model": {
                      "example": "claude-sonnet-4-6",
                      "type": "string"
                    },
                    "role": {
                      "example": "assistant",
                      "type": "string"
                    },
                    "stop_reason": {
                      "enum": [
                        "end_turn",
                        "stop_sequence",
                        "max_tokens",
                        "tool_use"
                      ],
                      "type": "string"
                    },
                    "stop_sequence": {
                      "nullable": true,
                      "type": "string"
                    },
                    "type": {
                      "example": "message",
                      "type": "string"
                    },
                    "usage": {
                      "properties": {
                        "cache_creation_input_tokens": {
                          "type": "integer"
                        },
                        "cache_read_input_tokens": {
                          "type": "integer"
                        },
                        "input_tokens": {
                          "type": "integer"
                        },
                        "output_tokens": {
                          "type": "integer"
                        }
                      },
                      "type": "object"
                    }
                  },
                  "type": "object"
                }
              }
            },
            "description": "成功响应"
          },
          "400": {
            "description": "请求参数无效"
          },
          "401": {
            "description": "缺少 API 密钥或 API 密钥无效"
          },
          "429": {
            "description": "超出速率限制"
          },
          "500": {
            "description": "内部服务器错误"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "summary": "创建消息"
      }
    }
  },
  "security": [
    {
      "BearerAuth": []
    }
  ],
  "servers": [
    {
      "url": "https://api.aisa.one/v1"
    }
  ]
}
