CORS for browser applications
Last updated: 2026-11-23T17:06:47-03:00 (UTC-3)
A web application served from another origin (for example https://app.example.com) can call the gateway’s inference API from the browser, typically with a short-lived JWT or a per-user key. Browsers allow that only when the server answers with CORS headers. server.cors lists the origins whose pages may read the answers. It is off by default.
How to enable it
Section titled “How to enable it”server: cors: allowed_origins: [https://app.example.com, http://localhost:5173] allowed_headers: [] # empty: the built-in list below max_age: 10m allow_credentials: false| Parameter | Default | Accepted values |
|---|---|---|
server.cors.allowed_origins |
[]: CORS off |
Up to 100 exact origins (https://host or http://host, with an optional port, no path, query, wildcard or trailing slash), or the single entry "*" |
server.cors.allowed_headers |
[]: the built-in list |
Up to 100 request header names, or prefixes ending in -* such as X-Stainless-*; a non-empty list replaces the built-in one |
server.cors.max_age |
10m |
0s to 24h; how long a browser may reuse a preflight answer (browsers cap it lower) |
server.cors.allow_credentials |
false |
true adds Access-Control-Allow-Credentials: true for listed origins; refused together with "*" |
The built-in request headers are Authorization, Content-Type, X-Request-Id, Traceparent, Idempotency-Key, X-Gateway-End-User, X-Gateway-Session-Id, X-Gateway-Feedback-Key, X-Gateway-Tags, X-Gateway-Cache, X-Gateway-Timeout-Ms, X-Api-Key, Anthropic-Version, Anthropic-Beta, Anthropic-Dangerous-Direct-Browser-Access, X-Goog-Api-Key, X-Goog-Api-Client, Openai-Beta, Openai-Organization, Openai-Project and every X-Stainless-* header: what the official OpenAI, Anthropic and Google SDKs send from a browser. The block is read at startup; restart each replica to change it.
What the gateway does
Section titled “What the gateway does”Where to read it. Settings & sources → Infrastructure → Inference HTTP shows the allowed origins, the allowed headers, the preflight cache and whether credentials are allowed (infrastructure.inference_http.cors in GET /api/v1/admin/config), read-only.
Only the inference API. CORS applies to /v1/* and the native Gemini /v1beta/*. The console, the admin API (/api/*), the public documentation, health and metrics never send CORS headers, whatever the configuration: the console keeps its same-origin session, CSRF token and content security policy.
Preflight. A browser sends OPTIONS with Origin and Access-Control-Request-Method before a cross-origin request with a key. The gateway answers it before authentication (a preflight carries no key) and never forwards it:
OPTIONS /v1/chat/completions HTTP/1.1Origin: https://app.example.comAccess-Control-Request-Method: POSTAccess-Control-Request-Headers: authorization, content-type
HTTP/1.1 204 No ContentAccess-Control-Allow-Origin: https://app.example.comAccess-Control-Allow-Methods: GET, POST, DELETEAccess-Control-Allow-Headers: authorization, content-typeAccess-Control-Max-Age: 600Vary: Origin, Access-Control-Request-Method, Access-Control-Request-HeadersAccess-Control-Allow-Headers repeats the headers the browser asked for, once all of them are allowed (a prefix entry cannot be listed as such). A preflight from an origin that is not listed, for a method other than GET, POST or DELETE, or asking for a header that is not allowed, gets 403 cors_preflight_refused without CORS headers, and the browser does not send the request.
Answers. Every answer to a listed origin, errors included, carries Access-Control-Allow-Origin with that origin (or *), Vary: Origin, and Access-Control-Expose-Headers so the page can read X-Request-Id, Traceparent, Retry-After, the X-Gateway-* headers and the opt-in response headers. An answer to an origin that is not listed has no CORS headers, so its page cannot read it.
CORS grants nothing. It only tells browsers which pages may read an answer. Every request still needs its key or token, with its models, budgets and team policy; a client outside a browser ignores CORS entirely. Do not treat an allowed origin as an access rule.
Wildcard. allowed_origins: ["*"] answers Access-Control-Allow-Origin: * to any origin, without Vary: Origin and without credentials. Browsers refuse * together with credentials, so the gateway refuses that configuration. Keys sent by a page are visible to its users; prefer short-lived tokens for browser applications.
Inspect it
Section titled “Inspect it”Settings & sources → Infrastructure → Inference HTTP and GET /api/v1/admin/config (infrastructure.inference_http.cors) show whether CORS is on, the allowed origins and headers, the preflight cache time and the credentials setting.
Upgrade
Section titled “Upgrade”Nothing changes until an origin is listed. Before rolling back to an older binary, remove server.cors, because its strict YAML refuses it.
See also
Section titled “See also”- JWT inference: short-lived tokens for browser applications.
- Response headers: what an answer can carry.
- Security.