Forward gateway options as cf-aig-* headers from Ai.run()#6798
Open
JoaquinGimenez1 wants to merge 1 commit into
Open
Forward gateway options as cf-aig-* headers from Ai.run()#6798JoaquinGimenez1 wants to merge 1 commit into
JoaquinGimenez1 wants to merge 1 commit into
Conversation
`env.AI.run(model, inputs, { gateway })` previously sent the gateway
config only inside the JSON request body (`options.gateway`). AI Gateway
enforces these options via `cf-aig-*` request headers (as the REST API
and the Universal endpoint `env.AI.gateway(id).run()` already do), so
fields like `requestTimeoutMs` were silently ignored on the binding's
run path. Long-running calls never aborted, despite the timeout being
exposed in the TypeScript types.
Add a `gatewayOptionsToHeaders` helper that mirrors
`AiGateway.#getHeadersFromOptions` in aig-api.ts, and emit those headers
in `#generateFetch`. The mapping is placed after `extraHeaders` so the
typed `gateway` option takes precedence. `gateway.id` is intentionally
not emitted as a header; it continues to drive `/ai-gateway/run` routing
via the body. The change is purely additive: the body still carries
`options.gateway`, so existing behavior is unaffected.
Adds a regression test (full option set and requestTimeoutMs-only) that
asserts the cf-aig-* headers reach the upstream fetch.
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.
env.AI.run(model, inputs, { gateway })previously sent the gateway config only inside the JSON request body (options.gateway). AI Gateway enforces these options viacf-aig-*request headers (as the REST API and the Universal endpointenv.AI.gateway(id).run()already do), so fields likerequestTimeoutMswere silently ignored on the binding's run path. Long-running calls never aborted, despite the timeout being exposed in the TypeScript types.Add a
gatewayOptionsToHeadershelper that mirrorsAiGateway.#getHeadersFromOptionsin aig-api.ts, and emit those headers in#generateFetch. The mapping is placed afterextraHeadersso the typedgatewayoption takes precedence.gateway.idis intentionally not emitted as a header; it continues to drive/ai-gateway/runrouting via the body. The change is purely additive: the body still carriesoptions.gateway, so existing behavior is unaffected.Adds a regression test (full option set and requestTimeoutMs-only) that asserts the cf-aig-* headers reach the upstream fetch.