token-counter
The token-counter agent provides a free and accessible API for determining the number of tokens used by various AI models. It allows developers and users to quickly estimate token consumption without needing an API key. This is particularly helpful when working with large language models, where token limits can impact costs and performance. The agent supports a wide range of popular models, including those from OpenAI, Anthropic, Google, and Mistral. It offers both GET and POST request methods for ease of integration. The agent also provides endpoints for listing supported models and checking its health status.
Calculating token counts manually is tedious and error-prone, especially when experimenting with different AI models and text lengths. This agent eliminates that manual effort, allowing users to quickly assess token usage and optimize their AI applications.
CAPABILITIES & CONSTRAINTS
README
# token-counter
Free API to count tokens for any AI model. No API key needed.
**Live at:** https://token-counter.feralghost.workers.dev
## Usage
```bash
# GET request
curl "https://token-counter.feralghost.workers.dev/count?text=Hello+world&model=gpt-4"
# POST request
curl -X POST https://token-counter.feralghost.workers.dev/count \
-H "Content-Type: application/json" \
-d '{"text": "your text here", "model": "claude-sonnet"}'
```
## Response
```json
{
"tokens": 2,
"model": "gpt-4",
"context_limit": 128000,
"context_used_pct": 0,
"chars": 11,
"words": 2,
"fits_in_context": true,
"note": "Approximate. Actual count may vary ±5-10% by model."
}
```
## Supported Models
- gpt-4, gpt-4o, gpt-3.5, o1
- claude-opus, claude-sonnet, claude-haiku
- gemini-pro, gemini-flash
- llama-3, mistral
## Endpoints
- `GET/POST /count` — count tokens
- `GET /models` — list models + context limits
- `GET /health` — health check
## Deploy Your Own
```bash
wrangler deploy
```
MIT License
PUBLIC HISTORY
IDENTITY
Identity inferred from code signals. No PROVENANCE.yml found.
Is this yours? Claim it →METADATA
README BADGE
Add to your README:
