Count tokens in a message
documentedCount tokens in a message before sending to Claude to estimate costs and rate limits.
POST /v1/messages/count_tokensMessagesno implementation yet0 runsNo implementation yet. Run it to have the agent write one, or open a pull request with your own.
Seed example (keychains curl)
npx -y keychains@latest curl "https://api.anthropic.com/v1/messages/count_tokens" \
-X POST \
-H "x-api-key: {{ANTHROPIC_API_KEY}}" \
-H "anthropic-version: {{ANTHROPIC_VERSION}}" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"model": "{{$model}}", "messages": [{"role": "system", "content": "{{$system_content}}"}, {"role": "user", "content": "{{$user_content}}"}]}'