Lounge
Connecting…
Connecting…
View all

Why Long Context Is Costly: Subquadratic Attention Explained

Why long-context LLMs cost more, what new subquadratic attention papers (LSA, ZHA) claim, and practical ways to cut long context cost today.

AIBasics8 min read29 viewsPublished Updated
Contents8 sections
  1. Why long context is expensive: attention complexity is quadratic
  2. What is subquadratic attention? Sparse and hierarchical indexers
  3. What the two new papers claim: LSA and ZHA
  4. How long context cost shows up in API pricing
  5. Practical ways to cut long context cost today
  6. Quality risks and how to read the research
  7. Frequently asked questions
  8. Sources and references

Key takeaways

  • Full self-attention scores every pair of tokens, so its compute and memory grow with the square of the context length.
  • Subquadratic attention lets each query look at only a selected subset of keys. The hard part is making the indexer that picks those keys cheap as well.
  • Two arXiv preprints submitted on October 30, 2026 (LSA and ZHA) use hierarchical clusters or trees of keys and report large speedups beyond one million tokens, but they are not yet peer reviewed.
  • API users pay per token, not per attention operation. Checking long-context price thresholds, prompt caching, batch processing and trimming context are the levers you control today.

Long-context AI is expensive mainly because standard transformer attention compares every token with every other token. Double the context and the number of pairs to score roughly quadruples; make it ten times longer and the pairs grow a hundredfold. Subquadratic attention is the line of research that tries to bend that curve by letting each query attend to only a chosen subset of keys. This guide explains the mechanics, what two new arXiv preprints submitted on October 30, 2026 actually claim, and how developers can control long context cost today. Facts were checked against the papers and the official Anthropic and OpenAI pricing documentation as of November 3, 2026.

Why long context is expensive: attention complexity is quadratic

Why long context is expensive: attention complexity is quadratic

A large language model processes text as tokens. In each attention layer, every token produces a query that is scored against the keys of the tokens it can see, and those scores decide how the corresponding values are mixed. With n tokens there are about n times n scores to compute. The FlashAttention paper states the problem plainly in its abstract: transformers are slow and memory-hungry on long sequences because the time and memory complexity of self-attention are quadratic in sequence length (arXiv 2205.14135).

1x

Token pairs to score (full attention)
1x
Growth
Baseline

2x

Token pairs to score (full attention)
4x
Growth
Quadratic

10x

Token pairs to score (full attention)
100x
Growth
Quadratic

100x

Token pairs to score (full attention)
10,000x
Growth
Quadratic

The table is a conceptual calculation. A real model also contains feed-forward layers and other components whose cost grows linearly with length, so total cost does not rise exactly with the square. Still, once the context reaches hundreds of thousands or millions of tokens, attention dominates. The LSA authors describe full attention above one million tokens as prohibitively expensive (arXiv 2610.42147).

Prefill, decode and the KV cache

It helps to split inference into two phases. Prefill reads the whole prompt at once; it is the wait you notice before the first word appears after pasting a long document. Decode generates the answer one token at a time, and each new token attends to everything before it. To avoid recomputing, servers keep the keys and values in a KV cache. The longer the context, the more GPU memory that cache occupies, which reduces how many requests one GPU can serve at the same time. For a provider, fewer concurrent users per GPU is the real cost of long context, and that cost eventually shows up in pricing.

What is subquadratic attention? Sparse and hierarchical indexers

What is subquadratic attention? Sparse and hierarchical indexers

Subquadratic attention is an umbrella term for attention methods whose cost grows more slowly than the square of the context length. The most common route is sparse attention: instead of scoring every key, each query computes exact attention over a small set of keys that look relevant. The catch is the indexer that chooses those keys. If the indexer itself scans every key, the method is still quadratic underneath. The ZHA paper groups earlier work into two camps: sliding-window and linear attention variants with a fixed-size state, which give up some expressiveness, and sparse methods whose indexers scale quadratically, which only deliver constant-factor speedups (arXiv 2610.42112).

Full attention

Core idea
Score every key
Scaling with length
Quadratic
Caveat
Exact, but very costly at ultra-long context

FlashAttention

Core idea
Same math, fewer GPU memory reads and writes
Scaling with length
Quadratic (same number of pairs)
Caveat
Exact results; does not change the growth rate

Sliding window or linear attention

Core idea
Look only nearby, or compress into a fixed-size state
Scaling with length
Roughly linear
Caveat
May lose distant details or expressiveness

Sparse attention with a flat indexer

Core idea
Indexer picks a subset of keys
Scaling with length
Constant-factor gains if the indexer is quadratic
Caveat
Indexer remains the bottleneck

Hierarchical indexer (LSA, ZHA)

Core idea
Group keys into clusters or a tree and search top-down
Scaling with length
Subquadratic (as claimed)
Caveat
Preprints; need replication and production testing

The intuition behind a hierarchical indexer is a library catalog. Rather than checking every book, you walk from section to shelf to row, discarding most of the building along the way. Keys are grouped into summaries; a query scores the top-level summaries first and only descends into promising branches. The selected keys then receive exact attention. Both new papers share this structure, though they build the hierarchy differently.

What the two new papers claim: LSA and ZHA

Latent Sparse Attention (LSA)

LSA clusters keys hierarchically in a learned latent space, and queries score the hierarchy of clusters instead of every key. The authors say this speeds up prefill, decode and training at long context. They propose Distilled-LSA, which can be added to pre-trained models through distillation, and Native-LSA, trained from scratch on next-token loss alone. According to the abstract, at 10M tokens D-LSA speeds up one attention layer by 22.7x in prefill and 4.6x in decode compared with GLM-5.3-FLASH's original sparse attention, and by 72.4x in prefill and 42.5x in decode compared with full attention in QWEN-3.8-27B, while keeping similar accuracy across a range of tasks. N-LSA is reported to match full attention accuracy with a 1.6x per-layer training speedup at 128k tokens (arXiv 2610.42147).

Zyphra Hierarchical Attention (ZHA)

ZHA builds a tree of recursively compressed key summaries over the KV cache. Future queries traverse it from the top down to fetch a sparse subset of keys. By growing the tree's depth as the sequence grows, the per-query cost, including routing and the final attention step, rises sublinearly, so overall attention scales subquadratically but still superlinearly. The authors report that ZHA can be applied to existing pretrained models with a short KL distillation stage over a few billion tokens, that it maintains performance on long-context retrieval, reasoning, math and agentic coding evaluations, and that it stays robust with trees up to six levels deep. Their performance model suggests large advantages over competing methods beyond one million tokens and potential to extend effective context to hundreds of millions or billions of tokens (arXiv 2610.42112).

Both papers are version 1 preprints submitted to arXiv on October 30, 2026. They have not been peer reviewed or independently reproduced. The speed figures are per attention layer or come from a performance model, so they do not translate directly into end-to-end latency or API prices.

To follow how new models and papers are being discussed, the theddari AI Telegram trends page and the blog trends page collect mentions in one place. Buzz is not the same as validated performance, so keep reading the original abstracts and evaluation scope alongside any headline.

How long context cost shows up in API pricing

API customers do not pay for attention operations directly; they pay tokens times the per-token rate. That makes the bill look linear, but providers fold the quadratic compute and memory burden into their pricing policies. Based on the official documentation checked on November 3, 2026, policies fall into two broad patterns: a flat rate across the window, or a higher rate once a request crosses a threshold.

Anthropic Claude 4.6 and later (except Haiku 5.5)

Long-context policy
Full 1M-token window at standard rates; a 900k-token request uses the same per-token rate as a 9k-token one
Source
Claude Pricing

Anthropic Claude Haiku 5.5

Long-context policy
Prompts over 100,000 tokens pay higher rates (input $0.10 to $0.50 per million tokens)
Source
Claude Pricing

OpenAI GPT-5.4

Long-context policy
1.05M window; prompts over 272K input tokens priced at 2x input and 1.5x output for the full session
Source
GPT-5.4 model docs

Anthropic notes that for Haiku 5.5 the prompt length includes cache reads and cache writes, and a request over the threshold pays the higher price even if part of it is a cache hit (Claude Pricing). OpenAI applies the GPT-5.4 surcharge across standard, batch and flex tiers (GPT-5.4 docs). In other words, two models with similar context windows can produce very different bills near the threshold. Prices change often, so recheck the current tables before you budget.

Practical ways to cut long context cost today

You do not have to wait for new attention methods to reach production models. Several levers are already in your hands.

  1. 1

    Know each model's threshold

    Check whether your model has a long-context price break, such as 100,000 tokens or 272K tokens. If many requests land just above it, trimming a little context to stay below can change the effective rate significantly.

  2. 2

    Cache repeated prefixes

    Sending the same system prompt, reference document or chat history every time means paying to process it every time. On Anthropic, a cache hit costs 0.1x the base input rate (lower on some newer models) and a five-minute cache write costs 1.25x, so a single reuse already pays off. Caches expire, so plan for rewrites.

  3. 3

    Batch work that can wait

    Anthropic's Batch API discounts both input and output by 50 percent, which suits bulk summarization or offline analysis. OpenAI's GPT-5.4 docs also list batch endpoint support.

  4. 4

    Put only what matters in the prompt

    Use retrieval to pull relevant passages instead of whole documents, and replace old conversation turns with summaries. Fewer input tokens lower both cost and time to first token.

  5. 5

    Measure quality with a small eval set

    After trimming context or switching models, compare answers on a few dozen real questions from your workload. Record the results so you know savings did not come at the expense of accuracy.

Quality risks and how to read the research

The core risk of sparse attention is simple: keys that are not selected are left out. If the indexer misses the key holding the decisive fact, the model may answer as if it never saw it. Rare but critical details, such as one exception clause in a long contract or a single config line in a large codebase, are the most exposed. Read any claim of similar accuracy together with the tasks, models and lengths where it was measured.

  • Check the unit of the speedup: LSA's 22.7x and 72.4x figures are for one attention layer, not whole-model latency.
  • Check the baseline: speedups over an existing sparse attention and over full attention are different comparisons.
  • Check how it was applied: distilled variants may behave subtly differently from the original model.
  • Check for replication: treat results as provisional until code, weights or independent reproductions appear.
  • Check for deployment: a paper is not an announcement of lower API prices or a specific product change.

In short, long context costs more because attention compares every pair of tokens, and subquadratic attention tries to shrink that structural cost by using hierarchical indexers to compare fewer pairs. Until that research is validated and deployed, the reliable way to manage long context cost is to know your model's price thresholds, cache repeated prefixes, batch non-urgent work, keep prompts lean, and measure quality on your own tasks.

Frequently asked questions

Why does attention scale quadratically with context length?
Each token acts as a query that scores its relevance against the keys of all other tokens in the context. With n tokens that is roughly n times n scores, so the work and the memory for those scores grow with n squared. Implementation tricks such as FlashAttention reduce memory traffic but still compute the same number of pairs.
If a model has a 1M-token context window, should I fill it?
Usually not by default. You still pay for every input token, latency grows, and some models switch to higher rates past a threshold. As of November 2026, OpenAI's GPT-5.4 docs apply 2x input and 1.5x output pricing to prompts above 272K input tokens. Retrieval or summarization that keeps only the relevant material is often cheaper and can be just as accurate.
Does sparse attention hurt answer quality?
It can. Keys the indexer does not select are simply left out of the attention calculation, so a missed key means missed information. The LSA and ZHA papers report similar accuracy to their baselines on the tasks they tested, but that does not guarantee the same result on your documents or code. Evaluate on your own workload before relying on it.
Will subquadratic attention make AI APIs cheaper?
Possibly over time, but there is no announced link yet. Prices depend on hardware, demand and business strategy, not only on algorithms. Both papers are October 2026 preprints with no stated product rollout, so treat lower long-context surcharges as a possible future outcome rather than a near-term expectation.

Sources and references

  1. 1arXiv: Latent Sparse Attention: Towards Subquadratic Ultra-Long Context Attention (2610.42147v1)(opens in a new tab)arxiv.org
  2. 2arXiv: Subquadratic Attention with a Hierarchical Tree-Structured Indexer (2610.42112v1)(opens in a new tab)arxiv.org
  3. 3arXiv: FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness(opens in a new tab)arxiv.org
  4. 4Anthropic Claude API Pricing(opens in a new tab)platform.claude.com
  5. 5OpenAI API: GPT-5.4 model documentation(opens in a new tab)developers.openai.com