Skip to content

Same-machine gateway comparison

Last updated: 2026-11-07T07:09:47-03:00 (UTC-3)

This gateway against LiteLLM, Bifrost and Portkey, each in its own container on the same machine, with the same CPU limit and the same simulated upstream, measured with gwbench. The tables are generated from same-machine.json by scripts/render-performance.py; the prose around them is written by hand. A second, independent comparison, run on AWS with a public benchmark’s method, is in Gateway benchmark reproduction. This gateway’s own numbers and how they are measured are under Performance.

A first measurement said “+0.8 ms of overhead versus +118.9 ms for LiteLLM”. The numbers were measured, but they were not comparable:

  • CPU: the gateway ran natively with 12 cores; LiteLLM ran with 1 Python worker, that is, one core.
  • Work per request: the gateway ran with chat_completions only, without PostgreSQL (possible before T087 made PostgreSQL mandatory); LiteLLM had a database, spend logs and num_retries.
  • Queueing: at concurrency 32, the 118.9 ms was almost entirely queueing in the saturated worker (32 ÷ 266 req/s ≈ 120 ms), not per-request cost.
  • TTFT with a real model (246 ms versus 300 ms) had no direct baseline: there was no way to separate the model from the gateway.

The measurement below fixes this. The method shared by every target is in How performance is measured; what differs per gateway:

  • Same CPU and memory: each gateway runs in a container with --cpus 2. LiteLLM with --num_workers 2; the Go gateways (ours and Bifrost) respect the cgroup CPU quota.
  • Same upstream, same path: all gateways in the same network namespace as the simulated provider, reached over loopback, and the client reaches all of them through the same host port forwarding.
  • Authentication on all of them: gateway key (ours), master key or virtual key (LiteLLM), virtual key x-bf-vk (Bifrost). Portkey OSS does not authenticate clients and persists nothing.
  • Production mode: per-request persistence in each tool. Ours writes durable_usage (the receipt, before inference), usage_analytics, request_logs and request_timing; LiteLLM keeps virtual keys in PostgreSQL and batches spend logs; Bifrost logs to SQLite; Portkey persists nothing.

Measured at commit 54414f9 against LiteLLM 1.104.5, Bifrost 2.3.2, Portkey 1.15.2. Environment: Mac Mini M4 Pro (Apple Silicon), Docker Desktop; each gateway in a container with –cpus 2, upstream simulated by gwbench -mock on the same host.

Cost per request: concurrency 1, instant upstream, minimal mode

Section titled “Cost per request: concurrency 1, instant upstream, minimal mode”

With no queue, the difference from direct is the gateway’s work on each call.

Target overhead p50 p99 CPU ms/req peak memory
ai-gateway +0.1 ms 3.5 ms 0.09 21 MB
Bifrost 2.3.2 +0.2 ms 1.1 ms 0.24 188 MB
Portkey 1.15.2 +0.4 ms 2.4 ms 0.79 128 MB
LiteLLM 1.104.5 +3.0 ms 4.4 ms 3.06 1,463 MB

Measured on 2026-10-26; source: fair round of 2026-10-26 (gwbench Markdown output, transcribed when this page was created).

Under load: instant upstream, minimal mode

Section titled “Under load: instant upstream, minimal mode”
Target c=32 p50 c=32 req/s c=128 p50 CPU ms/req
ai-gateway 2.0 ms 13,190 6.6 ms 0.09–0.11
Bifrost 2.3.2 3.9 ms 6,669 10.5 ms 0.24–0.25
Portkey 1.15.2 11.0 ms 2,668 42.4 ms 0.45–0.57
LiteLLM 1.104.5 44.4 ms 712 186.9 ms 2.75–3.14

Measured on 2026-10-26; source: fair round of 2026-10-26 (gwbench Markdown output, transcribed when this page was created).

A TTFT of 300 ms and a token every 20 ms: the scenario of a real provider.

Target c=8 TTFT p50 c=128 p50 c=512 p50 c=512 req/s c=512 CPU ms/req c=512 mem
direct 306.1 ms 669.5 ms 644.5 ms 486 — —
ai-gateway 307.9 ms (+1.8) 658.1 ms 638.6 ms 727 0.35 97 MB
Bifrost 2.3.2 309.3 ms (+3.2) 649.6 ms 645.4 ms 690 0.95 389 MB
Portkey 1.15.2 342.8 ms (+36.7) 639.1 ms 724.5 ms 583 2.02 172 MB
LiteLLM 1.104.5 323.1 ms (+17.0) 801.1 ms 2,037 ms 161 8.65 1,666 MB

Measured on 2026-10-26; source: fair round of 2026-10-26 (gwbench Markdown output, transcribed when this page was created).

Our gateway writes the durable receipt before inference (durable_usage), plus analytics, logs and timing; LiteLLM uses PostgreSQL with batched spend logs; Bifrost, SQLite; Portkey, no persistence.

Target c=1 p50 c=32 p50 c=128 req/s realistic c=512 p50 CPU ms/req
ai-gateway (PostgreSQL) 3.6 ms 13.8 ms 2,240 684 ms (558 req/s) 0.29–0.73
LiteLLM (PostgreSQL) 3.8 ms 61.5 ms 379 2,525 ms (179 req/s) 4.1–11.1
Bifrost (SQLite) 0.3 ms 4.9 ms 1,830 689 ms (721 req/s) 0.28–1.46
Portkey (no persistence) 0.5 ms 14.3 ms 745 752 ms (496 req/s) 0.61–2.28

Measured on 2026-10-26; source: fair round of 2026-10-26 (gwbench Markdown output, transcribed when this page was created).

To update: run the scenario with every target and record it with gwbench -record docs/benchmarks/same-machine.json -scenario <id> -title "..." -commit $(git rev-parse --short HEAD), then python3 scripts/render-performance.py.

Direct falls below the gateways in req/s at concurrency 512 in the realistic stream because the client opens 512 new connections through the host forwarding, while the gateways reuse connections to the upstream. Negative overheads in this range are noise from that queue.

Durability has a price. Our receipt is written synchronously before the provider is called, so that a crash never loses billing: ~3.5 ms per request with an instant upstream. LiteLLM aggregates spend logs in memory and writes them in batches: almost nothing per request, but it loses whatever is in the buffer if the process crashes. Bifrost writes to local SQLite, off the critical path. With a realistic upstream, the difference disappears inside the provider’s ~640 ms.

Shouldn’t Go make TTFT much lower than LiteLLM’s? Not by much, and that is what the measurement shows. The gateway does not speed up the model: TTFT is ~300 ms of provider plus whatever the gateway adds. Ours adds +1.8 ms; LiteLLM adds +17 ms under light load. Go’s advantage shows up in three places:

  • under concurrency: with 512 streams, LiteLLM reaches +1.4 s of queueing in TTFT, and ours stays within the noise;
  • CPU per request: 0.35 ms versus 8.65 ms, that is, ~25× fewer replicas for the same throughput;
  • memory: 97 MB versus 1.7 GB.

A “statistical tie” in the old TTFT (246 ms versus 300 ms)? That number had no direct baseline and mixed in the model’s time. With a baseline, the difference between the two is exactly each gateway’s overhead, and under light load it is small next to the model.

Bifrost is the relevant comparison (Go against Go). The two tie on latency with a realistic upstream. Ours uses ~2.5× less CPU per request and ~4× less memory. Bifrost is faster in production mode because it does not write a durable receipt before the call.

Streaming, 80 requests per target (160 in the focused round), each gateway in a 2-CPU container. With a real provider, network variance dominates; overheads below ~10 ms are within the noise.

OpenAI (gpt-4.1-mini):

Target c=1 p50 c=1 overhead c=8 p50 c=8 overhead c=8 TTFT p50 memory
direct (OpenAI) 658.7 ms — 648.0 ms — 563.4 ms —
ai-gateway 660.1 ms +1.3 ms 654.4 ms +6.5 ms 559.9 ms 16 MB
LiteLLM 1.104.5 660.2 ms +1.5 ms 709.8 ms +61.9 ms 601.7 ms 1,520 MB
Bifrost 2.3.2 727.3 ms +68.6 ms 693.7 ms +45.7 ms 614.7 ms 150–180 MB
Portkey 1.15.2 636.8 ms −21.9 ms 684.8 ms +36.9 ms 609.9 ms 70 MB

At concurrency 1, Bifrost had an isolated p99 of 36 s; at concurrency 8, the difference between gateways shows.

Anthropic (claude-haiku-4-5). The workspace header goes through the fixed provider headers in ours, extra_headers in LiteLLM and Bifrost, and x-portkey-forward-headers in Portkey:

Target c=1 p50 overhead c=8 p50 overhead c=8 TTFT p50
direct (compatible endpoint) — — 420.8 ms
ai-gateway (compatible) +15.5 ms +6.0 ms 426.0 ms
LiteLLM (native /v1/messages) +152.5 ms +133.4 ms 582.4 ms
Portkey (native) +141.8 ms +158.8 ms 612.6 ms
Bifrost (native) +228.8 ms +227.9 ms 654.4 ms

Direct and ours use Anthropic’s OpenAI-compatible endpoint, and the others translate to the native one: the difference mixes gateway overhead with the difference between endpoints.

Gemini (gemini-3.5-flash-lite), concurrency 8, 160 requests and 8 rounds. Through the compatible endpoint:

Target p50 p90 TTFT p50 CPU ms/req memory
direct (compatible endpoint) 1,059.9 ms 1,577.3 ms 1,021.9 ms — —
ai-gateway (compatible) 1,038.4 ms 1,562.5 ms 1,009.0 ms 2.34 18 MB
LiteLLM (native) 941.4 ms 1,160.2 ms 910.9 ms 16.73 1,544 MB
Bifrost (native) 926.1 ms 1,159.5 ms 890.2 ms 4.61 172 MB

The gap came from HTTP/2 toward Google, not from the endpoint (the finding). With automatic http_version (HTTP/1.1 for Google):

Target p50 p90 TTFT p50 p50 overhead CPU ms/req memory
direct HTTP/1.1 926.3 ms 1,151.3 ms 889.3 ms — — —
ai-gateway (native, HTTP/1.1) 933.7 ms 1,193.9 ms 899.3 ms +7.4 ms 3.14 20 MB
LiteLLM 1.104.5 962.2 ms 1,204.4 ms 935.9 ms +36.0 ms 18.80 1,530 MB
Bifrost 2.3.2 959.4 ms 1,175.2 ms 923.6 ms +33.1 ms 5.71 156 MB

Bedrock: only this gateway and direct were measured. Running LiteLLM in a container would have required putting a broadly scoped AWS credential into it, which we did not do.

The single-target method, with the other gateways added as targets:

{"targets": [
{"name": "direct", "base_url": "http://127.0.0.1:18096/v1", "model": "m@300ms,20ms", "key_env": "BENCH_NONE", "container": "mock"},
{"name": "ai-gateway", "base_url": "http://127.0.0.1:18080/v1", "model": "bench-real", "key_env": "GATEWAY_KEY", "container": "gateway"},
{"name": "bifrost", "base_url": "http://127.0.0.1:18401/v1", "model": "openai/m@300ms,20ms", "key_env": "BIFROST_VK", "header": "x-bf-vk", "container": "bifrost"},
{"name": "portkey", "base_url": "http://127.0.0.1:18402/v1", "model": "m@300ms,20ms", "key_env": "DUMMY",
"headers": {"x-portkey-provider": "openai", "x-portkey-custom-host": "http://localhost:8000/v1"}, "container": "portkey"}],
"options": {"requests": 4096, "concurrency": 512, "rounds": 2, "warmup": 16, "stream": true,
"max_tokens": 16, "prompt": "Name three colors.", "baseline": "direct"}}

Bifrost 2.3.2: the image’s entrypoint script loops on arguments it does not recognize. Configure it through APP_PORT and APP_HOST, with no arguments.

Real OpenAI, Anthropic and Gemini with all gateways side by side in alternating rounds, and LiteLLM on Bedrock with a Bedrock-only IAM credential.

m7gtwcontact@m7gtw.com