Skip to content

fix(ai-gateway): relay Retry-After, rate-limit, and request-id headers - #4113

Open
MauryaQbit wants to merge 1 commit into
fosrl:mainfrom
MauryaQbit:fix/4110-ai-gateway-relay-headers
Open

MauryaQbit wants to merge 1 commit into
fosrl:mainfrom
MauryaQbit:fix/4110-ai-gateway-relay-headers

Conversation

@MauryaQbit

@MauryaQbit MauryaQbit commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Community Contribution License Agreement

By creating this pull request, I grant the project maintainers an unlimited,
perpetual license to use, modify, and redistribute these contributions under any terms they
choose, including both the AGPLv3 and the Fossorial Commercial license terms. I
represent that I have the right to grant this license for all contributed content.

AI Disclosure

This PR was prepared with the help of an AI assistant (Claude), reviewed against the current main code, and the change was type-checked and smoke-tested.

Description

Fixes #4110.

streamAiGatewayResponse previously forwarded only the upstream status and Content-Type, dropping Retry-After, x-ratelimit-* / anthropic-ratelimit-*, and x-request-id / request-id. SDK clients therefore could not honour provider backoff hints or correlate requests by id.

This change relays a small allowlist of those headers (retry-after, x-request-id, request-id, and anything containing ratelimit) from the upstream response to the client on both the streaming and buffered paths. content-length, content-encoding, set-cookie, transfer-encoding, and all other headers remain unforwarded since fetch has already decoded the body.

How to test?

  • Run npx tsc --noEmit.
  • Drive streamAiGatewayResponse with a mocked upstream 429 response carrying Retry-After, x-ratelimit-*, and x-request-id headers; verify those headers are forwarded and transport/encoding headers are not.

@oschwartz10612

Copy link
Copy Markdown
Member

Hi! Thanks for the PR! Please make sure to use the PR template and include the CLA as required and we can then test and merge.

streamAiGatewayResponse previously forwarded only the upstream status and Content-Type, dropping Retry-After, x-ratelimit/anthropic-ratelimit and x-request-id/request-id. SDK clients therefore could not honour provider backoff hints or correlate requests by id.

Relay a small allowlist of those headers (retry-after, x-request-id, request-id, and anything containing ratelimit) from the upstream response to the client on both streaming and buffered paths. Leave content-length, content-encoding, set-cookie, transfer-encoding and all other headers unforwarded since fetch already decoded the body.

Fixes fosrl#4110.
@MauryaQbit
MauryaQbit force-pushed the fix/4110-ai-gateway-relay-headers branch from d4b9880 to 1aa32bb Compare November 16, 2026 19:05
@MauryaQbit

Copy link
Copy Markdown
Contributor Author

@oschwartz10612 Thanks I've updated the PR to follow the template and added the CLA statement + AI disclosure. Also ran prettier and tsc, both clean. I smoke-tested the change with a mocked upstream 429 carrying Retry-After, x-ratelimit-*, and x-request-id — those get forwarded and the transport/encoding headers don't.

The full test suite shows 4 failures on my end, but they're pre-existing and unrelated (migrations/DB schema setup stuff). Let me know if you'd like anything else adjusted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AI gateway drops upstream Retry-After / x-ratelimit-* / x-request-id headers on responses

2 participants