AIGoCode Docs

Anthropic Compatible

使用 Messages 接口调用 Claude 模型

使用支持第三方调用的 Claude 分组 API Key,通过 Anthropic SDK 或 HTTP 请求调用 Claude 模型。

请求地址与认证

用途地址
Anthropic 官方 SDK 的 base_url / baseURLhttps://api.aigocode.app
HTTP 完整请求地址POST https://api.aigocode.app/v1/messages

官方 SDK 会拼接 /v1/messages。其他客户端按其要求填写地址,避免重复拼接路径。

请求头包含 x-api-key: YOUR_API_KEYanthropic-version: 2023-06-01Content-Type: application/json

先按 认证方式 设置环境变量 AIGOCODE_API_KEY。下方 curl 命令适用于 macOS / Linux;Windows Cmd、PowerShell 和 Python 示例见 第一次请求

最小请求

macOS / Linux
curl "https://api.aigocode.app/v1/messages" \
  -H "x-api-key: $AIGOCODE_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "claude-sonnet-5",
  "max_tokens": 512,
  "messages": [
    {
      "role": "user",
      "content": "请只回复:Hello from AIGoCode!"
    }
  ]
}'

成功响应

以下为上述请求的实际返回,ID、时间和用量使用占位符。

response.json
{
  "id": "msg_xxx",
  "type": "message",
  "role": "assistant",
  "model": "claude-sonnet-5",
  "content": [
    {
      "type": "text",
      "text": "Hello from AIGoCode!",
      "citations": []
    }
  ],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "stop_details": null,
  "context_management": {
    "applied_edits": []
  },
  "usage": {
    "input_tokens": xx,
    "cache_creation_input_tokens": xx,
    "cache_read_input_tokens": xx,
    "cache_creation": {
      "ephemeral_5m_input_tokens": xx,
      "ephemeral_1h_input_tokens": xx
    },
    "output_tokens": xx,
    "output_tokens_details": {
      "thinking_tokens": xx
    },
    "service_tier": "standard",
    "inference_geo": "global"
  }
}

进阶用法

更多模型见 模型名称列表。请求失败时查看 错误码

On this page