API Hop

Guides

Token Cost Calculator: Text, Code & Image Math

Use this token cost calculator guide to convert English, CJK, JSON, code & images into tokens, apply 95% cache discounts & estimate USD bills in Python.

Reviewed:

A token cost calculator is only as accurate as its tokenization assumptions: while English prose averages ~4 characters per token, minified JSON, source code, and CJK/Indic scripts burn 1.5x to 3x more tokens for the exact same character count—and hidden reasoning tokens bill at full output rates ($5.00–$20.00/1M). In multi-turn workflows, applying 95%-off prompt caching ($0.05–$0.11/1M on API Hop) slashes repeated-context costs by over 80%. Below are the exact modality conversion rules, a worked multi-turn formula across GPT-6.2 Sol, Gemini 4 Argon, and Claude Opus 5.5, and a runnable Python calculator you can drop straight into your codebase.

Key Takeaways

  • Characters do not map 1:1 to tokens across languages: English prose averages ~4 chars/token (~0.75 words/token), source code and JSON average ~2.5–3.2 chars/token due to punctuation/indentation, and Chinese/Japanese/Korean (CJK) text averages ~1.5–2.0 chars/token—meaning a 10,000-character Chinese document costs roughly 2x–2.5x as many input tokens as a 10,000-character English document.
  • Four distinct billing buckets govern modern LLM invoices: Every call splits into uncached input, cached input reads (typically 95% off), visible output, and hidden reasoning/thinking tokens (billed at the full output rate, often 5x the input price).
  • Images convert into fixed tile tokens: A standard 1024×1024 image typically consumes ~765 to 1,600 input tokens depending on vision encoder tiling (low vs. high detail), turning batch screenshot agents into heavy input-token consumers.
  • Worked multi-turn math shows caching dominates model choice: On a 12-turn, 100K-token support/coding session with 10K output tokens, Gemini 4 Argon on API Hop ($1.00 in / $0.05 cache / $5.00 out) drops from $1.25 uncached to $0.21 with 90% cache hits—an 83% reduction from one configuration fix.
  • Verify real token counts before scaling: Local tiktoken or heuristic estimators are fast for budgeting, but always reconcile against the exact usage.prompt_tokens, prompt_tokens_details.cached_tokens, and completion_tokens_details.reasoning_tokens fields returned by the API.
  • Test token economics with zero monthly fee: Fund a small pay-as-you-go balance on the API Hop Pricing Page using USDT/USDC crypto, Brazil PIX, or Indonesian QRIS/GoPay/DANA to benchmark real token burn across live frontier models.

Tokenization Conversion Rules at a Glance

Verified 2026-11-23 across modern BPE tokenizers (OpenAI o200k, Anthropic, and Gemini SentencePiece tokenizers) and live API Hop Model Catalog rates:

Content Type / ModalityTypical Conversion RatioExample PayloadEst. Token CountBilling Pitfall to Watch
English Prose~4 chars/token (~1.33 tok/word)1,000 English words (~5,500 chars)~1,330–1,400 tokensBaseline assumption; underestimates every other type
Source Code (Python/TS)~2.8–3.3 chars/token500 lines (~18,000 chars)~5,500–6,400 tokensIndentation, brackets & short variable names split often
JSON / Tool Schemas~2.5–3.0 chars/token20 tool definitions (~12,000 chars)~4,000–4,800 tokensRe-sent on every turn unless prefix-cached
CJK Text (Chinese/JP/KR)~1.5–2.0 chars/token3,000 Chinese characters~1,500–2,000 tokens2x–2.5x denser token burn per character vs. English
Indic / Arabic / Cyrillic~1.5–2.5 chars/token3,000 Hindi or Arabic chars~1,200–2,000 tokensMulti-byte UTF-8 splits inflate prompt bills
Vision Image (1024×1024)Tile-based (512px or 768px tiles)1 high-detail UI screenshot~765–1,600 tokens20 browser screenshots = ~15K–32K input tokens
Reasoning / Thinking Output2x–6x visible answer length1,000 visible + 4,000 thinking5,000 output tokensBilled at full output rate (5x input price)

The Exact Token-to-USD Formula

To calculate real per-request or per-session API cost without surprises, separate all four token buckets:

$$\text{Total Cost ($)} = \frac{T_{\text{in,uncached}}}{10^6} \cdot P_{\text{in}} + \frac{T_{\text{in,cached}}}{10^6} \cdot P_{\text{cache}} + \frac{T_{\text{out,visible}} + T_{\text{out,reasoning}}}{10^6} \cdot P_{\text{out}}$$

Where:

  • $T_{\text{in,uncached}}$ = fresh prompt tokens (first turn + newly appended user messages or tool outputs)
  • $T_{\text{in,cached}}$ = repeated prefix tokens hitting the provider’s KV cache (system prompt, docs, repo context)
  • $T_{\text{out,visible}} + T_{\text{out,reasoning}}$ = total billed completion tokens (both final text and hidden chain-of-thought)
  • $P_{\text{in}}, P_{\text{cache}}, P_{\text{out}}$ = per-million-token prices in USD

Live Model Rate Reference on API Hop (Verified 2026-11-23)

Model (Live on API Hop)Uncached Input ($/1M)Cached Read ($/1M)Output & Reasoning ($/1M)Output-to-Input Multiplier
Gemini 4 Argon (50% off official)$1.00$0.05$5.005.0x
GPT-6.2 Sol$2.00$0.10$10.005.0x
Claude Opus 5.5 (45% off official)$2.20$0.11$11.005.0x

Worked Workload Cost Calculation: 12-Turn Document & Code Session

Suppose your app runs a 12-turn session over a 100,000-token context (40K source code + 40K multilingual docs + 20K JSON tool schemas). Turn 1 sends 100K uncached input; turns 2–12 replay the 100K prefix (1,100,000 cached tokens at a 90% cache hit rate, plus 10K fresh turn inputs = 110K total uncached input + 1,090K cached reads) and generate 10,000 total output tokens (3K visible + 7K hidden reasoning):

  • Uncached baseline (0% cache hit): 1,200,000 uncached input + 10,000 output tokens
  • Warm-cache production (90% cache hit): 110,000 uncached input + 1,090,000 cached reads + 10,000 output tokens
Model (API Hop Rates)0% Cache Cost / Session90% Cache Cost / SessionSavings from CachingMonthly Bill (1,000 Sessions, Warm Cache)
Gemini 4 Argon ($1.00 / $0.05 / $5.00)$1.250$0.215 ($0.11 + $0.055 + $0.05)82.8%$215.00
GPT-6.2 Sol ($2.00 / $0.10 / $10.00)$2.500$0.429 ($0.22 + $0.109 + $0.10)82.8%$429.00
Claude Opus 5.5 ($2.20 / $0.11 / $11.00)$2.750$0.472 ($0.242 + $0.120 + $0.11)82.8%$472.00

Notice how a single broken cache prefix (such as injecting Current time: 14:23:05 at line 1 of your system prompt) multiplies your monthly bill by 5.8x—from $215 to $1,250 on Gemini 4 Argon.

Runnable Python: Lightweight Multi-Modality Token Cost Calculator

Use this zero-dependency Python script to estimate tokens across English, code/JSON, CJK text, and images, then price the session across live API Hop models:

import math
import re

MODELS = {
    "gemini-4-argon": {"in": 1.00, "cache": 0.05, "out": 5.00},
    "gpt-6.2-sol": {"in": 2.00, "cache": 0.10, "out": 10.00},
    "claude-opus-5.5": {"in": 2.20, "cache": 0.11, "out": 11.00},
}

def estimate_text_tokens(text: str, is_code_or_json: bool = False) -> int:
    """Heuristic token estimator separating CJK/multibyte chars from ASCII."""
    cjk_chars = len(re.findall(r"[\u4e00-\u9fff\u3040-\u30ff\uac00-\ud7af]", text))
    other_chars = len(text) - cjk_chars
    ascii_divisor = 2.8 if is_code_or_json else 4.0
    return math.ceil((cjk_chars / 1.6) + (other_chars / ascii_divisor))

def estimate_image_tokens(num_images: int, high_detail: bool = True) -> int:
    """Approximate vision token footprint per 1024x1024 image."""
    return num_images * (1105 if high_detail else 85)

def calculate_session_cost(
    model: str,
    uncached_input_tokens: int,
    cached_input_tokens: int,
    visible_output_tokens: int,
    reasoning_output_tokens: int = 0,
) -> float:
    rates = MODELS[model]
    total_out = visible_output_tokens + reasoning_output_tokens
    cost = (
        (uncached_input_tokens / 1_000_000) * rates["in"]
        + (cached_input_tokens / 1_000_000) * rates["cache"]
        + (total_out / 1_000_000) * rates["out"]
    )
    return round(cost, 4)

# Example: 20K chars of Python code + 4K Chinese chars + 2 screenshots, 10 cached replays
base_tokens = (
    estimate_text_tokens("x" * 20_000, is_code_or_json=True)
    + estimate_text_tokens("中" * 4_000)
    + estimate_image_tokens(2, high_detail=True)
)
print(f"Estimated base prompt tokens: {base_tokens:,}")

for m in MODELS:
    usd = calculate_session_cost(
        model=m,
        uncached_input_tokens=base_tokens + 2_000,
        cached_input_tokens=base_tokens * 10,
        visible_output_tokens=2_500,
        reasoning_output_tokens=5_500,
    )
    print(f"{m:16s} -> ${usd:.4f} per session")

Free Tier Reality, Minimum Deposit, and Regional Payments

Offline token calculators are always free to run, but validating real reasoning-token ratios and cache hit rates requires live API calls. Most flagship 2026 models (gpt-6.2-sol, claude-opus-5.5, gemini-4-argon) do not offer unlimited free production API tiers—and official vendor consoles often block local debit cards or enforce strict tier-1 rate limits until you prepay $50–$100+.

On the API Hop Pricing Page, you can run live token benchmarks against your exact production prompts without subscription overhead:

  • Low pay-as-you-go entry: Start with a small top-up and zero monthly seat fees; 1,000 test calls on Gemini 4 Argon with prompt caching often cost under $5 total.
  • Global & regional payment rails: No overseas USD credit card is required—API Hop supports USDT/USDC crypto, Brazil PIX, and Indonesian QRIS, GoPay, and DANA wallets.
  • Exact billing telemetry: Every OpenAI-compatible response returns usage.prompt_tokens, cached_tokens, and completion_tokens, letting you replace heuristic estimates with real dollar attribution across the entire API Hop Model Catalog.

What We Don’t Know Yet

  • Cross-vendor tokenizer convergence: Each model family still ships its own BPE/SentencePiece vocabulary, so a prompt that measures 10,000 tokens on OpenAI’s tokenizer can vary by ±8% to ±15% on Claude or Gemini—especially for non-Latin scripts and domain-specific code.
  • Dynamic reasoning-effort token caps: Reasoning models vary their internal thinking length based on prompt ambiguity; predicting exact reasoning_tokens before running a 20-sample calibration batch remains an empirical exercise rather than a closed-form formula.

What to Watch Next

  • Long-context tier cliffs: Watch whether providers keep flat pricing up to 1M tokens or reintroduce 2x pricing cliffs above 200K context—always verify threshold rules in your calculator config.
  • Multimodal audio & video token meters: As models unify text, image, audio, and video (like Seedance 2.5 billing per million video completion tokens), token calculators must expand beyond text characters to pixel-frame and audio-second formulas.

Frequently Asked Questions

How does API token pricing work for input, cached, and output tokens?

API providers price tokens per 1 million units across three tiers: standard uncached input (e.g., $1.00–$2.20/M on API Hop), cached input reads (typically 95% cheaper, $0.05–$0.11/M), and output tokens (typically 5x the input rate, $5.00–$11.00/M). Hidden reasoning tokens count as output tokens.

Is there a free token cost calculator or free API tier to test real token counts?

Yes for estimation, and no for unlimited production inference. You can run the Python token cost calculator in this guide (or tiktoken) completely free offline to estimate budgets. To measure real server-side cached_tokens and reasoning_tokens without a monthly subscription, top up a small pay-as-you-go balance on API Hop—a few dollars covers hundreds of real benchmark calls.

How many characters or words equal 1,000 tokens?

For English prose, 1,000 tokens equals roughly 750 words or 4,000 characters. For Python/JavaScript code or JSON, 1,000 tokens covers only 2,500–3,200 characters because symbols and whitespace split frequently. For Chinese, Japanese, or Korean, 1,000 tokens covers roughly 1,500–2,000 characters.

Do hidden reasoning or thinking tokens cost money?

Yes. On frontier reasoning models—including GPT-6.2 Sol, Claude Opus 5.5, and Gemini 4 Argon—internal thinking tokens are billed at the full output token rate, even when the raw chain-of-thought is hidden or summarized in the API response.

How many tokens does an image use in a vision API call?

Most modern vision encoders divide images into fixed tiles (such as 512×512 or 768×768 patches). A low-detail thumbnail uses roughly 85–250 tokens, whereas a high-detail 1024×1024 screenshot or document page consumes ~765 to 1,600 input tokens.

Why did my actual API bill differ from my token calculator estimate?

Four causes explain 95% of billing variance: (1) forgetting that multi-turn chat replays the full conversation history on every turn; (2) accidentally busting the prompt cache with a dynamic timestamp at the top of the system prompt; (3) ignoring hidden reasoning tokens billed at 5x input rates; and (4) using English character ratios on CJK text or dense JSON payloads.