Token counting
POST /v1/messages/count_tokens
compatible
semantic operation generate
contract revision 1
State semantics: stateless; served natively against one direct Anthropic connection
Raw contract deviations
These statements are source-contract evidence. Use the examples, field table, and Profile coverage matrix for ordinary integration, and expand this list when investigating a compatibility boundary.
- 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
- count_tokens has no input/output token billing span, so Halro settles zero under ordinary per-token prices; a configured fixed per-request fee is still charged — 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
Count tokens before generation. This endpoint does not stream and rejects
Halro-Route-Mode: portable.
Request examples
Section titled “Request examples”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": "Hello"}] }'import osfrom anthropic import Anthropic
client = Anthropic(base_url="https://halro.example.com", api_key=os.environ["HALRO_GATEWAY_KEY"], timeout=60.0, max_retries=0)count = client.messages.count_tokens( model="claude", messages=[{"role": "user", "content": "Hello"}],)print(count.input_tokens)import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({ baseURL: "https://halro.example.com", apiKey: process.env.HALRO_GATEWAY_KEY, timeout: 60_000, maxRetries: 0,});const count = await client.messages.countTokens({ model: "claude", messages: [{ role: "user", content: "Hello" }],});console.log(count.input_tokens);Request headers
Section titled “Request headers”x-api-key or Authorizationanthropic-versionanthropic-betaContent-Type
Request fields
Section titled “Request fields”| Field | Provider Profiles that do not support it | Combination-level constraints |
|---|---|---|
model | — | — |
messages | — | — |
messages[].role | — | — |
messages[].content | — | — |
system | — | — |
tools | — | — |
tool_choice | — | — |
thinking | — | — |
output_config | — | — |
Fields rejected at the facade
Section titled “Fields rejected at the facade”Halro rejects these fields before any Provider I/O:
streamHalro-Route-Mode: portableunknown top-level fields
Response fields
Section titled “Response fields”input_tokens
Provider Profile contract coverage and current availability
Section titled “Provider Profile contract coverage and current availability”| Provider Profile | Maturity | Current build | Unsupported request fields |
|---|---|---|---|
anthropic.messages.2023-06-01 | compatible | creatable | undeclared |
Declared transformations
Section titled “Declared transformations”anthropic.messages.2023-06-01
- only the model identifier is substituted; every other member is forwarded unchanged
Evidence
Section titled “Evidence”Verified evidence: gateway_contract, provider_transport_fixture, sdk_blackbox
SDK black-box protocol-stub matrix
Section titled “SDK black-box protocol-stub matrix”anthropic-go, anthropic-typescript, anthropic-python
Best practices
Section titled “Best practices”See Anthropic native features and Token Count.
Fields, coverage, transformations, and deviations are generated from Halro 8f185de7674c
(scripts/generate-api-pages-en.mjs; synchronized manifest digest 8e5e7a0a794721aa…).
The synchronized copy contains 1 recorded accuracy correction(s); source manifest digest b321ee18ad2e38f3….
The contract currently carries field names, not complete types, required relationships, or value semantics.