Skip to content
POST/count

Estimate tokens and cost for a piece of text

Estimates the input token count for the supplied text and prices it against the chosen model.

Pass outputTokens to include the expected completion in the cost. The response reports context-window usage and whether the request would fit. Defaults to claude-sonnet-4 when no model is given.

$0.0002 per call300 req/minFree allowance applies

Request

curl -X POST "https://www.twotic.dev/v1/token-counter/count" \
  -H "Authorization: Bearer $TWOTIC_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "text": "Summarise the following support transcript…", "model": "claude-sonnet-4", "outputTokens": 500 }'

Request body

application/json · required

{
  "text": "Summarise the following support transcript…",
  "model": "claude-sonnet-4",
  "outputTokens": 500
}

Response

200The token estimate and cost breakdown.
{
  "cost": {
    "input": 0.003852,
    "total": 0.011352,
    "output": 0.0075,
    "currency": "USD"
  },
  "model": "claude-sonnet-4",
  "words": 812,
  "characters": 5136,
  "approximate": true,
  "inputTokens": 1284,
  "totalTokens": 1784,
  "outputTokens": 500,
  "contextWindow": 200000,
  "fitsInContext": true,
  "pricesUpdated": "2026-08-01",
  "contextUsedPercent": 0.89
}
400The text is missing or the model is unknown.
{
  "error": "unknown_model",
  "message": "Unknown model \"gpt-9\". Call GET /models for the supported list."
}

As an agent tool

Connect https://www.twotic.dev/api/mcp/token-counter and this endpoint is exposed as the tool token-counter_count.

Estimate the token count and dollar cost of a piece of text for a specific LLM, and check whether it fits that model's context window. Choose this before sending a large prompt, when deciding between models on price, or when showing a user what a request will cost. Send {"text": "...", "model": "...", "outputTokens": n}. Results are approximate and marked as such.