Skip to content

WebSocket support in AI Binding#4754

Merged
danlapid merged 3 commits intocloudflare:mainfrom
thatsKevinJain:kevin/ai-websockets
Aug 25, 2025
Merged

WebSocket support in AI Binding#4754
danlapid merged 3 commits intocloudflare:mainfrom
thatsKevinJain:kevin/ai-websockets

Conversation

@thatsKevinJain
Copy link
Copy Markdown
Contributor

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.

@thatsKevinJain thatsKevinJain requested a review from a team as a code owner August 11, 2025 23:15
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.
@JoaquinGimenez1
Copy link
Copy Markdown
Contributor

LGTM

@danlapid danlapid merged commit 4331807 into cloudflare:main Aug 25, 2025
16 of 17 checks passed
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>
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.

4 participants