feat(ai): AI Gateway transport over the Cloudflare AI binding - #7901
Merged
badlogic merged 1 commit intoAug 11, 2026
Merged
Conversation
Add createGatewayBindingFetch: a FetchFunction factory that intercepts requests bound for an AI Gateway HTTPS endpoint and re-issues them through the Workers AI binding's universal endpoint (env.AI.gateway(id).run()). Binding calls are pre-authenticated in-account, so Workers running inside the gateway's account need no cf-aig-authorization API token. The shim is transport-only: it composes with the existing gateway passthrough base URLs and every API implementation that honors StreamOptions.fetch, preserving each provider's native wire format (verified: workers-ai v1/chat/completions OpenAI-compat SSE streams incrementally; anthropic v1/messages and openai responses route end-to-end; cf-aig-log-id is present and readable via gateway getLog). Binding types are structural, so no @cloudflare/workers-types dependency and no impact on browser bundling. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Collaborator
|
cheers |
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.
What do you want to change?
Add Cloudflare Workers AI Gateway transport over the AI binding
#7838
https://blog.cloudflare.com/workers-ai-gateway-unification/
https://developers.cloudflare.com/ai-gateway/usage/worker-binding-methods/#envairun
See cloudflare/cloudflare-os#123 which uses a vendored implementation of this approach
Why?
Pi apps running inside a Cloudflare Worker currently have to provision and store a Cloudflare API token purely as transport auth for gateway-routed inference. With this fetch helper, workers-ai / anthropic / openai requests through AI Gateway binding need no token by using capabilities granted to the worker, and it lowers latency for AI requests.
How?
Add createGatewayBindingFetch: a FetchFunction factory that intercepts requests bound for an AI Gateway HTTPS endpoint and re-issues them through the Workers AI binding's universal endpoint (env.AI.gateway(id).run()). Binding calls are pre-authenticated in-account, so Workers running inside the gateway's account need no
cf-aig-authorizationAPI token.Claude Fable was used during implementation of this PR