Skip to main content
POST
/
v1
/
messages
curl -X POST https://www.geeknow.top/v1/messages \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-20250514",
    "max_tokens": 1024,
    "system": "你是一个严谨的技术顾问。",
    "messages": [
      {
        "role": "user",
        "content": "解释一下 API 网关为什么需要限流。"
      }
    ]
  }'
{
  "id": "msg_abc123",
  "type": "message",
  "role": "assistant",
  "model": "claude-sonnet-4-20250514",
  "content": [
    {
      "type": "text",
      "text": "API 网关限流可以保护上游服务,避免突发流量耗尽资源,并为不同用户提供稳定的服务质量。"
    }
  ],
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 32,
    "output_tokens": 45
  }
}

Documentation Index

Fetch the complete documentation index at: https://mercury-eab3b728.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

Claude 消息接口

Claude Messages 接口保留 Anthropic 原生请求结构,适合已有 Claude SDK 或原生提示词结构的业务迁移。路由会进入 Claude relay 格式,并根据渠道分发到对应上游。

认证

Authorization: Bearer YOUR_API_KEY
也可以使用 Claude 原生请求头:
x-api-key: YOUR_API_KEY
anthropic-version: 2023-06-01

请求体

model
string
required
Claude 模型名称。
messages
array<object>
required
对话消息数组。Claude 原生格式中消息角色通常为 userassistant
system
string | array<object>
系统提示词。Claude 不使用 system 角色消息,而是通过该字段传递系统指令。
max_tokens
integer
最大输出 token 数。多数 Claude 请求都应显式传入。
stream
boolean
是否启用 SSE 流式输出。
temperature
number
采样温度。
top_p
number
核采样参数。
top_k
integer
Top-K 采样参数。
stop_sequences
array<string>
停止序列。
tools
array<object>
Claude 工具列表,通常包含 namedescriptioninput_schema
tool_choice
object
控制工具选择策略,例如 { "type": "tool", "name": "get_weather" }
thinking
object
扩展思考配置,例如 { "type": "enabled", "budget_tokens": 10000 }
metadata
object
业务侧元数据,例如 user_id

请求示例

curl -X POST https://www.geeknow.top/v1/messages \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-20250514",
    "max_tokens": 1024,
    "system": "你是一个严谨的技术顾问。",
    "messages": [
      {
        "role": "user",
        "content": "解释一下 API 网关为什么需要限流。"
      }
    ]
  }'

多模态输入

curl -X POST https://www.geeknow.top/v1/messages \
  -H "x-api-key: YOUR_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-20250514",
    "max_tokens": 1024,
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "image",
            "source": {
              "type": "url",
              "url": "https://example.com/architecture.png"
            }
          },
          { "type": "text", "text": "这张架构图里有哪些风险点?" }
        ]
      }
    ]
  }'

工具调用

curl -X POST https://www.geeknow.top/v1/messages \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-20250514",
    "max_tokens": 1024,
    "messages": [
      { "role": "user", "content": "上海今天适合骑行吗?" }
    ],
    "tools": [
      {
        "name": "get_weather",
        "description": "查询城市天气",
        "input_schema": {
          "type": "object",
          "properties": {
            "city": { "type": "string" }
          },
          "required": ["city"]
        }
      }
    ]
  }'

响应示例

{
  "id": "msg_abc123",
  "type": "message",
  "role": "assistant",
  "model": "claude-sonnet-4-20250514",
  "content": [
    {
      "type": "text",
      "text": "API 网关限流可以保护上游服务,避免突发流量耗尽资源,并为不同用户提供稳定的服务质量。"
    }
  ],
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 32,
    "output_tokens": 45
  }
}

相关接口