Skip to content

feat(ai): AI Gateway transport over the Cloudflare AI binding - #7901

Merged
badlogic merged 1 commit into
earendil-works:mainfrom
Maximo-Guk:maximo/ai-gateway-transport-over-ai-binding
Aug 11, 2026
Merged

feat(ai): AI Gateway transport over the Cloudflare AI binding#7901
badlogic merged 1 commit into
earendil-works:mainfrom
Maximo-Guk:maximo/ai-gateway-transport-over-ai-binding

Conversation

@Maximo-Guk

@Maximo-Guk Maximo-Guk commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

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-authorization API token.

Claude Fable was used during implementation of this PR

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>
@Maximo-Guk Maximo-Guk changed the title #7838 feat(ai): AI Gateway transport over the Cloudflare AI binding feat(ai): AI Gateway transport over the Cloudflare AI binding Aug 10, 2026
@badlogic
badlogic merged commit 2300290 into earendil-works:main Aug 11, 2026
1 check passed
@badlogic

Copy link
Copy Markdown
Collaborator

cheers

@Maximo-Guk
Maximo-Guk deleted the maximo/ai-gateway-transport-over-ai-binding branch August 11, 2026 14:29
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.

2 participants