Repository navigation
server: --cors-origin for browser clients, and /v1/apply-template returns a chat request's rendered prompt - #3166
Merged
Merged
Conversation
ashhart
force-pushed
the
lead/cors-apply-template
branch
3 times, most recently
from
November 17, 2026 09:09
b0e8bc0 to
5da64d0
Compare
…it on its replies (#3111) --cors-origin ORIGIN is repeatable (64 at most), takes the exact http(s)://HOST[:PORT] form --allowed-origin takes, and admits that origin too. A preflight from a listed origin is answered before keys: 204 with Access-Control-Allow-Origin echoing it, the API's methods and request headers and a 600 s max age; another method or header gets 403, and an unlisted origin gets the origin 403 as before. The allowed request headers are authorization, x-api-key, content-type, anthropic-version, anthropic-beta and anthropic-dangerous-direct-browser-access, plus the x-stainless-* headers the OpenAI and Anthropic browser SDKs send, which the reply names lowercased after the fixed list. Every reply to a listed origin's request, key refusals and SSE streams included, carries Access-Control-Allow-Origin, and with the flag set replies carry Vary: Origin. No wildcard and no credentials mode; gated routes still need a key. Without the flag no reply changes.
…s to (#3111) POST /apply-template and /v1/apply-template take /tokenize's messages body (tools, reasoning_effort, chat_template_kwargs, add_generation_prompt) and reply {"prompt": TEXT}: the ids /tokenize would return, media expanded, decoded with their special tokens. Nothing reaches the engine. Both routes are in the inference key scope, like /tokenize and /detokenize.
ashhart
force-pushed
the
lead/cors-apply-template
branch
from
November 17, 2026 18:04
5da64d0 to
b76b221
Compare
ashhart
added a commit
that referenced
this pull request
Nov 17, 2026
ashhart
added a commit
that referenced
this pull request
Nov 17, 2026
ashhart
added a commit
that referenced
this pull request
Nov 17, 2026
ashhart
added a commit
that referenced
this pull request
Nov 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3111.
Two server additions for browser clients and template debugging:
--cors-origin ORIGIN(repeatable, off by default). Only a request origin that exactly matches a listed one is echoed back, withVary: Origin. There is no credentials mode. Preflights are answered only after the existing Host and Origin policy passes: 204 with noContent-Length, and an unlisted origin gets 403 with noAccess-Control-Allow-Origin. Allowed request headers:authorization,x-api-key,content-type,anthropic-version,anthropic-beta,anthropic-dangerous-direct-browser-access, and anyx-stainless-*header (letters, digits,-and_after the prefix), so the OpenAI and Anthropic browser SDKs pass preflight. An unknown header refuses the whole preflight./v1/apply-templatereturns the prompt text a chat request renders to, under the same auth as inference. It decodes the rendered token ids directly.SECURITY.mdanddocs/api.mddescribe both.Tests:
test-cors-template-host30, with 3 of the apply-template tests failing on main and the CORS tests not compiling there. The preflight tests cover listed and unlisted origins, SDK headers, unknown and malformed headers, and mixed case.test-server-cpu1346 pass, 7 skip;test-server-security35;test-http-limits-host30;test-goldenpasses.Served check pending (no GPU): with
--cors-origin https://ui.invalidand a key, a listed preflight gets 204 and an unlisted one gets 403;/v1/apply-templategets 401 without a key and 200 with one; one browser SSEfetchfrom the listed origin; and on a real checkpoint, tokenizing the returned prompt withadd_special_tokens: falsegives/tokenize's ids.