lazymac2x avatar

Ai Token Counter

lazymac2x/ai-token-counter-api

Built as a Cloudflare Workers MCP server that counts tokens for AI model inputs. The implementation runs on Cloudflare's edge network and exposes both REST and MCP interfaces over JSON-RPC 2.0 via streamable HTTP transport. Reach for this when you need to estimate token usage before sending prompts to language models, especially if you're working with Claude or other token-limited APIs and want to avoid surprises on cost or context window limits. The remote endpoint is already live, so you can integrate it without deploying your own infrastructure. Useful for pre-flight checks in applications that construct dynamic prompts or need to stay within specific token budgets.

tools
4
transport
HTTP
last updated
May 16, 2026

Install

From registry metadata
$ npx add-mcp https://api.lazy-mac.com/ai-token-counter/mcp --name ai-token-counter

Run in your terminal. add-mcp asks which agents to add it to (Claude Code, Codex, Cursor and more). Add -g to install it for every project.

Review the command, arguments and environment values before installing. MCP servers run with your local permissions.

Other ways

Claude Code

$ claude mcp add --transport http ai-token-counter https://api.lazy-mac.com/ai-token-counter/mcp

Run in your terminal. Add --scope user to make it available in every project.

Tools

Verified live · 4 tools

Verified live against the running server on Nov 6, 2026.

count_tokensCount tokens for a text string or chat messages array for any supported AI model (GPT-4o, Claude, Gemini, Mistral, Llama).3 params

Count tokens for a text string or chat messages array for any supported AI model (GPT-4o, Claude, Gemini, Mistral, Llama).

Parameters* required
messagesarray
Chat messages array in OpenAI/Anthropic format.
modelstring
Model ID, e.g. gpt-4o, claude-sonnet-4. Defaults to gpt-4o.
textstring
Plain text to count tokens for.
estimate_costEstimate the cost of an AI API call given model and token counts or text. Returns input/output/total cost and optional monthly projection.5 params

Estimate the cost of an AI API call given model and token counts or text. Returns input/output/total cost and optional monthly projection.

Parameters* required
input_tokensinteger
Number of input tokens.
model*string
Model ID, e.g. gpt-4o, claude-opus-4, gemini-2.0-flash.
output_tokensinteger
Number of output tokens.
requests_per_daynumber
If given, adds daily/monthly/yearly cost projection.
textstring
Text to tokenize for input (if input_tokens not given).
get_model_pricingGet input/output pricing per 1M tokens for a specific AI model.1 params

Get input/output pricing per 1M tokens for a specific AI model.

Parameters* required
model*string
Model ID, e.g. gpt-4o, claude-haiku-3, llama-3-70b.
list_modelsList all supported AI models with their pricing and context windows.

List all supported AI models with their pricing and context windows.

No parameters. Call it with no arguments.

Sponsors

Readme

ai-token-counter-api

Cloudflare Workers MCP server: ai-token-counter. REST + MCP (JSON-RPC 2.0). Live: api.lazy-mac.com/ai-token-counter

Details

Repository
github.com/lazymac2x/ai-token-counter-api
Category
Cloud & Infrastructure
Transport
HTTP
Registry
MCP registry, active
Tools verified
Nov 6, 2026

More from lazymac2x

Related Cloud & Infrastructure MCP servers

View all
1lazymac2x avatarApi Mock Serverlazymac2x/api-mock-server-apiCloudflare Workers MCP server: api-mock-server0stars
2lazymac2x avatarApi Perf Analyzerlazymac2x/api-perf-analyzer-apiCloudflare Workers MCP server: api-perf-analyzer0stars
3lazymac2x avatarCron Collision Detectorlazymac2x/cron-collision-detector-apiCloudflare Workers MCP server: cron-collision-detector0stars
4lazymac2x avatarSmart Data Extractorlazymac2x/smart-data-extractor-workersmart-data-extractor MCP server on Cloudflare Workers · REST + MCP JSON-RPC · free tier0stars
5pipeworx-io avatarStudio Ghiblipipeworx-io/mcp-studio-ghibliStudio Ghibli MCP — fan API. Auth: none. Docs: https://ghibliapi.vercel.app0stars
6weiseer avatarstatus-aggregatorweiseer/status-aggregator-mcpCross-vendor SaaS status aggregator for AI agents (Anthropic/OpenAI/AWS/GH/Stripe/CF).0stars