โ† Home ยท Blog

Understanding LLM Tokens and API Pricing

Published: October 7, 2026 ยท 8 min read ยท By JSON Suite Team

If you're using AI APIs like OpenAI's GPT-4, Anthropic's Claude, or Google's Gemini, you've seen pricing in "tokens." But what exactly is a token, and how do you estimate costs? This guide explains everything you need to know.

What is a Token?

A token is the basic unit that language models process. It's not a word, character, or sentence โ€” it's something in between. Tokens are pieces of text that the model's tokenizer splits input into.

Roughly speaking:

  • 1 token โ‰ˆ 4 characters (in English)
  • 1 token โ‰ˆ 0.75 words (common estimate)
  • 100 tokens โ‰ˆ 75 words

How Tokenization Works

Most modern LLMs use subword tokenization (like BPE โ€” Byte Pair Encoding). Common words become single tokens, while rare words are split into pieces:

// Common words = 1 token each "the", "and", "is", "hello", "world" // Less common = split into multiple tokens "tokenization" โ†’ ["token", "ization"] // 2 tokens "JSON" โ†’ ["JS", "ON"] // 2 tokens "antidisestablishmentarianism" โ†’ 6+ tokens // Numbers vary "2024" โ†’ 1 token "3.14159" โ†’ 3 tokens (often split at decimals) // Non-English uses more tokens "ใ“ใ‚“ใซใกใฏ" (Japanese "hello") โ†’ 3-5 tokens "ไฝ ๅฅฝ" (Chinese "hello") โ†’ 2-3 tokens

Why Tokens Matter

Tokens affect two things:

  1. Cost โ€” APIs charge per token (usually per 1,000 tokens)
  2. Context limits โ€” Models have maximum token limits (context window)

Input vs Output Tokens

Most APIs charge differently for:

  • Input tokens โ€” Your prompt, system message, and any context you send
  • Output tokens โ€” The model's generated response

Output tokens are typically 2-4x more expensive than input tokens because generation is more compute-intensive.

Model Pricing Comparison (2026)

ModelInput (per 1M tokens)Output (per 1M tokens)Context Window
GPT-4 Turbo$10$30128K
GPT-4o$2.50$10128K
GPT-3.5 Turbo$0.50$1.5016K
Claude 3 Opus$15$75200K
Claude 3 Sonnet$3$15200K
Claude 3 Haiku$0.25$1.25200K
Gemini 1.5 Pro$3.50$10.501M
Gemini 1.5 Flash$0.075$0.301M

Note: Prices change frequently. Always check official pricing pages.

Calculating Costs

Here's how to estimate API costs:

// Example: GPT-4o // Input: 2000 tokens, Output: 500 tokens Input cost: 2000 รท 1,000,000 ร— $2.50 = $0.005 Output cost: 500 รท 1,000,000 ร— $10 = $0.005 Total: $0.01 per request // 10,000 similar requests = $100

Context Window Explained

The context window is the total tokens the model can handle in one request (input + output combined). This affects what you can do:

  • 4K tokens โ€” Short conversations, simple tasks
  • 16K-32K tokens โ€” Document summarization, code review
  • 128K tokens โ€” Analyze entire codebases, long documents
  • 1M+ tokens โ€” Process books, massive datasets (Gemini 1.5)

Tips to Reduce Token Usage

1. Be Concise in Prompts

// Verbose (50+ tokens): "I would like you to please help me by summarizing the following text that I have provided below in a way that captures the main points and key ideas." // Concise (10 tokens): "Summarize this text in 3 bullet points:"

2. Limit Output Length

// Use max_tokens parameter { "model": "gpt-4", "max_tokens": 150, // Cap response length "messages": [...] } // Or instruct in prompt "Answer in 2-3 sentences maximum."

3. Use Cheaper Models for Simple Tasks

Not every task needs GPT-4. Use GPT-3.5 or Claude Haiku for:

  • Simple classification
  • Text extraction
  • Basic formatting
  • Translations

4. Compress Context

// Instead of full conversation history: [30 previous messages = 5000 tokens] // Summarize periodically: "Previous context: User asked about Python, we discussed lists and dictionaries. Now continuing..." [500 tokens saved!]

5. Remove Unnecessary Data

// Don't send full JSON if you only need some fields // Before (200 tokens): { "user": { "id": 1, "name": "John", "email": "...", "address": {...}, "preferences": {...}, ... } } // After (20 tokens): { "name": "John", "email": "john@example.com" }

JSON and Tokens

JSON is commonly used in LLM APIs for structured input/output. However, JSON uses more tokens than plain text:

// JSON format (more tokens due to punctuation): {"name": "John", "age": 30, "city": "NYC"} // ~15 tokens // Plain text alternative: "name=John, age=30, city=NYC" // ~10 tokens // But JSON is worth it for: - Structured extraction - Function calling - Consistent parsing

Different Tokenizers

Each model family uses different tokenizers, so the same text produces different token counts:

TextGPT-4 (cl100k)ClaudeGemini
"Hello, world!"4 tokens4 tokens3 tokens
"JSON formatting"3 tokens3 tokens2 tokens
1000-word essay~1200 tokens~1100 tokens~1000 tokens

This is why counting tokens accurately requires using the right tokenizer for your model.

Batch Processing for Savings

Some providers offer batch/async APIs at lower costs:

  • OpenAI Batch API โ€” 50% discount, 24-hour processing
  • Anthropic Batches โ€” Similar discounts for async workloads

Great for non-urgent tasks like content generation, data processing, or analysis.

Count Your Tokens

Before sending expensive API calls, count your tokens! Use our free LLM Token Counter to:

  • Count tokens for GPT-4, Claude, Gemini, and more
  • Calculate estimated API costs
  • Optimize prompts before sending
  • Stay within context limits

It's especially useful when working with JSON APIs where structured data can quickly add up.

Related Tools

Optimize your AI workflows:

More Articles

What is JSON โ€” A Complete Guide

JSON API Best Practices

What is JWT โ€” Token Authentication

Understanding Base64 Encoding