// docs

Integration Docs

Buyers integrate against the router with one API key and one route alias. These examples show the buyer-facing request surface.

支持的模型

AINOGAP 目前支持 4 个 Claude 模型。所有请求均使用 Anthropic Messages API 格式。

Haiku 4.5
claude-haiku-4-5
Sonnet 4.6
claude-sonnet-4-6
Opus 4.6
claude-opus-4-6
Opus 4.7
claude-opus-4-7

请求示例

使用 Anthropic Messages API 格式。通过 URL 路径选择路由。

POST /<route-alias>/v1/messages
x-api-key: rk_xxx
anthropic-version: 2023-06-01
Content-Type: application/json

{
  "model": "claude-sonnet-4-6",
  "max_tokens": 1024,
  "messages": [
    { "role": "user", "content": "Hello" }
  ]
}
{
  "type": "message",
  "role": "assistant",
  "content": [
    { "type": "text", "text": "Hello! How can I help?" }
  ],
  "usage": {
    "input_tokens": 12,
    "output_tokens": 8,
    "cache_creation_input_tokens": 0,
    "cache_read_input_tokens": 0
  }
}

通过 URL 路径选择路由(如 /claude-fast/v1/messages)。买家账本计量 5 种 Token:未缓存输入、输出、缓存写入(5分钟)、缓存写入(1小时)、缓存读取。每种类型独立计费。费用从预充值 USDT 余额中实时扣除。

Token 计量明细

每个请求按 5 种 Token 分类计量。了解缓存 Token 有助于优化成本。

Token 分类:
• input      — 未缓存输入 Token(提示词)
• output     — 生成输出 Token
• cache_w5m  — 缓存写入 Token(5分钟 TTL)
• cache_w1h  — 缓存写入 Token(1小时 TTL)
• cache_read — 缓存读取 Token(缓存命中)

费用 = Σ(各分类 Token 数 × 对应单价)
缓存请求计量示例:
{
  "uncachedInputTokens": 50,
  "cacheWrite5mTokens": 200,
  "cacheWrite1hTokens": 0,
  "cacheReadTokens": 1500,
  "outputTokens": 120,
  "buyerChargeUsdMicros": 4200
}

缓存读取 Token 比输入 Token 便宜很多。对重复上下文使用提示词缓存可降低成本。缓存写入 Token 仅在缓存创建时收费一次。

Key 轮换

如果 Key 泄露,可从买家控制台或管理后台立即轮换。

POST /buyer/rotate-api-key
Authorization: Bearer <session_token>
{
  "item": {
    "buyerId": "buyer_abc",
    "routeApiKey": "rk_new_xxx"
  }
}

旧 Key 立即失效。请复制新 Key — 仅显示一次。浏览器会话将自动更新。