API 参考

Anthropic Messages API

使用 Anthropic Messages 格式调用模型,读取文本与内容块回复。

POST https://api.aigocode.dev/v1/messages

本接口使用 Anthropic 协议,适用于 Claude、Grok、GLM、Kimi、DeepSeek 等通过该协议接入的模型,鉴权为 x-api-key: YOUR_API_KEY。

直接调用时,选择包含目标模型且支持外接调用的分组;在 Claude Code 等工具中使用时,按对应工具教程配置。

请求参数

字段类型必填说明
modelstring是当前分组中的模型 ID
max_tokensinteger建议填写最大输出 Token 数
messagesarray是对话消息列表,角色为 user 或 assistant
systemstring / array否系统指令,放在请求体顶层
streamboolean否设置为 true 时使用 SSE 流式返回

messages[].content 可使用文本字符串,或按模型能力使用内容块数组。多轮对话时,顺序传入历史消息和本轮输入。

请求示例

下面使用 claude-opus-5-5。调用 GLM、Kimi、DeepSeek 或 Grok 时,填写对应模型 ID 与分组 Key,请求仍采用 Messages 格式。

export AIGOCODE_API_KEY="填写支持 Anthropic 协议且可外接分组的 API Key"

curl "https://api.aigocode.dev/v1/messages" \
  -H "x-api-key: $AIGOCODE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "claude-opus-5-5",
  "max_tokens": 512,
  "messages": [
    {
      "role": "user",
      "content": "Reply with exactly: Hello from AIGoCode!"
    }
  ]
}'
$env:AIGOCODE_API_KEY = "填写支持 Anthropic 协议且可外接分组的 API Key"

$body = @{
  model = "claude-opus-5-5"
  max_tokens = 512
  messages = @(
    @{
      role = "user"
      content = "Reply with exactly: Hello from AIGoCode!"
    }
  )
} | ConvertTo-Json -Depth 6

$response = Invoke-RestMethod `
  -Method Post `
  -Uri "https://api.aigocode.dev/v1/messages" `
  -Headers @{ "x-api-key" = $env:AIGOCODE_API_KEY } `
  -ContentType "application/json; charset=utf-8" `
  -Body ([System.Text.Encoding]::UTF8.GetBytes($body))

$response | ConvertTo-Json -Depth 20
set "AIGOCODE_API_KEY=填写支持 Anthropic 协议且可外接分组的 API Key"

curl.exe "https://api.aigocode.dev/v1/messages" ^
  -H "x-api-key: %AIGOCODE_API_KEY%" ^
  -H "Content-Type: application/json" ^
  -d "{\"model\":\"claude-opus-5-5\",\"max_tokens\":512,\"messages\":[{\"role\":\"user\",\"content\":\"Reply with exactly: Hello from AIGoCode!\"}]}"

响应

{
  "id": "msg_example",
  "type": "message",
  "role": "assistant",
  "model": "claude-opus-5-5",
  "content": [
    {
      "type": "text",
      "text": "Hello from AIGoCode!"
    }
  ],
  "stop_reason": "end_turn"
}

遍历 content,读取 type 为 text 的文本块;工具调用等其他内容块按各自的 type 处理。stop_reason 表示本轮生成的结束原因。

用量位于 usage,包含输入、输出及可能返回的缓存读写信息。实际额度扣减在「使用统计」中按请求展示。

流式响应

请求中设置 "stream": true,按 SSE 事件读取:

事件含义
message_start消息开始
content_block_start内容块开始
content_block_delta内容增量,文本增量的类型为 text_delta
message_stop消息结束
error流中的错误信息

相关入口

本页目录