Skip to content

Token Counter

v1.0.0

Estimate token counts and dollar cost for any text across Claude, GPT, Gemini, Llama and Mistral — before you make the call.

2 endpoints
Price per call
$0.0002
Free each month
5K calls
Rate limit
300/min
MCP server
Included

Overview

Token Counter estimates how many tokens a piece of text will consume and what it will cost, for the models people actually budget against.

Two questions it answers before you spend anything: will this fit in the model's context window, and what will it cost at that model's rate. Both are far cheaper to answer in advance than to discover from a truncation error or an invoice.

The estimate is an approximation and every response says so with approximate: true. An exact count would require each provider's own tokeniser vocabulary, which is correct for one model and wrong for every other. On ordinary prose this lands within a few percent of real counts — the accuracy a budgeting decision actually needs, without the weight.

Prices are maintained by us rather than scraped live, so a vendor changing their pricing page cannot break your cost dashboard. Every response includes pricesUpdated so you can see how fresh the figures are.

Make your first call

Every request goes through the Twotic gateway, which authenticates your key, applies the rate limit, meters the call and forwards it. The exact amount charged comes back on the X-Twotic-Cost header.

curl -X POST "https://www.twotic.dev/v1/token-counter/count" \
  -H "Authorization: Bearer $TWOTIC_KEY"

Endpoints

What you can build

Guard a context window before you call

Estimate first and branch: if the prompt would not fit, chunk or summarise instead of sending it and handling a truncation error afterwards.

Show users what a request will cost

In any product that exposes model usage, an up-front cost estimate turns an opaque bill into an informed decision — and reduces the support load that opacity generates.

Compare models on the same workload

Run the same text against several model ids and compare the totals. The cost difference across models for identical output is frequently an order of magnitude.

Use Token Counter from an AI agent

Every endpoint above is also an MCP tool. Pick your client and the steps below fill in with this API’s real server URL, so there is nothing to substitute.

In claude.ai and the Claude desktop app

  1. 1Open Settings, then Connectors.
  2. 2Choose Add custom connector.
  3. 3Paste the server URL below and confirm.
  4. 4A Twotic sign-in page opens. Approve the connection.
  5. 5Start a new conversation. The tools are available there.

Server URL

https://www.twotic.dev/api/mcp/token-counter

Signs you in through Twotic. Access expires hourly and renews itself, and you can revoke this one app without touching your API keys.

Once connected, the tools are named token-counter_<endpoint>. Every Token Counter endpoint becomes one. Calls are metered exactly like an HTTP request, against the same allowance and balance.

Frequently asked

How accurate is the estimate?+

Within a few percent on ordinary English prose. It is less accurate on dense code, long base64 strings and heavily mixed scripts. Every response is marked approximate: true — use it for budgeting and context-fit checks, not for reconciling an invoice to the token.

Why not use the real tokeniser?+

A count from one provider's tokeniser is simply wrong for another's, and carrying all of them would make this slower and more expensive than the model call it exists to protect you from.

How current are the prices?+

Every response includes a pricesUpdated date. The table tracks published list prices for the models developers most commonly budget against, and is updated as vendors change them.

Can I check whether my prompt fits the context window?+

Yes — that is what fitsInContext and contextUsedPercent are for. Checking before you send turns a failed call into a branch in your own code.