Skip to content

Reverse Proxy & TLS ​

LLM Proxy listens on plain HTTP and relies on a reverse proxy in front of it for TLS termination.

What the app expects ​

  • TLS termination: the server starts without certificate options, so nginx, Caddy, Traefik, Cloudflare Tunnel, or another reverse proxy handles HTTPS.

  • Forwarded headers: only peers listed in TRUSTED_PROXIES may set X-Forwarded-For or X-Real-IP. The default includes RFC1918, loopback, and link-local ranges:

    10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,127.0.0.0/8,169.254.0.0/16,::1/128,fc00::/7,fe80::/10

    Client IP resolution walks X-Forwarded-For from right to left and picks the first hop outside the trusted ranges (up to 50 hops). X-Real-IP is used only when X-Forwarded-For is absent. Spoofed headers from untrusted peers cannot affect rate limiting, lockouts, or audit attribution.

    TRUSTED_PROXIES replaces the default list

    Setting TRUSTED_PROXIES drops the built-in ranges, so always include your local and Docker networks. Setting it to an empty value trusts no proxies and falls back to the TCP peer address. Invalid CIDRs cause startup to fail.

  • HTTP/1.1 to the app (terminate HTTP/2 at the reverse proxy): pass through WebSocket upgrades on /v1/responses and /v1/realtime, and disable buffering for SSE streaming.

  • Keep-alive: UVICORN_TIMEOUT_KEEPALIVE defaults to 600 seconds.

Cloudflare and other impatient CDNs ​

Cloudflare's free and pro plans abort proxied requests that stay silent for roughly 100 seconds (error 524). Long reasoning requests can exceed that. The proxy mitigates this in two ways, both hot-reloadable under Settings → Advanced → Response Keepalive:

SituationMechanism
Non-streaming request runs longer than grace_seconds (default 60 s)Sends 200 application/json immediately and writes a single space byte every interval_seconds (default 15 s) until the real body is ready
Streaming request with upstream silenceSends SSE comment frames (: keep-alive) at each interval; SSE clients ignore comments

Tradeoffs to keep in mind:

  • Once heartbeat mode starts, the HTTP status is already committed to 200. Any later failure is sent as 200 with an error JSON body, so clients that check only the status code will treat it as success. Inner response headers (including some usage headers) are also lost.
  • The audio/speech endpoint is excluded because its response is binary.
  • If the client or CDN disconnects first, the proxy cancels the upstream call and logs the request as 499.

::: note Keepalive defaults With nothing saved, the runtime defaults are enabled, 60 s grace, 15 s interval. The Settings form displays those same defaults, and saving the section applies what the form shows. :::

Example: nginx ​

nginx
server {
    listen 443 ssl;
    server_name llm.example.com;

    ssl_certificate     /etc/letsencrypt/live/llm.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/llm.example.com/privkey.pem;

    client_max_body_size 64m;   # keep in sync with max_request_body_size_bytes

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_http_version 1.1;

        proxy_set_header Host              $host;
        proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        # Streaming: no buffering, long read/send timeouts
        proxy_buffering off;
        proxy_read_timeout 600s;
        proxy_send_timeout 600s;

        # WebSockets (/v1/responses, /v1/realtime)
        proxy_set_header Upgrade    $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

Set TRUSTED_PROXIES to the network the reverse proxy connects from (for example, 127.0.0.1/32 for the snippet above). Otherwise all clients appear as the proxy's IP and share one rate-limit bucket.

Security headers ​

The app sets these headers on every response:

  • X-Content-Type-Options: nosniff
  • X-Frame-Options: DENY
  • X-XSS-Protection: 1; mode=block
  • Referrer-Policy: strict-origin-when-cross-origin
  • Permissions-Policy: geolocation=(), microphone=(), camera=()
  • Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; font-src 'self' data:; connect-src 'self'; frame-ancestors 'none'
  • Strict-Transport-Security: max-age=31536000; includeSubDomains when hsts_enabled is on (default true; toggle in Server Settings, and disable only for local HTTP development)

You do not need to duplicate these headers at the reverse proxy. Adding an HTTP-to-HTTPS redirect at the edge is still recommended.

CORS ​

CORS is needed only when the admin UI is served from a different origin than the API. Allowed origins live in Settings → Advanced → CORS Origins and hot-reload on save; an empty list disables CORS.

Preflight responses dynamically echo the headers requested by the client (validated as HTTP field names, up to 64 headers) for origins on the allowlist. SDKs can send x-api-key, anthropic-beta, x-stainless-*, or provider identity headers without failing preflight.

CORS runs after auth, body-size, and rate-limit checks

Requests rejected for authentication, body size, or rate limits return before CORS headers are added. Browsers report a generic CORS error in those cases instead of the underlying 401, 413, or 429. Check the proxy logs or test with curl when debugging cross-origin setups.

Request body size ​

max_request_body_size_bytes defaults to 64 MiB, which accommodates multimodal and batch payloads (base64 images, audio, and PDFs) while capping memory per request. Requests with a Content-Length header are checked up front; chunked or HTTP/2 bodies without a declared length are counted as they stream and dropped as soon as they exceed the limit. Configure this in Server Settings and keep the reverse proxy's body limit at or above the same value.

MIT licensed