# AI token counter

> Count tokens and estimate the API cost of a prompt for GPT, Claude, and Gemini models.

Free LLM token counter and API cost calculator. Paste text to count tokens with OpenAI's tokenizers and estimate input and output cost across GPT, Claude, Gemini, and other models.

- Page: https://benchline.fabwaseem.com/t/ai-token-counter
- Runs: in the browser. Input stays on the device.
- Price: free, no account
- Input: Prompt text or a text file, selected models, expected output tokens, requests per day, and a cached-input share.
- Output: Token, character, and word counts, a token boundary preview, and a cost table per model.
- Keywords: token counter, LLM token counter, OpenAI token counter, tiktoken, AI cost calculator
- Updated: 2026-10-16
- Built by: Waseem Anjum (https://fabwaseem.com)

## How to use it

1. **Paste your prompt or file.** Drop a .txt, .md, or .json file, or paste the prompt. The count updates in the browser.
2. **Pick models and expected output.** Choose the models to compare, set the output tokens you expect back, and the cached-input share.
3. **Compare cost per request and per month.** The table prices input and output separately. Copy it as markdown when you want to keep the estimate.

## Use it from an AI agent

MCP tool name: `count_tokens`
MCP endpoint: https://benchline.fabwaseem.com/mcp (Streamable HTTP, no key)
HTTP: POST https://benchline.fabwaseem.com/api/v1/tools/ai-token-counter with the input as the JSON body
This call does not fetch anything. It runs on the arguments you send.

Count tokens with the o200k or cl100k encoder and price the count against the published model table. Claude and Gemini rows are estimates, not those vendors' tokenizers.

### Input schema

```json
{
  "type": "object",
  "properties": {
    "text": {
      "type": "string",
      "description": "The prompt or document to count."
    },
    "encoding": {
      "default": "o200k",
      "type": "string",
      "enum": [
        "o200k",
        "cl100k"
      ]
    },
    "modelIds": {
      "default": [
        "gpt-6.1-sol",
        "claude-sonnet-5-5",
        "gemini-4-argon"
      ],
      "description": "Price rows to return. Unknown ids are rejected.",
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "outputTokens": {
      "default": 0,
      "type": "integer",
      "minimum": 0,
      "maximum": 9007199254740991
    },
    "cachedRatio": {
      "default": 0,
      "type": "number",
      "minimum": 0,
      "maximum": 1
    },
    "requestsPerDay": {
      "default": 0,
      "type": "number",
      "minimum": 0
    }
  },
  "required": [
    "text",
    "encoding",
    "modelIds",
    "outputTokens",
    "cachedRatio",
    "requestsPerDay"
  ],
  "additionalProperties": false
}
```

### Example tools/call

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "count_tokens",
    "arguments": {
      "text": "example",
      "encoding": "o200k",
      "modelIds": [
        "gpt-6.1-sol",
        "claude-sonnet-5-5",
        "gemini-4-argon"
      ],
      "outputTokens": 0,
      "cachedRatio": 0,
      "requestsPerDay": 0
    }
  }
}
```

Setup for Claude, Cursor, and VS Code: https://benchline.fabwaseem.com/mcp/guide

## Questions

### What is a token?

A token is the unit an LLM bills and reads. In English, one token is about 4 characters or about three quarters of a word. Other languages and code often use more tokens for the same text.

### Why do counts differ between models?

Each family has its own encoding. This tool counts OpenAI text with o200k_base and can show cl100k_base. Other providers are not the same encoding.

### Are Claude and Gemini counts exact?

No. Claude and Gemini do not publish a browser tokenizer. Their counts are an estimate equal to the o200k_base count. Use the provider's count-tokens API when you need an exact number.

### How is cost calculated?

Input and output are priced separately, per million tokens. Cached input uses the cache-read rate when the model has one. A request over a model's long-context threshold uses that model's higher rate for the whole request. Monthly cost is the request cost times requests per day times 30.

### Is my text uploaded?

No. Counting and the cost table run locally in your browser. The tokenizer loads as a cacheable worker. The text is not sent to this site.

### When were prices updated?

The date under the cost table is 2026-10-16, when these rates were copied from the providers' pricing pages. Open the cited links to confirm the current rate before you budget a large workload.

## Related tools

- [JSON-LD schema generator](https://benchline.fabwaseem.com/t/schema-generator): Fill a form, get valid schema.org JSON-LD for Article, FAQ, Product, Organization, and more.
- [llms.txt generator](https://benchline.fabwaseem.com/t/llms-txt-generator): Read a public sitemap and write an llms.txt index, plus an optional llms-full.txt.
- [JWT decoder](https://benchline.fabwaseem.com/t/jwt-decoder): Paste a JSON Web Token, read the claims, and verify the signature in the browser.
- [Cron expression builder](https://benchline.fabwaseem.com/t/cron-expression-builder): Build or paste a cron schedule, read it in plain English, and see the next run times.
