跳转到内容
v0.9.1正式版

Token 计数

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

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

查看原始契约偏差(英文)

这些是源码契约中的逐条证据。日常接入先看本页示例、字段表和 Profile 覆盖矩阵;排查兼容性边界时 再展开核对原文。

  • 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 契约覆盖与本构建可用性
Provider Profile成熟度本构建不支持的请求字段
anthropic.messages.2023-06-01compatible可创建未声明
anthropic.messages.2023-06-01
  • 操作结论:原生模式只替换模型标识,其余字段原样转发;调用方必须确保正文完全符合所选 Provider 的原生协议。 原始契约:only the model identifier is substituted; every other member is forwarded unchanged

已验证的证据:gateway_contract、provider_transport_fixture、sdk_blackbox

anthropic-go、anthropic-typescript、anthropic-python

计数与实际治理准入的边界见案例十。


本页的字段表、覆盖矩阵与偏差列表由 Halro 08af8c8b0b10 的兼容性契约生成 (scripts/generate-api-pages.mjs,当前副本摘要 db249a88ce62e5b7…)。

字段的类型、是否必填与语义说明尚未进入契约,因此本页只列字段名。