-
Notifications
You must be signed in to change notification settings - Fork 10k
[AIG]websockets new path #22038
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
[AIG]websockets new path #22038
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2abb5f0
websockets new path
daisyfaithauma 1fdc725
invalid links
daisyfaithauma ba6f166
invalid links
daisyfaithauma 6ae01ad
Update index.mdx
daisyfaithauma fb8718b
Merge branch 'production' into websockets-new-path
pedrosousa 2445abf
Update src/content/docs/ai-gateway/websockets-api/index.mdx
daisyfaithauma 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
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
30 changes: 16 additions & 14 deletions
30
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 |
|---|---|---|
| @@ -1,37 +1,39 @@ | ||
| --- | ||
| title: AI Gateway launches Realtime WebSockets API | ||
| description: AI Gateway now supports end-to-end, client-to-provider WebSockets | ||
| 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/). | ||
|
|
||
| We are excited to announce that [AI Gateway](/ai-gateway/) now supports real-time AI interactions with the new [Realtime WebSockets API](/ai-gateway/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"; | ||
| "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", | ||
| }, | ||
| 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" }, | ||
| }), | ||
| 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. | ||
| Get started by checking out the [Realtime WebSockets API](/ai-gateway/websockets-api/realtime-api/) documentation. |
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
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
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
File renamed without changes.
File renamed without changes.
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.