Skip to content

Claude 聊天

POST /v1/messages

Anthropic Claude Messages API 格式的请求。 需要在请求头中包含 anthropic-version

基本信息

项目内容
Base URLhttps://www.yunzhuhub.cn
标签Claude格式(Messages)
Operation IDcreateMessage

认证

  • BearerAuth:使用 Bearer Token 认证。 格式: Authorization: Bearer sk-xxxxxx

密钥安全

请只使用你自己的 API Key。示例中的 <YOUR_API_KEY> 必须在本地替换,不要把真实密钥提交到代码仓库或发送给他人。

参数

名称位置类型必填说明
anthropic-versionheaderstringAnthropic API 版本
x-api-keyheaderstringAnthropic API Key (可选,也可使用 Bearer Token)

请求体

Content-Type: application/json

json
{
  "title": "ClaudeRequest",
  "type": "object",
  "required": [
    "model",
    "messages",
    "max_tokens"
  ],
  "properties": {
    "model": {
      "type": "string",
      "example": "<MODEL_ID>"
    },
    "messages": {
      "type": "array",
      "items": {
        "$ref": "#/components/schemas/ClaudeMessage"
      }
    },
    "system": {
      "oneOf": [
        {
          "type": "string"
        },
        {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {}
          }
        }
      ]
    },
    "cache_control": {
      "type": "object",
      "properties": {}
    },
    "inference_geo": {
      "type": "string"
    },
    "max_tokens": {
      "type": "integer",
      "minimum": 1
    },
    "temperature": {
      "type": "number",
      "minimum": 0,
      "maximum": 1
    },
    "top_p": {
      "type": "number"
    },
    "top_k": {
      "type": "integer"
    },
    "stream": {
      "type": "boolean"
    },
    "stop_sequences": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "tools": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "input_schema": {
            "type": "object",
            "properties": {}
          }
        }
      }
    },
    "tool_choice": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "enum": [
                "auto",
                "any",
                "tool",
                "none"
              ]
            },
            "name": {
              "type": "string"
            }
          }
        }
      ]
    },
    "thinking": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "enabled",
            "disabled"
          ]
        },
        "budget_tokens": {
          "type": "integer"
        }
      }
    },
    "context_management": {
      "type": "object",
      "properties": {}
    },
    "output_config": {
      "type": "object",
      "properties": {}
    },
    "output_format": {
      "type": "object",
      "properties": {}
    },
    "container": {
      "oneOf": [
        {
          "type": "string"
        },
        {
          "type": "object",
          "properties": {}
        }
      ]
    },
    "mcp_servers": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {}
      }
    },
    "metadata": {
      "type": "object",
      "properties": {
        "user_id": {
          "type": "string"
        }
      }
    },
    "speed": {
      "type": "string",
      "enum": [
        "standard",
        "fast"
      ]
    },
    "service_tier": {
      "type": "string",
      "enum": [
        "auto",
        "standard_only"
      ]
    }
  }
}

请求示例

以下示例只用于复制到本地终端,不会从文档站发送请求。

bash
curl --request POST 'https://www.yunzhuhub.cn/v1/messages' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'Content-Type: application/json' \
  --data '<REQUEST_JSON>'

响应

200 成功创建响应

json
{
  "title": "ClaudeResponse",
  "type": "object",
  "properties": {
    "id": {
      "type": "string"
    },
    "type": {
      "type": "string",
      "example": "message"
    },
    "role": {
      "type": "string",
      "example": "assistant"
    },
    "content": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string"
          },
          "text": {
            "type": "string"
          }
        }
      }
    },
    "model": {
      "type": "string"
    },
    "stop_reason": {
      "type": "string",
      "enum": [
        "end_turn",
        "max_tokens",
        "stop_sequence",
        "tool_use"
      ]
    },
    "usage": {
      "type": "object",
      "properties": {
        "input_tokens": {
          "type": "integer"
        },
        "output_tokens": {
          "type": "integer"
        },
        "cache_creation_input_tokens": {
          "type": "integer"
        },
        "cache_read_input_tokens": {
          "type": "integer"
        }
      }
    }
  }
}

云筑Hub 文档。底层项目基于 New API