Skip to Content
aicentos
API 接口聊天接口

原生 Claude 格式

Claude 原生格式的消息接口:端点、鉴权与请求示例

最后更新于:

Anthropic Messages 格式的对话接口。

POST /v1/messages

鉴权

Bearer Token:API Key 在控制台「令牌管理」获取,放在请求头 Authorization。

请求

Content-Type: application/json

export AICENTOS_API_KEY="sk-your-aicentos-api-key"

curl -X POST "https://aicentos.com/v1/messages" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $AICENTOS_API_KEY" \
  -d '{
    "model": "claude-sonnet-4-6",
    "max_tokens": 256,
    "messages": [
      { "role": "user", "content": "用一句话介绍你自己" }
    ]
  }'

参数与 Anthropic 官方一致,max_tokens 必填。

响应

回复内容取 content[0].text,用量在 usage(input_tokens / output_tokens):

{
  "id": "string",
  "type": "message",
  "role": "assistant",
  "content": [
    { "type": "text", "text": "string" }
  ],
  "model": "string",
  "stop_reason": "end_turn",
  "usage": { "input_tokens": 0, "output_tokens": 0 }
}

鉴权失败时返回 invalid_api_key 错误,排查方法见错误处理:

{
  "error": {
    "message": "Incorrect API key provided",
    "type": "authentication_error",
    "code": "invalid_api_key"
  }
}

本页内容