Free Practical AI Tools & 50 Field Guide Books β€’ All 10 Free Tools β€’ 50 Books
Home β€Ί Free AI tools β€Ί AI Token Cost and Context Window Calculator

AI Token Cost and Context Window Calculator

This free calculator adds up your instructions, attached documents, chat history and reply space, shows how full the model's context window is, and estimates the cost of 1,000 runs with and without prompt caching. Keeping the window well short of full makes long prompts more reliable and cheaper. Everything runs in your browser.
Free, no sign-up, runs in your browser. Last checked 22 October 2026.

1. AI Token Cost and Context Window Calculator

Find out why an AI workflow is forgetting rules, cutting off replies, or costing too much - and fix it in 3 simple steps.

1
STEP 1: Pick or Type Your Issue Use Tab A to build a custom contract (WHO / WHAT / OUTPUT), Tab B to pick from 24 presets, or Tab C to paste your own text.
2
STEP 2: See the Diagnosis & 1-Click Fix Read the plain-English root cause and click the green "Apply Recommended Fix" button.
3
STEP 3: Fine-Tune Pages & Copy Template Adjust the page sliders if needed and copy your cache-pinned prompt template.
STEP 1 OF 3 β€’ BUILD FOR ANY NEED (WHO / WHAT / OUTPUT) OR PICK A DESIGNATED SCENARIO Use Tab A for any custom need (WHO / WHAT / OUTPUT / ETC), Tab B for the 24 designated scenarios, or Tab C for free-form text:
🧱 Universal Custom Building Block (Build a Verified Prompt & Schema Contract for Any Need)

Fill in the 4 core building blocks below (or click a starter archetype) - your custom contract & JSON Schema compile live below with 7/7 debugger verification.

Quick Archetypes:
1. WHO β€’ ROLE, PERSONA & AUDIENCE Who is the AI & who is this for?
2. WHAT β€’ TASK OBJECTIVE & INPUT CONTEXT What job needs to be done?
3. OUTPUT REQUIRED β€’ FORMAT & DELIVERABLE SCHEMA What exact output is required?
4. ETC β€’ HARD RULES, CONSTRAINTS & SAFETY GATES What must it never break?
βœ“ Custom Building Block Active β€’ 5 Output Schema Keys Bound
STEP 2 OF 3 β€’ INSTANT DIAGNOSIS & RECOMMENDED FIX

Scenario Loaded: 🎧 Customer Support RAG Knowledge Base (132 Pages - Optimal)

βœ… HEALTHY SETUP (WITHIN SAFE CEILING)

🚨 1. Why This Happens (Root Cause)

Answering complex customer tickets using a 36-page policy rulebook and 48 pages of retrieved product documentation.

πŸ› οΈ 2. How We Fix It (The Prescription)

Example benchmark configuration: 18K pinned rules (prefix-cached) + 24K retrieved docs + 16K ticket history + 8K reply space.

⚑ 3. Before vs. After Optimization
Memory Used:132 of 256 pgs β†’ 132 of 256 pgs
Middle-Doc Recall:Lower risk β†’ Lower risk
Pinned Cache Discount:Cached Top 36 Pages
STEP 3 OF 3 β€’ FINE-TUNE YOUR PAGES & COPY YOUR PROMPT TEMPLATE Move any slider on the left to test custom page counts - the cost & memory meter on the right updates live:
βš™οΈ Prompt Memory & Provider ControlsOPS-12
~36 pgs (13,500 words)
~48 pgs (18,000 words)
~32 pgs (12,000 words)
~16 pgs (6,000 words)
πŸ“Š Memory Load & Cost Breakdown

OPTIMAL LOAD

Memory Window Used (Target: Within Safe Ceiling)

132 of 256 Pages Allocated

66,000 / 128,000 Tokens (62,000 Free Headroom)

Recall Ceiling
Pinned Rules~36 pgs
Attached Docs~48 pgs
Chat History~32 pgs
Reply Space~16 pgs
Input vs. Output Token Split58,000 input @ USD 3.00/1M β€’ 8,000 output @ USD 15.00/1M
Cost per 1,000 Runs (Standard vs. Pinned Cache)USD 294.00 vs USD 248.10 (Save USD 45.90)
Middle-Document Instruction RecallLower risk (within safe recall zone)
πŸ›‘οΈ Built-In Pre-Flight Output Debugger & Code Sanitizer (app.doctor())

βœ… 7 of 7 prompt checks pass

βœ“ G1: Zero PlaceholdersPASS
βœ“ G2: XML & ASCII CommentsPASS
βœ“ G3: JSON Schema ValidPASS
βœ“ G4: Cache Prefix Pinned 1stPASS
βœ“ G5: Within Recall CeilingPASS
βœ“ G6: Reply Reserve >= 4pgPASS (16pg)
βœ“ G7: OCR & Slop ScrubbedPASS
Ready-to-Use Cache-Pinned Prompt Contract (Zero Placeholders β€’ Scenario-Grounded):

<!-- CACHE-PINNED PROMPT CONTRACT (66,000 / 128,000 TOKENS | SAFE LOAD | FORMAT: JSON_SCHEMA | ZERO PLACEHOLDERS) --> <system_instructions cache_control="ephemeral" budget="18000_tokens" pages="36"> <role_and_objective> Scenario: Customer Support RAG Knowledge Base (132 Pages - Optimal) Role: Customer Support RAG Resolution & Policy Compliance Specialist (OPS-02 / OPS-12) Objective: Resolve customer support tickets accurately using the 36-page pinned policy rulebook and 48 pages of retrieved product documentation within the safe memory load. </role_and_objective> <hard_operational_invariants> 1. Ground every troubleshooting step, warranty rule, and refund eligibility check in the pinned policy rulebook. 2. Never invent product features, promise unapproved discounts, or send external emails without staging a human-reviewed draft. 3. Write in a warm, direct human operator voice with zero banned AI slop buzzwords, zero corporate filler, and zero em-dashes. 4. Enforce 2-Bump Circuit Breaker (OPS-06): halt on 2nd consecutive validation fault and log root cause. </hard_operational_invariants> <output_contract format="application/schema+json" deliverable_mode="json_schema"> { "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "support_rag_response_contract", "type": "object", "additionalProperties": false, "required": [ "status", "scenario_id", "deliverable_format", "memory_load_pct", "verified_output", "citations" ], "properties": { "status": { "type": "string", "enum": [ "PASS", "NEEDS_REVIEW", "HALT_2_BUMP" ] }, "scenario_id": { "type": "string", "const": "support_rag" }, "deliverable_format": { "type": "string", "const": "json_schema", "description": "Strict JSON Schema Contract (Draft 2020-12)" }, "memory_load_pct": { "type": "number", "maximum": 65 }, "verified_output": { "type": "object", "required": [ "ticket_id", "policy_rule_cited", "troubleshooting_steps", "draft_customer_reply" ], "properties": { "ticket_id": { "type": "string", "minLength": 1 }, "policy_rule_cited": { "type": "string", "minLength": 1 }, "troubleshooting_steps": { "type": "string", "minLength": 1 }, "draft_customer_reply": { "type": "string", "minLength": 1 } } }, "citations": { "type": "array", "items": { "type": "string" } } } } </output_contract> </system_instructions> <reference_documents cache_scope="task_scoped" budget="24000_tokens" pages="48"> <document_manifest> - doc_01: Customer_Support_Policy_and_Warranty_Rulebook.md (36 pages β€’ Pinned Cached Prefix) - doc_02: Retrieved_Product_Technical_Docs_and_Ticket_Context.json (48 pages β€’ Task Scoped) </document_manifest> </reference_documents> <conversation_state max_tokens="16000" max_pages="32" reserve_reply="8000" reserve_pages="16" circuit_breaker="2_bump_max"> <rolling_state_handoff> Active context load locked at 66,000 / 128,000 tokens. Keep turn history under 32 pages (16,000 tokens) and reserve 16 pages (8,000 tokens) for complete, un-truncated Strict JSON Schema Contract (Draft 2020-12) output. </rolling_state_handoff> </conversation_state>

Put this free tool on your own site

Copy the code below and paste it into any web page or blog post. The tool runs inside your page, stays free, and updates itself when we improve it.

Why Deterministic Operator Tools Replace Trial-and-Error Prompting

❌ Broken Old Way (Ad-Hoc Trial & Error)

Stuffing 150+ pages of unranked docs and chat history into a prompt until the context window overflows, causing middle-document instruction forgetting and full-price token billing on every turn.

βœ… Deterministic New Mechanism (LocalZero Workbench)

Pinning static rules and schemas at Line 1 for a provider cache-read discount, trimming active context to a safe window share, and reserving at least 4,000 tokens for complete replies.

Context Window & Token Pricing Specification Table (Station 1)

Parameter / ComponentFormula / ThresholdDefault BenchmarkOperational Purpose
Total Window Saturation (%)(Rules + Docs + History + Reply) / Window * 10066,000 / 128,000 tokens (~132 of 256 pages)Keep within the safe recall zone to avoid middle-context recall drop-off
Pinned Top Rules (sys)Billed at discounted provider cache-read rates18,000 tokens (~36 pages)Locks static instructions and JSON schemas at Line 1
Attached Reference Docs (rag)Billed at 100% of input rate per 1M tokens24,000 tokens (~48 pages)Scopes task-specific PDFs, contracts, or retrieved chunks
Chat History (hist)Shrunk first by 'Trim to fit my current window'16,000 tokens (~32 pages)Compacts prior turns so old messages never crowd out rules
Reserved Reply Space (out)Billed at output rate per 1M tokens (min 4,000)8,000 tokens (~16 pages)Prevents mid-sentence or mid-file code/JSON truncation

How this is calculated

Frequently asked questions

How many tokens is a page of text?

About 500 tokens for a dense page of English, roughly 375 words. Code, tables and other languages use more tokens per word.

What is prompt caching and how much does it save?

Providers store the unchanging start of your prompt so repeat calls read it at a discount. Providers discount cached prefix reads substantially (see Anthropic and OpenAI pricing docs), though initial cache writes can cost slightly more than normal input. Put fixed instructions first and changing details last.

Why does my AI forget instructions in long chats?

As the context window fills, models are less reliable with details buried in the middle. Keep fixed rules at the top, summarize old chat history, and leave room for the reply.

Why do AI replies get cut off?

The reply must fit in the space left in the window and under the model's output limit. Reserve reply space and raise the maximum output setting.

Are the prices in the calculator current?

The price choices are examples. Enter your model's current price per million input tokens for a real estimate.

Sources and further reading

Related guides

More free AI tools

LLM Temperature and Top-P Settings ToolChoose temperature and top-p for your task and copy ready API settings. A simple simulated example shows how each setting changes the model's word choices.LLM VRAM Calculator: Will This Model Run on My GPU or Mac?Free LLM VRAM calculator. Pick a model, quantization and context length to see memory needed, whether it fits your GPU or Mac, a rough speed and the Ollama command.SKILL.md Generator for AI Agent SkillsTurn a repeatable task into a SKILL.md file with a name, description, allowed tools, rules and an output schema. Copy or download it free. Runs in your browser.AI Agent Retry Cost CalculatorSee how many tokens an AI agent burns when it keeps retrying a failing step, and how much a two-strike stop rule saves. Free, runs in your browser.AI Writing ClichΓ© CheckerPaste a draft to flag overused AI words like delve, tapestry and seamless, plus dash breaks and long sentences. Free, private, runs in your browser.Multi-Agent Task Queue PlannerPlan how long a queue of AI agent jobs takes across parallel workers and get a lock-safe dispatch schedule. Free, runs in your browser.OCR and Copy-Paste Text CleanerClean scanned or copy-pasted text: fix letter O and zero mix-ups in numbers, l and 1, curly quotes, hidden zero-width characters and extra spaces. Free and private.GEO Answer Capsule Checker for AI SearchCheck the short answer at the top of your page against a simple checklist for AI search: length, a named topic, a source link and question headings. Free.Book and Digital Product Profit CalculatorWork out profit per sale and per month for a book, ebook, workbook or digital product after store fees, printing, payment processing, royalties and a tax set-aside.