Per-call pricing · No setup

Token Counter API

Know exactly how many tokens your text uses before calling an LLM. Supports GPT-4o, Claude, Gemini, and more. One POST request. No library installs.

The problem it solves

openai.BadRequestError: This model's maximum context length is 128000 tokens.
However, your messages resulted in 134,521 tokens.

Context overflows kill agent runs at the worst moment. Counting tokens correctly means knowing when to summarize, chunk, or truncate — before the call fails.

How it works

Request

POST /api/tools/token-counter

{
  "text": "Analyze this document and
           extract key action items...",
  "model": "gpt-4o"
}

Response

{
  "tokens": 14,
  "model": "gpt-4o",
  "limit": 128000,
  "remaining": 127986,
  "percentUsed": 0.01
}

Common use cases

🤖

AI Agents

Check before every LLM call. Summarize or chunk context when approaching limits.

📄

Document Processing

Decide how to split large documents before sending them to the model.

💰

Cost Estimation

Estimate API costs before processing large batches of text.

TypeScript SDK

import { AgentToolbelt } from "agent-toolbelt";

const toolbelt = new AgentToolbelt({ apiKey: process.env.TOOLBELT_KEY });

async function prepareContext(history: Message[], doc: string) {
  const { percentUsed, remaining } = await toolbelt.tokenCounter({
    text: buildContext(history, doc),
    model: "gpt-4o",
  });

  if (percentUsed > 80) {
    return summarizeHistory(history, remaining);
  }

  return buildContext(history, doc);
}

Pricing

Fractions of a cent per call

Get API Key →

More tools

Part of Agent Toolbelt — 14 focused API tools for AI developers