Repository navigation
fix(ai-gateway): relay Retry-After, rate-limit, and request-id headers - #4113
Open
MauryaQbit wants to merge 1 commit into
Open
MauryaQbit wants to merge 1 commit into
MauryaQbit wants to merge 1 commit into
Conversation
MauryaQbit
requested review from
miloschwartz and
oschwartz10612
as code owners
November 15, 2026 04:24
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
force-pushed
the
fix/4110-ai-gateway-relay-headers
branch
from
November 16, 2026 19:05
d4b9880 to
1aa32bb
Compare
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. |
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.
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.
streamAiGatewayResponsepreviously forwarded only the upstream status andContent-Type, droppingRetry-After,x-ratelimit-*/anthropic-ratelimit-*, andx-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 containingratelimit) 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?
npx tsc --noEmit.streamAiGatewayResponsewith a mocked upstream 429 response carryingRetry-After,x-ratelimit-*, andx-request-idheaders; verify those headers are forwarded and transport/encoding headers are not.