POST /v1/messages/count_tokens counts full Claude input with and without a server prompt. When a prompt is applied, its tokens are already part of the returned input_tokens; the prompt text is not exposed.
curl https://api.guardrelay.ai/v1/messages/count_tokens \
-H "x-api-key: $GUARD_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-sonnet-5-5",
"messages": [{"role": "user", "content": "How many tokens is this?"}]
}'{ "input_tokens": 56 }POST /v1/messages/count_tokens works for Claude, Kimi, and GLM, and also for Gemini and Muse (for them it is a free approximate estimate). GLM also supports /glm/v1/messages/count_tokens; internal count-only fallback 5.2 is not a public model. Composer and Grok receive 404.
- Kimi. Free counting is available at
/v1/messages/count_tokensfor all four IDs. It does not replace the generation reserve: set an explicitmax_tokens, or the output reserve is computed at Kimi's default: 131,072 tokens fork3andk3-256k, 32,768 forkimi-for-coding-highspeed, 32,000 forkimi-for-coding; if the balance cannot cover that reserve with room for 8 more regular requests, 32,000. - Composer and Grok. No pre-count. Actual consumption arrives in the response
usage; the context window is 200K for Composer, 256K in Guard for Grok 4.7, and 500K for Grok 4.6.
All four Kimi IDs support free POST /v1/messages/count_tokens. Send the model and messages; the response contains input_tokens. Generation usage is reported separately in the billed response.
curl -s -X POST https://api.guardrelay.ai/v1/messages/count_tokens \
-H "Authorization: Bearer $GUARD_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "k3",
"messages": [{"role": "user", "content": "How many tokens is this?"}]
}'{ "input_tokens": 14 }POST /v1/messages/count_tokens and /glm/v1/messages/count_tokens accept a Messages body and do not debit the balance.
curl https://api.guardrelay.ai/glm/v1/messages/count_tokens \
-H "Authorization: Bearer $GUARD_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{"model":"glm-5.3","messages":[{"role":"user","content":"Count this input"}]}'{"input_tokens": 14, "model": "glm-5.3"}Flash uses its native tokenizer. The messages content is checked against the same media matrix as generation.
POST /v1/messages/count_tokens works for Gemini free of charge. The count before an answer returns an approximate estimate of the whole input (system instructions, tools, and the server prompt when it applies), not an exact Google count. It is a reference number: the charge follows the actual usage, not the estimate.
POST /v1/messages/count_tokens works for Muse as well. The free count before an answer returns an approximate estimate, not an exact Meta count. It is a reference number: the charge follows the actual usage, not the estimate.