n4nAI

Llama 4 inference speed benchmark on n4n routing

Practical analysis of Llama 4 inference speed n4n routing: isolating gateway overhead, provider variance, and cache hints to get real production latency numbers.

n4n Team5 min read1,011 words

Audio narration

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

Benchmarking Llama 4 inference speed n4n routing requires separating the routing layer’s overhead from the latency characteristics of the underlying provider. The thesis here is simple: a correctly configured gateway adds negligible latency while buying meaningful resilience, but raw token throughput is governed by the model variant and the accelerator behind it.

Why most Llama 4 latency numbers are noise

Engineers comparing providers usually slap a curl against an endpoint and report the time to first byte. That measurement conflates DNS, TLS, gateway routing, provider queue depth, and model warm-up. For Llama 4, a mixture-of-experts (MoE) architecture, cold-start penalties are pronounced because expert weights must be loaded or shifted into high-bandwidth memory.

When you route through n4n, the request hits one OpenAI-compatible endpoint that addresses 240+ models and then forwards to a backend. The hop itself is a single intra-region proxy if you deploy close to the gateway. The variable is which provider answers.

The extra hop is not the bottleneck

A routing layer adds at most a few milliseconds of processing per request: header parsing, auth check, and directive forwarding. In practice, the same-region round trip between your service and the gateway plus the gateway-to-provider leg is dwarfed by provider-side scheduling. If you measure 800 ms TTFT, blame the provider’s batching, not the proxy.

Network topology matters more than the proxy. A gateway in us-east-1 forwarding to a provider in eu-west-2 injects cross-Atlantic latency no matter how thin the gateway code is. Control region explicitly before drawing conclusions about Llama 4 inference speed n4n routing.

Setting up a defensible test

To measure honestly, pin the model and provider, disable fallback, and run a warm-up pass. Use streaming to capture time-to-first-token (TTFT) and tokens-per-second (TPS) separately.

from openai import OpenAI
import time

client = OpenAI(
    base_url="https://api.n4n.ai/v1",
    api_key="YOUR_KEY",
)

def measure(prompt: str, provider: str):
    start = time.time()
    stream = client.chat.completions.create(
        model="llama-4-scout",
        messages=[{"role": "user", "content": prompt}],
        stream=True,
        extra_body={"routing": {"provider": provider}}  # client routing directive
    )
    first = None
    n_tokens = 0
    for chunk in stream:
        delta = chunk.choices[0].delta.content
        if delta:
            if first is None:
                first = time.time()
            n_tokens += 1
    end = time.time()
    ttft = (first - start) * 1000
    decode_ms = (end - first) * 1000
    tps = n_tokens / (decode_ms / 1000) if first else 0
    return ttft, tps

n4n.ai exposes that single endpoint and honors the routing directive, so the comparison against a direct provider call is apples-to-apples. Run the identical payload straight to the provider’s base URL and subtract medians.

A bare-bones shell check helps sanity-check the non-streaming path:

curl -s -o /dev/null -w "starttransfer=%{time_starttransfer}\n" \
  -H "Authorization: Bearer $KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"llama-4-scout","messages":[{"role":"user","content":"hi"}]}' \
  https://api.n4n.ai/v1/chat/completions

Use this only for TCP/TLS handshake baselines, not for token metrics.

What Llama 4’s architecture does to your numbers

Llama 4 ships MoE variants (Scout, Maverick). Only a subset of experts activates per token. That reduces FLOPs per token versus a dense model of equal parameter count, but it increases memory bandwidth pressure and complicates batching.

A direct consequence: TTFT scales with prompt length because the router must score experts and fetch weights. Throughput stabilizes once the decode loop runs, but small batches waste the expert parallelism. If your workload sends many short prompts, you will see lower TPS than a provider’s marketing chart implies.

Expert routing itself is not free. The gating network runs on every forward pass; for long contexts the overhead is amortized, but for single-shot tiny prompts it can be a measurable fraction of total compute. This is intrinsic to the model, not the gateway.

Measuring token throughput without lying to yourself

Streaming TPS must exclude the TTFT interval. Divide generated tokens by the decode duration only. Also account for tokenization mismatch: count tokens as returned by the API, not words in your string.

If you benchmark a 100-token prompt and 200-token completion, run at least 20 iterations and drop the first five as warm-up. Report median and p95, not averages. A single lucky uncrowded moment produces vanity numbers.

# inside the loop above, after collecting end time:
def report_runs(prompt, provider, n=20):
    ttfts, tpss = [], []
    for _ in range(n):
        ttft, tps = measure(prompt, provider)
        ttfts.append(ttft)
        tpss.append(tps)
    ttfts.sort(); tpss.sort()
    p95_ttft = ttfts[int(0.95*len(ttfts))-1]
    median_tps = tpss[len(tpss)//2]
    return p95_ttft, median_tps

Cache hints change the game

Llama 4 prompts often contain long system prefixes. Provider-side prompt caching cuts TTFT dramatically when the prefix is stable. n4n forwards provider cache-control hints, so you can annotate messages and let the backend reuse KV caches.

{
  "model": "llama-4-maverick",
  "messages": [
    {
      "role": "system",
      "content": "Long static instructions...",
      "cache_control": {"type": "ephemeral"}
    },
    {"role": "user", "content": "Actual question?"}
  ]
}

Without this hint, repeated prefixes are re-processed. With it, TTFT drops from hundreds of milliseconds to near-zero on cache hit. This single optimization outweighs any routing overhead by an order of magnitude. Ignore it and you will misattribute slowness to the gateway.

Provider variance is the real story

Under the n4n routing umbrella, Llama 4 inference speed n4n routing differs primarily because backends differ. One provider may run FP8 on H100, another may serve via quantized weights on A100. The gateway’s automatic fallback hides these gaps—when a pinned provider returned 429s in our test, the request rerouted and completed, but latency tripled.

That resilience is valuable, but it ruins microbenchmarks. If you need deterministic speed, disable fallback and pin. If you need uptime, accept variance. The routing layer is a weather vane, not the climate.

Per-token usage metering lets you see exactly which backend served a request after the fact, which is the only way to attribute cost and latency post-fallback. Use the response headers or usage block to slice your own data.

Tradeoffs: resilience vs pinning

When to pin

  • Low-latency interactive agents where p95 TTFT must stay under a strict bound.
  • Batch jobs where you’ve validated a specific backend’s throughput.
  • Repeated cached prefixes where you want a stable warm pool.

When to let routing float

  • Background summarization where a few seconds of delay is acceptable.
  • Prototyping across model variants without code changes.
  • Incident windows when a primary provider is degraded and you care about completion, not speed.

The routing directive in extra_body is your lever. Use it explicitly; don’t assume the gateway guesses your priority.

Honest limitations of this analysis

We did not publish absolute numbers because they would be misleading without your exact region, model variant, and provider mix. Llama 4 inference speed n4n routing in us-east-1 against provider X will not match eu-west-2 against provider Y. The methodology above is portable; the digits are not.

MoE behavior also shifts with batch size in ways dense models do not. A benchmark with concurrency 1 tells you nothing about concurrency 32. Test at your production parallelism.

Takeaway

Route Llama 4 through a gateway for production resilience, but pin providers and use cache hints when latency matters. The routing layer’s added milliseconds are irrelevant next to provider queueing and cold experts. Measure TTFT and decode TPS separately, warm up, and drop outliers. If you internalize one thing: Llama 4 inference speed n4n routing is a provider question wearing a routing costume—strip the costume before you optimize.

Tagsllama-4n4nroutinginference-speed

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 llama 4 inference speed by provider posts →