Skip to content

Commit 824861d

Browse files
authored
fix(devserver): add x-bt-use-gateway to CORS allowed headers (#119)
The Braintrust Playground sends x-bt-use-gateway when gateway routing is enabled. The api-ts CORS config already allows it, but the Python devserver's ALLOWED_HEADERS list was missing it, causing browsers to block preflight requests to remote eval servers with a CORS error.
1 parent 8439874 commit 824861d

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

py/src/braintrust/devserver/cors.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"x-bt-project-id",
2424
"x-bt-stream-fmt",
2525
"x-bt-use-cache",
26+
"x-bt-use-gateway",
2627
"x-stainless-os",
2728
"x-stainless-lang",
2829
"x-stainless-package-version",

py/src/braintrust/devserver/test_server_integration.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,28 @@ def test_devserver_health_check(client):
8787
assert response.text == "Hello, world!"
8888

8989

90+
def test_cors_preflight_allows_gateway_header(client):
91+
"""Test that CORS preflight accepts x-bt-use-gateway header.
92+
93+
The Braintrust Playground sends this header when gateway routing is
94+
enabled. If it is missing from the devserver's allowed-headers list
95+
the browser blocks the actual request with a CORS error.
96+
"""
97+
response = client.options(
98+
"/eval",
99+
headers={
100+
"origin": "https://www.braintrust.dev",
101+
"access-control-request-method": "POST",
102+
"access-control-request-headers": "x-bt-use-gateway",
103+
},
104+
)
105+
assert response.status_code == 200
106+
allowed = response.headers.get("access-control-allow-headers", "")
107+
assert "x-bt-use-gateway" in allowed, (
108+
f"x-bt-use-gateway not found in access-control-allow-headers: {allowed}"
109+
)
110+
111+
90112
@pytest.mark.vcr
91113
def test_devserver_list_evaluators(client, api_key, org_name):
92114
"""Test listing evaluators endpoint."""

0 commit comments

Comments
 (0)