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
| Field | Type | Required | What it is |
|---|---|---|---|
text | string | Yes | — |
model | string | No | gpt-4o, claude-3-haiku, etc. |
Output fields
How reliably each field appears in a successful answer.
| Field | Type | Appears |
|---|---|---|
token_count | integer | Always (present in every successful answer) |
estimated_cost_usd | number | Always (present in every successful answer) |
fits_context_window | boolean | Always (present in every successful answer) |
max_context_for_model | integer | Always (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
}' {
"tool": "strale_execute",
"arguments": {
"slug": "token-count",
"inputs": {
"text": "This is a test input for automated capability testing."
},
"max_price_cents": 2
}
} import { Strale } from "straleio";
const strale = new Strale({ apiKey: process.env.STRALE_API_KEY! });
const result = await strale.do({
capability_slug: "token-count",
inputs: {
"text": "This is a test input for automated capability testing."
},
max_price_cents: 2,
}); import os
from straleio import Strale, DoRequest
strale = Strale(api_key=os.environ["STRALE_API_KEY"])
result = strale.do(DoRequest(
capability_slug="token-count",
inputs={
"text": "This is a test input for automated capability testing.",
},
max_price_cents=2,
)) # No account. The first request answers 402 with the price in USDC;
# an x402 client pays it from your wallet and repeats the request.
curl -i 'https://api.strale.io/x402/v2/token-count?text=This+is+a+test+input+for+automated+capability+testing.' 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.
Related tools
- Agent Trace Analysis €0.20
- API Docs Generator €0.20
- API Mock Responses €0.05
- Changelog Generator €0.03
- Code Converter €0.05
- Commit Message Generator €0.05