WebSocket support in AI Binding#4754
Merged
danlapid merged 3 commits intocloudflare:mainfrom Aug 25, 2025
Merged
Conversation
Workers AI is extending its AI binding to allow users to establish a WebSocket connection with supported models, enabling real-time, bi-directional inference requests. The code for ai.run() method is refactored to have separate flows for generating a regular fetch call, a readable stream fetch and one for supporting websockets. There is a new AiOptions called "websocket", a boolean value that will help establish a connection to the model using the Upgrade header. The WebSocket will be returned to the calling code as-is and the user can add event listeners to send and receive inference requests. Tests are trivial as they currently only check if the headers were parsed correctly along with the body.
c4a9339 to
a2092dc
Compare
84d7609 to
50408e3
Compare
G4brym
approved these changes
Aug 12, 2025
Contributor
|
LGTM |
JoaquinGimenez1
approved these changes
Aug 13, 2025
danlapid
approved these changes
Aug 25, 2025
vicb
added a commit
to cloudflare/workers-sdk
that referenced
this pull request
Aug 29, 2025
vicb
added a commit
to cloudflare/workers-sdk
that referenced
this pull request
Aug 29, 2025
vicb
added a commit
to cloudflare/workers-sdk
that referenced
this pull request
Sep 1, 2025
* Bump the workerd-and-workers-types group with 2 updates Bumps the workerd-and-workers-types group with 2 updates: [workerd](https://github.com/cloudflare/workerd) and [@cloudflare/workers-types](https://github.com/cloudflare/workerd). Updates `workerd` from 1.20250823.0 to 1.20250829.0 - [Release notes](https://github.com/cloudflare/workerd/releases) - [Changelog](https://github.com/cloudflare/workerd/blob/main/Dockerfile.release) - [Commits](cloudflare/workerd@v1.20250823.0...v1.20250829.0) Updates `@cloudflare/workers-types` from 4.20240614.0 to 4.20250829.0 - [Release notes](https://github.com/cloudflare/workerd/releases) - [Changelog](https://github.com/cloudflare/workerd/blob/main/Dockerfile.release) - [Commits](https://github.com/cloudflare/workerd/commits) --- updated-dependencies: - dependency-name: workerd dependency-version: 1.20250829.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: workerd-and-workers-types - dependency-name: "@cloudflare/workers-types" dependency-version: 4.20250829.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: workerd-and-workers-types ... Signed-off-by: dependabot[bot] <support@github.com> * chore: update dependencies of "miniflare" package The following dependency versions have been updated: | Dependency | From | To | | ---------- | ------------ | ------------ | | workerd | 1.20250823.0 | 1.20250829.0 | * fixup! sync cloudflare/workerd#4754 --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Wrangler automated PR updater <wrangler@cloudflare.com> Co-authored-by: Victor Berchet <victor@suumit.com>
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.
Workers AI is extending its AI binding to allow users to establish a WebSocket connection with supported models, enabling real-time, bi-directional inference requests.
The code for ai.run() method is refactored to have separate flows for generating a regular fetch call, a readable stream fetch and one for supporting websockets.
There is a new AiOptions called "websocket", a boolean value that will help establish a connection to the model using the Upgrade header.
The WebSocket will be returned to the calling code as-is and the user can add event listeners to send and receive inference requests.
Tests are trivial as they currently only check if the headers were parsed correctly along with the body.