-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Create 2025-03-20-websockets.mdx #21003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
13e2556
Create 2025-03-20-websockets.mdx
kathayl 4b6de0a
Update 2025-03-20-websockets.mdx
kathayl 3e48338
Apply suggestions from code review
kodster28 3883831
Update src/content/changelog/ai-gateway/2025-03-20-websockets.mdx
kathayl 2fa071b
Update 2025-03-20-websockets.mdx
kathayl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/content/changelog/ai-gateway/2025-03-20-websockets.mdx
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| --- | ||
| title: AI Gateway launches Realtime WebSockets API | ||
| description: AI Gateway now supports end-to-end, client-to-provider WebSockets | ||
| date: 2025-03-21T09:00:00Z | ||
| --- | ||
| We are excited to announce that [AI Gateway](/ai-gateway/) now supports real-time AI interactions with the new [Realtime WebSockets API](/ai-gateway/configuration/websockets-api/realtime-api/). | ||
|
|
||
| This new capability allows developers to establish persistent, low-latency connections between their applications and AI models, enabling natural, real-time conversational AI experiences, including speech-to-speech interactions. | ||
|
|
||
| The Realtime WebSockets API works with the [OpenAI Realtime API](https://platform.openai.com/docs/guides/realtime#connect-with-websockets), [Google Gemini Live API](https://ai.google.dev/gemini-api/docs/multimodal-live), and supports real-time text and speech interactions with models from [Cartesia](https://docs.cartesia.ai/api-reference/tts/tts), and [ElevenLabs](https://elevenlabs.io/docs/conversational-ai/api-reference/conversational-ai/websocket). | ||
|
|
||
| Here's how you can connect AI Gateway to [OpenAI's Realtime API](https://platform.openai.com/docs/guides/realtime#connect-with-websockets) using WebSockets: | ||
| ```javascript title="OpenAI Realtime API example" | ||
| import WebSocket from "ws"; | ||
|
|
||
| const url = | ||
| "wss://gateway.ai.cloudflare.com/v1/<account_id>/<gateway>/openai?model=gpt-4o-realtime-preview-2024-12-17"; | ||
| const ws = new WebSocket(url, { | ||
| headers: { | ||
| "cf-aig-authorization": process.env.CLOUDFLARE_API_KEY, | ||
| Authorization: "Bearer " + process.env.OPENAI_API_KEY, | ||
| "OpenAI-Beta": "realtime=v1", | ||
| }, | ||
| }); | ||
|
|
||
| ws.on("open", () => console.log("Connected to server.")); | ||
| ws.on("message", (message) => console.log(JSON.parse(message.toString()))); | ||
|
|
||
| ws.send( | ||
| JSON.stringify({ | ||
| type: "response.create", | ||
| response: { modalities: ["text"], instructions: "Tell me a joke" }, | ||
| }), | ||
| ); | ||
| ``` | ||
|
|
||
| Get started by checking out the [Realtime WebSockets API](/ai-gateway/configuration/websockets-api/realtime-api/) documentation. | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.