Skip to content

Commit 2ec0e61

Browse files
committed
fix(ai-openrouter): match SSE content-type case-insensitively
Content-Type header values are case-insensitive per RFC 9110. OpenRouter today serves lowercase `text/event-stream` but a proxy on the path could return a different casing, which would make cost capture silently skip a real SSE response. Lowercase the header before the substring match. Picked up in CodeRabbit review of TanStack#469.
1 parent 77b70d3 commit 2ec0e61

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

packages/typescript/ai-openrouter/src/adapters/cost-capture.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,10 @@ export function createCostCaptureHook(
158158
): (res: Response, req: Request) => void {
159159
return (res, req) => {
160160
if (!isChatCompletionsRequest(req.url)) return
161-
const contentType = res.headers.get('content-type') ?? ''
161+
// Content-Type is case-insensitive per RFC 9110. OpenRouter today
162+
// serves lowercase `text/event-stream`, but a proxy on the path could
163+
// legitimately return a different casing — normalize before matching.
164+
const contentType = (res.headers.get('content-type') ?? '').toLowerCase()
162165
// Cost capture is only wired for streaming chat completions. Non-SSE
163166
// responses on `/chat/completions` (e.g. `structuredOutput()` which
164167
// calls `chat.send({ stream: false })`) never consume `costStore` —

0 commit comments

Comments
 (0)