Token Count

Estimate text token counts and costs for supported AI models using character-based rules, without calling a model.

Pay by wallet (x402) token-count

Example

Example answer
{
  "model": "gpt-4o",
  "text_length": 54,
  "token_count": 14,
  "model_recognized": true,
  "cost_per_1k_tokens": 0.0025,
  "estimated_cost_usd": 0.000035,
  "fits_context_window": true,
  "chars_per_token_used": 4,
  "max_context_for_model": 128000
}

Inputs

FieldTypeRequiredWhat it is
textstringYes—
modelstringNogpt-4o, claude-3-haiku, etc.

Output fields

How reliably each field appears in a successful answer.

FieldTypeAppears
token_countintegerAlways (present in every successful answer)
estimated_cost_usdnumberAlways (present in every successful answer)
fits_context_windowbooleanAlways (present in every successful answer)
max_context_for_modelintegerAlways (present in every successful answer)

How to call it

The same tool through each route. MCP clients reach it through Strale’s server at https://api.strale.io/mcp; the call below is what the agent sends.

# Needs an API key. max_price_cents caps what this call may cost.
curl -X POST https://api.strale.io/v1/do \
  -H "Authorization: Bearer $STRALE_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "capability_slug": "token-count",
    "inputs": {
      "text": "This is a test input for automated capability testing."
    },
    "max_price_cents": 2
  }'

Limitations

  • Estimated token counts can differ by 5–15%

    Token counts are estimated using character-based heuristics — actual counts vary by 5-15% depending on the tokenizer

    What to do instead: Use the target model provider’s official tokenizer for exact counts.