The wait before the first word: TTFT for app builders

APIFreeGroqKey · Updated 2026-11-22 · 9 min read

Runner waiting at the starting line next to a stopwatch
TTFT is the moment between the starting signal and the first step.

When people compare inference providers they usually quote one number: tokens per second. It is easy to measure and looks great on a chart. But users rarely complain that a reply arrived at 80 tokens per second instead of 200. They complain that they pressed a button and nothing happened for four seconds. That silent gap has a name, time to first token, usually shortened to TTFT, and for many interactive features it shapes the experience more than raw generation speed.

This article is for developers building chat boxes, autocomplete, assistants and anything else where a person watches the screen while the model works. You will learn what TTFT includes, why it varies so much between providers and between requests, how to measure it yourself with a few lines of Python, and which levers in your own code shorten it. We use Groq's hosted API and the keyless free-ai endpoint on this site as examples, but the ideas apply to any OpenAI-compatible service.

Frequently asked questions

What does time to first token measure exactly?

It is the time between sending a request and receiving the first generated token of the answer. It includes network travel, queueing on the provider's side, processing of your whole prompt and the generation of that first token. It does not include the rest of the answer.

How does TTFT differ from tokens per second?

Tokens per second describes how fast text flows once it has started. TTFT describes how long the user waits before anything appears. A provider can be very fast at streaming and still feel slow if requests sit in a queue or long prompts take a while to process.

Why is my TTFT sometimes ten times higher than usual?

Shared services batch and queue requests. At busy hours your request may wait behind others, or the provider may be loading capacity. Long prompts also raise TTFT because the whole input must be processed first. Measuring percentiles, not a single run, shows this spread.

Does a longer prompt always mean a slower first token?

Generally yes, because prefill work grows with input length. Some providers cache repeated prompt prefixes, which can reduce the cost for prompts that start the same way each time. Check your provider's documentation to see whether prompt caching applies.

Is a p95 value more useful than an average?

For user experience, usually yes. The average hides the slow tail that people remember. A p95 of several seconds means one request in twenty feels broken, even if the median looks fine. Track median and p95 together.

Does streaming reduce time to first token?

Streaming does not make the model start sooner, but without it the user waits for the whole answer, so the perceived wait becomes total generation time. With streaming, the perceived wait shrinks to TTFT, which is why almost every chat interface streams.

Which matters more for a voice or game feature?

Both, but TTFT is often the bottleneck. Spoken replies and character lines can start playing as soon as the first sentence is ready, so a quick first token followed by steady generation feels responsive even when total time is several seconds.

What happens between the click and the first word

A request to a hosted model passes through several stages before any text comes back. Your client opens or reuses a TLS connection and sends the JSON body. The provider authenticates the request, applies rate limits and places it in a queue. When a slot is free, the server runs the prefill step, reading every token of your system prompt, conversation history and user message. Only after prefill finishes can the model produce the first output token, which is then sent back over the stream.

Each of these stages can dominate depending on the situation. On a quiet service with a short prompt, network round trips may be most of the wait. On a busy free tier, queueing can add seconds. With a long retrieved context, prefill becomes the main cost. Knowing which stage is slow tells you which fix will help.

Prefill versus decode

Inference has two phases. Prefill processes the input in parallel and is limited by compute. Decode produces output one token at a time and is limited mostly by memory bandwidth. TTFT is roughly network plus queue plus prefill; tokens per second is a decode property. Hardware tuned for fast decode does not automatically shorten a long prefill.

The queue you cannot see

Providers rarely publish queue times, but you notice them as variance. Two identical requests sent a minute apart can differ by seconds. A common observation with free or experimental endpoints is a respectable median TTFT and a much worse p95, which is exactly the queue showing through.

Why fast generation can still feel slow

There is an interesting effect that developers sometimes describe about slow models: when output crawls at a modest rate, the session seems to last forever, so usage limits feel generous, while a very fast model burns through quotas quickly. The reverse also holds for perceived speed. A model that streams at a high rate but begins after a long pause feels sluggish, because humans judge responsiveness mostly by how quickly something starts to happen.

Reading speed puts a ceiling on how much generation speed helps. Most people read somewhere in the range of a few words per second. Once a stream comfortably outruns the reader, extra throughput mainly helps when a program consumes the output, for example when another step waits for structured JSON. For a human-facing chat, cutting a second off TTFT is often worth more than doubling throughput. For a deeper look at the throughput side, see our separate piece on how request batching works.

When throughput really wins

Batch jobs, agents that chain many calls and pipelines that parse full answers before acting do benefit from high tokens per second, because nobody watches the stream. There, total completion time matters and TTFT is just one part of it.

Paper boats queued at a canal lock
Queueing on a shared service is invisible but shows up as variance.

Measuring TTFT with a streaming request

You cannot trust a provider's marketing figure for your own workload, because your prompt length, region and time of day differ. The simplest measurement is a streaming request where you record the time when the request starts and when the first content chunk arrives. The script below does that against the keyless endpoint on this site and also prints the total time and an approximate output rate. Replace the base URL and key to test Groq or any other OpenAI-compatible provider the same way.

Chunks are not exactly tokens

Streaming chunks often carry one token, but some servers group several. Treat the chunk rate as an approximation. If you need exact numbers, compare the final usage figures with the timing, or count tokens with the tokenizer of the model you use.

import time
from openai import OpenAI

client = OpenAI(base_url="https://api.apifreegroqkey.com/v1", api_key="free")

def measure(prompt):
    start = time.perf_counter()
    first = None
    chunks = 0
    stream = client.chat.completions.create(
        model="free-ai",
        messages=[{"role": "user", "content": prompt}],
        stream=True,
        max_tokens=300,
    )
    for event in stream:
        if not event.choices:
            continue
        delta = event.choices[0].delta.content
        if delta:
            if first is None:
                first = time.perf_counter() - start
            chunks += 1
    total = time.perf_counter() - start
    return first, total, chunks

ttft, total, chunks = measure("Explain DNS caching in three sentences.")
print(f"TTFT {ttft:.2f}s, total {total:.2f}s, ~{chunks / max(total - ttft, 0.01):.0f} chunks/s")

Reading the numbers: percentiles, not anecdotes

One run tells you almost nothing. Run the same prompt twenty or fifty times, spread over different hours, and look at the median and the 95th percentile. On the keyless endpoint, keep the limits in mind: one request per second per IP with small bursts, and two requests in parallel. A loop with a pause of a little over a second between calls stays within those limits and gives you clean data.

Also vary the prompt length. Measure a short question, a prompt with a few thousand tokens of context and one close to the size you expect in production. Plotting TTFT against input length shows how much of the wait is prefill. If the curve is flat, your bottleneck is network or queueing; if it climbs steeply, trimming the prompt will pay off.

Separate cold and warm runs

The first call after a pause can be slower because connections must be opened and caches are empty. Record it, but report it apart from the warm runs so it does not distort the median.

  • Median TTFT: what a typical user sees
  • p95 TTFT: the slow tail that drives complaints
  • TTFT by prompt size: how much prefill costs you
  • Error rate: 429 and 503 responses count as very slow answers
  • Time of day: free and shared tiers vary with load
Laptop and notebook with hand-drawn timing curves
Measure many runs and look at percentiles, not one lucky request.

Levers you control in your own app

Many TTFT improvements need no provider change at all. The biggest one is the prompt. Every token in the system prompt, the chat history and the retrieved documents must be processed before the first output token. Long instructions written once and never pruned are a common hidden cost.

Trim history and context

Keep only the last few turns verbatim and summarize older ones. Retrieve fewer, better chunks instead of stuffing ten documents into each request. The answer quality often stays the same while prefill time falls.

Reuse connections

Create one client object and reuse it, so TLS handshakes are not repeated on every call. In serverless functions, keep the client outside the handler so warm invocations skip connection setup.

Start speculative work early

If a feature always needs a model call, start it as soon as you know the input, for example when the user stops typing, rather than on an explicit submit. Cancel the request if the input changes.

Turn off reasoning for snappy features

On the keyless endpoint, the optional "reasoning": true flag makes the model think before answering, which helps hard questions but delays visible output. Leave it off for autocomplete and short replies.

Hosted fast inference versus a free shared endpoint

Groq built its reputation on low latency, using its own chips designed for fast inference, and its API is frequently chosen for interactive features where response time is visible. Its free plan comes with rate limits that vary by model; consult Groq's current limits page before you depend on a specific number. A paid plan with an SLA is the right choice when slow tail latency would cost you customers.

The free-ai endpoint here is a different service, and this site is not affiliated with Groq. It runs an independent open-weight model of roughly 35B parameters with no key, no account and no SLA. It is useful for prototyping latency-sensitive flows, testing streaming code and comparing prompt sizes, but you should expect variable queueing at busy times and occasional 503 responses that tell you to retry in a few seconds. For a production feature where a slow p95 hurts, a paid provider is the honest recommendation.

Design for the slow tail anyway

Whatever provider you pick, show an immediate visual response, such as a typing indicator, and set a timeout after which you fall back or offer a retry. Users tolerate a short wait when they can see that something is happening.

Gardener trimming an overgrown hedge
Trimming prompts and history is the cheapest way to cut prefill time.

Perceived latency tricks that are honest

Some UX choices make waiting feel shorter without hiding anything. Show the user's message instantly in the chat log. Display a subtle indicator the moment the request is sent. For features that produce structured output, show a skeleton of the result layout so the page does not jump. In voice and game contexts, play a short acknowledgement while the real reply is generated; our guide on LLM-driven NPC dialogue covers that pattern in more detail.

Avoid tricks that mislead, such as fake typing animations that suggest a reply is coming when the request has actually failed. If a 429 or 503 arrives, tell the user plainly and retry with the delay the server suggests.

A short checklist before you ship

Before launch, measure TTFT under realistic prompts at the hours your users are active, and decide what number is acceptable. Write it down as a target, for example a p95 under two seconds, and test against it again whenever you add context, tools or a longer system prompt. If you are comparing several providers, use the same prompts and timing code for all of them; our walkthrough on benchmarking providers on your own prompts shows how to structure that comparison so the results are fair.

Re-test after every prompt change

Latency regressions creep in quietly. A new tool definition or a longer persona can add hundreds of tokens to every request, so keep the timing script in your repository and run it whenever the prompt grows.

  • Stream every human-facing response
  • Measure median and p95, not single runs
  • Keep system prompts and history lean
  • Reuse HTTP clients and connections
  • Handle 429 and 503 with visible, polite retries
Waiter serving bread while the main dish is prepared
Honest feedback while waiting makes a short delay feel shorter.
Try the free API

Send a request to the keyless free-ai endpoint from the home page and see how it fits your project, no sign-up needed.

Read also