协议端点

三套原生入口,互相平级。入口路径即协议,我们不做请求体嗅探。

端点

入口协议标识base_url说明
POST /v1/messagesanthropichttps://api.akrouter.com原生 Messages API。thinking block、cache_control 断点、tool_use id 全部原样透传
POST /v1/responsesopenai_responseshttps://api.akrouter.com/v1原生 Responses API。reasoning item 原样保留
POST /v1/chat/completionsopenai_chathttps://api.akrouter.com/v1最广泛兼容的入口
POST /v1/messages/count_tokensanthropichttps://api.akrouter.comClaude Code 用它估算上下文占用,以决定何时压缩历史

流式与非流式都支持,由请求体里的 stream 决定,与我们无关 —— 我们只是把它转发出去。

原样转发是默认,翻译是降级

调度顺序固定为:

  • 优先protocols 包含你的客户端协议的渠道 —— 请求体字节级透传,零翻译
  • 无同协议渠道可用时才降级到翻译路径
  • 走了翻译的请求会在日志上标记 translated = true,你能在使用日志里看到
跨协议翻译是有损的
损失点恰好都在编码 Agent 最依赖的功能上。这类故障的共同特征是「能用,但行为不对」—— 不报错、难复现。
翻译时丢失的东西后果
Anthropic thinking block扩展思考内容丢失或格式错乱
cache_control 断点prompt cache 全部不命中,成本涨数倍、TTFT 变差
tool_use / tool_result 的 id 对齐多轮工具调用直接崩
Responses API 的 reasoning itemCodex 的推理链断裂
anthropic-beta / openai-beta 头特性开关静默失效

因此如果你在意这些能力,建议在 路由偏好 里打开「只用原生协议渠道」硬约束:满足不了就报错,而不是悄悄翻译。

请求头处理

原则是默认放行,只剥必须剥的。

处理
剥离hop-by-hop 头、hostcontent-lengthcf-*x-forwarded-*,以及你的下游凭据(Authorization / x-api-key
透传其余全部,尤其 anthropic-betaopenai-betaanthropic-version

路由元数据

我们会回传这次请求实际走了哪条渠道、尝试过哪些、哪些约束生效了。 没有它,「为什么这次慢」只能靠猜。

json
{
  "akrouter": {
    "requested": "claude-sonnet-5",
    "selected": { "merchant": "acme-01", "channelId": "...", "translated": false },
    "attempts": [ { "channel": "...", "status": 429, "errorClass": "rate_limited" } ],
    "constraints": { "priceCap": "applied", "preferLatency": "soft, 2 channels downweighted" }
  }
}

同样的信息在 使用日志 的请求详情里有完整的 attempts 时间线。

错误响应形状

错误一律按你的客户端协议的形状返回,不做统一格式。

json
// anthropic
{ "type": "error", "error": { "type": "...", "message": "..." } }

// openai_chat / openai_responses
{ "error": { "message": "...", "type": "...", "code": "..." } }