跳转到内容

Token 计数

POST /v1/messages/count_tokens  compatible  语义操作 generate  契约修订 1

状态语义:stateless; served natively against one direct Anthropic connection

逐条来自契约,不是补充说明:

  • only the direct Anthropic Messages provider profile serves this endpoint; Bedrock Mantle shares the Messages wire format but its count_tokens surface is not established
  • the request body reaches the provider verbatim with only the upstream model identifier substituted, so there is no portable execution mode to select
  • Anthropic does not bill count_tokens, and Halro settles it at zero cost — but it is a real provider call on the operator’s credential, so it takes a ledger attempt and appears in the audit trail like any other
  • the reported count is Anthropic’s, for the upstream model behind the alias; it is not re-derived by Halro

在真正发出请求之前估算 token 数。这个端点不支持流式stream 会被拒), 也不接受 Halro-Route-Mode: portable

Terminal window
curl https://halro.example.com/v1/messages/count_tokens \
-H "x-api-key: $HALRO_GATEWAY_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{ "model": "claude",
"messages": [{"role": "user", "content": "你好"}] }'
  • x-api-key or Authorization
  • anthropic-version
  • anthropic-beta
  • Content-Type
字段不支持该字段的 Provider Profile组合级限制
model
messages
messages[].role
messages[].content
system
tools
tool_choice
thinking
output_config

这些字段在到达任何 Provider 之前就会被拒。照搬 OpenAI 文档最容易撞上的就是它们:

  • stream
  • Halro-Route-Mode: portable
  • unknown top-level fields

input_tokens

可路由的 Provider Profile 及各自成熟度

Section titled “可路由的 Provider Profile 及各自成熟度”
Provider Profile成熟度不支持的请求字段
anthropic.messages.2023-06-01compatible未声明
anthropic.messages.2023-06-01
  • only the model identifier is substituted; every other member is forwarded unchanged

已验证的证据:gateway_contractprovider_transport_fixturesdk_blackbox

anthropic-goanthropic-typescriptanthropic-python


本页的字段表、覆盖矩阵与偏差列表由 Halro 7117fdc38491 的兼容性契约生成 (scripts/generate-api-pages.mjs,契约摘要 9f8a5c57f76ae870…)。 字段的类型、是否必填与语义说明尚未进入契约,因此本页只列字段名。