0Pricing
AI Prompt Engineering · Lesson

Million-Token Context Windows

Opportunities and pitfalls.

Million-Token Context Windows is a free AI Prompt Engineering lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AI Prompt Engineering learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What a Million Tokens Buys

Million-token windows let you place entire codebases, document corpora, or multi-hour transcripts directly in context — no retrieval system required. The promise is in-context everything: the model reasons over the raw material rather than over a lossy summary.

  • Whole-repository reasoning and refactors.
  • Cross-document synthesis without chunking.
  • Long-horizon conversations that retain early detail.

But capacity is not the same as effective use.

Capacity vs Effective Context

The advertised window is an upper bound, not a guarantee of uniform recall. Effective context — the span over which the model reliably retrieves and reasons — is usually smaller and uneven across positions.

Treat the window as a budget with non-uniform value: tokens near the edges are recalled better than tokens buried in the middle.

Latency and Cost Realities

Attention cost grows with context length, and so does time-to-first-token. A million-token prompt can mean seconds of prefill latency and substantial per-call cost, even when the answer is short.

  • Prefill dominates latency for huge prompts.
  • Cost scales with input tokens regardless of output size.
  • Stuffing context you do not need is paying to confuse the model.
# Rough mental model: input tokens drive both $ and prefill ms.
# 900k tokens of haystack to answer one question is rarely optimal.

Distraction and Dilution

More context can hurt accuracy. Irrelevant material dilutes attention and introduces distractors the model may latch onto. A focused 20k-token prompt often beats a noisy 500k-token one for a specific question.

The rule: include what helps the task, exclude what merely could be relevant.

When Long Context Beats Retrieval

Long context wins when the task needs global, cross-cutting reasoning that retrieval would fragment: 'find every place this invariant is violated across the repo', 'reconcile contradictions across all ten contracts'. Chunked retrieval can miss the connection that spans chunks.

Use full context for synthesis; use retrieval for needle lookups in enormous corpora.

When Retrieval Beats Long Context

Retrieval wins when the relevant fraction is tiny and stable. Fetching the 5 relevant pages out of 50,000 is cheaper, faster, and often more accurate than stuffing all 50,000 and hoping the model finds them.

  • Frequent queries over a static corpus -> index once, retrieve cheaply.
  • One-off global synthesis -> long context.

Many systems combine both: retrieve to narrow, then long-context to synthesize.

def route(task):
    if task.is_global_synthesis: return 'long_context'
    if task.relevant_fraction < 0.05: return 'retrieval'
    return 'hybrid'

Position Is a Resource

Because recall varies by position, where you place content is a design decision. Put the task instruction and the most critical material at the boundaries the model recalls best, and avoid burying must-use facts in the deep middle.

You manage position deliberately, not by accident of concatenation order.

Verifying Long-Context Recall

Never assume the model used a buried fact. Probe it. Insert a known canary fact at a known depth and ask for it; measure recall across depths to characterize your model on your prompt shape before trusting it in production.

canary = 'The internal code name is BLUE_HERON.'
# Place at depth d, then ask: 'What is the internal code name?'
# Sweep d across the window to map recall vs position.

Compaction Over Accumulation

In long agentic sessions, do not let context grow unbounded. Periodically compact: summarize stale turns into a dense state object and drop the raw history. This preserves the signal while reclaiming budget and reducing dilution.

Accumulation is the default and the trap; compaction is the discipline.

state = summarize(old_turns)  # dense facts, decisions, open items
context = [system, state] + recent_turns

Hybrid Architectures

The strongest designs blend strategies: retrieve a focused candidate set, place it with deliberate positioning, cache the stable prefix, and compact the conversation. Long context is one tool in a budget-management toolkit, not a replacement for engineering.

  • Retrieve to shrink.
  • Position to expose.
  • Cache to cheapen.
  • Compact to sustain.

Decision Heuristics

Before reaching for the full window, ask:

  • Does the task need global reasoning, or a needle? Needle -> retrieve.
  • Is the relevant fraction small and stable? Yes -> retrieve/cache.
  • Will latency/cost of a huge prefill be acceptable? No -> shrink.
  • Have I verified recall at the depth I am relying on? If not, probe first.

Capacity is permission, not a plan.

Quick Check

You must answer one narrow factual question that lives on roughly 3 pages out of a static 40,000-page archive, and you will run this query thousands of times a day.

Recap: Million-Token Windows

A huge window is a non-uniform budget, not free recall. Effective context is smaller than capacity, latency and cost scale with input, and irrelevant material dilutes accuracy. Use long context for global synthesis, retrieval for needles, and hybrids for the rest — positioning critical content at strong recall zones, caching stable prefixes, compacting long sessions, and always probing recall before you trust a buried fact.

Frequently asked questions

Is the “Million-Token Context Windows” lesson free?

Yes — the full text of “Million-Token Context Windows” is free to read here on the web, and the AI Prompt Engineering course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AI Prompt Engineering course, upgrade to CoddyKit PRO.

What will I learn in “Million-Token Context Windows”?

Opportunities and pitfalls. You practise AI Prompt Engineering with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start AI Prompt Engineering?

No prior experience is required. AI Prompt Engineering on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Million-Token Context Windows” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this AI Prompt Engineering lesson?

Yes. Every AI Prompt Engineering lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Million-Token Context Windows
  2. Lost in the Middle
  3. Structuring Huge Prompts
  4. Caching Long Prefixes
← Back to AI Prompt Engineering