n4nAI

GPT-5 time-to-first-token: cold start vs warm cache

Analysis of GPT-5 time to first token cold start versus warm cache, breaking down prefill latency and cache strategies for production LLM apps.

n4n Team4 min read778 words

Audio narration

Coming soon — every post will get a voice note here.

The gap between a cold and warm GPT-5 time to first token cold start is not a model-quality issue—it is a systems problem rooted in prefix prefill and KV cache allocation. If your interactive app feels sluggish on the first request but snappy on the second, you are seeing cache misses, not slow generation.

What TTFT actually measures

Time-to-first-token (TTFT) is the interval from when the client sends a complete request to when it receives the first streamed token. It bundles network round-trip, load-balancer queueing, scheduler admission, prefill compute, and the first decode step. For a 200-token chat message the prefill cost is trivial; for a 32k-token system prompt with retrieved context, prefill dominates.

When we talk about GPT-5 time to first token cold start, we are really talking about the cost of building the key-value cache for the input prefix from scratch.

Cold start: where the latency hides

Prefill cost scales with input tokens

Autoregressive transformers compute attention over the full input sequence before emitting token one. That prefill pass allocates a KV cache sized to the context length and runs matrix multiplies across all input positions. On large models, this is memory-bandwidth bound, not compute bound, but the absolute milliseconds still grow linearly with prompt length.

A cold start has no reusable state. The provider must allocate GPU memory, load routing metadata, and run the forward pass on every input token. There is no shortcut.

Scheduler queueing compounds it

In multi-tenant inference, the cold request often lands behind other jobs. Because prefill is bursty and resource-heavy, schedulers may delay admission until a batch slot opens. This adds tail latency unrelated to your prompt but correlated with provider load.

Warm cache: prefix reuse in practice

How providers expose caching

OpenAI-compatible APIs implement prompt caching by hashing the prefix of the request. If an identical prefix (system block, few-shot examples, static instructions) was recently processed, the provider attaches the stored KV cache and skips recomputation. The first token then arrives after only the uncached suffix and a single decode step.

Some providers require explicit cache_control markers; others do it implicitly. A gateway like n4n.ai honors client routing directives and forwards provider cache-control hints, so your cache strategy survives provider failover.

Code: sending a cacheable prefix

Keep the static part of your prompt byte-identical across calls. Here is a minimal OpenAI-compatible request body:

{
  "model": "gpt-5",
  "messages": [
    {"role": "system", "content": "You are a strict JSON parser. Always output valid JSON."},
    {"role": "user", "content": "Parse: {{dynamic_input}}"}
  ],
  "stream": true
}

The system message is the cacheable prefix. If you mutate whitespace, add a timestamp, or reorder keys in a rendered template, the hash breaks and you pay cold-start cost again.

Measuring GPT-5 time to first token cold start

You cannot optimize what you do not measure. TTFT must be captured client-side because server-side logs exclude network and queueing.

A minimal timing snippet

import time, openai

client = openai.OpenAI(base_url="https://api.your-gateway.com/v1", api_key="sk-...")

start = time.perf_counter()
stream = client.chat.completions.create(
    model="gpt-5",
    messages=[{"role": "system", "content": "Static instructions..."},
              {"role": "user", "content": "Dynamic query"}],
    stream=True,
)
first_token_ts = None
for chunk in stream:
    if chunk.choices[0].delta.content:
        first_token_ts = time.perf_counter()
        break
ttft = first_token_ts - start
print(f"TTFT: {ttft*1000:.1f}ms")

Run this twice back-to-back: the second call should show a dramatically lower value if the prefix is cached. That difference is your GPT-5 time to first token cold start penalty.

Tradeoffs and failure modes

Cache key fragility

Prompt caches are content-addressed. Inserting a request ID, rotating a date string, or nondeterministic tool description invalidates the prefix. In practice, teams lose expected hits because of invisible template drift. Pin your system prompt and inject dynamics only after the cached boundary.

Eviction and TTL

Providers bound cache lifetime. Typical TTLs are minutes, not hours, and under memory pressure the eviction policy is LRU. If your traffic pattern has gaps longer than the TTL, every request is cold. For low-QPS internal tools, caching may never pay off.

Multi-region routing

If a gateway routes your retry to a different region or provider, the cache is absent. Automatic fallback solves availability but resets TTFT. Design for explicit affinity: pin a session to a region unless degraded.

Engineering recommendations

  • Front-load stable content. Put instructions, schemas, and few-shot examples in the system role or a leading user message that never changes.
  • Separate dynamic data. Pass user input as the final turn. Never interpolate it into the cached prefix.
  • Instrument TTFT per route. Record cold vs warm histograms. Alert when warm hit rate drops below a threshold.
  • Use cache-control directives where supported. If your gateway forwards them, set cache_control on the prefix block to signal intent.
  • Accept fallback tradeoffs. Failover protects uptime but costs a cold start. For latency-critical paths, prefer queuing over cross-region reroute.

Takeaway

Treat GPT-5 time to first token cold start as a prefill problem, not an inference problem. The single highest-leverage change is structuring prompts so the long prefix is immutable and cacheable, then measuring hit rate relentlessly. Warm cache turns seconds of prefill into milliseconds; ignoring it leaves your users staring at a blank box while the model recomputes what it already computed yesterday.

Tagsgpt-5time-to-first-tokencaching

Written by

n4n Team

The team building n4n — a single OpenAI-compatible API in front of 240+ models, with automatic fallback, load balancing and pay-per-token metering.

More from n4n Team →

All time-to-first-token benchmarks posts →