AI Infra Runs on Streams
Look at a modern internal AI platform from the outside and it resembles standard web plumbing: a client sends an HTTP POST request and gets text back. In reality, production AI inference behaves nothing like a traditional request-response REST API. Because LLM generations can run for over a minute—and GPUs are expensive, preemptible resources—the entire stack is built around Server-Sent Events (SSE) streaming.
[Claude Code / Web UI] ──(SSE Stream) ──▶ [LiteLLM Gateway] ──▶
(Client / Harness) (Router / Proxy)
──(SSE Stream)──▶ [Global Spot GPUs + SGLang]
(GLM / Qwen / Clef)
Decoupling the gateway from the GPU runtime via a standard streaming contract is what lets teams blend frontier cloud APIs with cheap, globally hunted spot GPUs without breaking developer workflows.
Client to Gateway: How Claude Code & Web UIs Talk to LiteLLM
Whether a user is typing into a browser chat interface or running an autonomous coding harness like Claude Code, every turn begins with an HTTP POST (typically to /v1/chat/completions or Anthropic's /v1/messages) with "stream": true.
Instead of holding the socket silent until generation finishes, the server immediately responds with Content-Type: text/event-stream and leaves the TCP connection open. As the model samples tokens one by one, tiny data: {...} chunks drip back to the client in real time.
This streaming contract solves three operational problems:
- Surviving proxy timeouts. Load balancers and corporate proxies drop idle connections after 30–60 seconds. A steady trickle of tokens acts as a continuous heartbeat, keeping long agentic sessions alive.
- Instant feedback and agentic loops. A web UI renders text word-by-word instead of freezing on a spinner, while Claude Code parses partial tool calls on the fly and immediately executes local commands.
- Immediate cancellation. If a user hits stop or closes a tab, the dropped TCP socket signals the upstream stack to abort generation and free GPU VRAM right away.
LiteLLM sits in the middle of this pipe on stable, always-on CPU infrastructure. To clients, it looks like a single unified API. Under the hood, it translates API dialects in real time (such as converting Anthropic-formatted streams for Claude Code into OpenAI-formatted streams for self-hosted models), captures token usage from the final stream chunk for cost metering, and handles retries if a spot node disappears mid-stream.
Gateway to Metal: Talking to Any SSE-Compatible Backend
Because LiteLLM acts purely as a protocol-translating proxy, it does not care what generates the tokens or where that hardware lives. As long as a backend exposes an HTTP endpoint yielding OpenAI-compatible SSE chunks, LiteLLM can route traffic to it — including across a global pool of preemptible spot GPUs (such as NVIDIA H200 or RTX PRO 6000 instances).
That standard SSE boundary lets infrastructure teams mix and match specialized inference runtimes on the backend:
- SGLang – Built for high-throughput serving on datacenter GPUs, SGLang runs directly on the GPU nodes and exposes an OpenAI-compatible streaming server. Its signature optimization, RadixAttention, stores KV caches in a radix tree so multiple concurrent streams sharing long system prompts or codebases reuse cached prefixes without recomputing them.
- vLLM – Uses PagedAttention to manage GPU VRAM efficiently and supports continuous batching across dozens of simultaneous user streams. Because it speaks the same OpenAI-compatible SSE format (and Anthropic's Messages API), LiteLLM can load-balance across SGLang and vLLM clusters interchangeably.
- FastAPI + PyTorch – Raw PyTorch is a tensor math library, not a web server. When running a custom fine-tune or experimental architecture not yet supported by SGLang or vLLM, wrapping the PyTorch generation loop in a lightweight Python FastAPI
StreamingResponsethat yields standard SSE JSON chunks lets LiteLLM route to it like any major provider. - llama.cpp & Ollama – Built for lightweight deployments, CPU offloading, and quantized GGUF weights, both expose OpenAI-compatible
/v1/chat/completionsstreaming endpoints—making them drop-in targets for local developer fallbacks or smaller edge nodes.
The Architectural Payoff
Standardizing on SSE streams through a central gateway separates developer experience from compute volatility. Coding harnesses and web chat apps get a single, reliable endpoint, while platform teams stay free to hunt for cheap spot GPUs anywhere in the world, swap inference engines from vLLM to SGLang, or route between self-hosted open models (like Qwen, GLM, or Clef) and metered frontier APIs behind the scenes.