Skip to content

Commit 107f012

Browse files
[AIG]websockets new path (#22038)
* websockets new path * invalid links * invalid links * Update index.mdx * Update src/content/docs/ai-gateway/websockets-api/index.mdx Co-authored-by: Pedro Sousa <[email protected]> --------- Co-authored-by: Pedro Sousa <[email protected]>
1 parent 0e8e4a8 commit 107f012

File tree

7 files changed

+33
-27
lines changed

7 files changed

+33
-27
lines changed

public/__redirects

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,10 @@
146146
/ai-gateway/integration/aig-workers-ai-binding/ /ai-gateway/integrations/aig-workers-ai-binding/ 301
147147
/ai-gateway/integration/ /ai-gateway/integrations/ 301
148148
/ai-gateway/providers/open-router/ /ai-gateway/providers/openrouter/ 301
149-
/ai-gateway/providers/universal/ /ai-gateway/universal/ 301
149+
/ai-gateway/configuration/websockets-api/ /ai-gateway/websockets-api/ 301
150+
/ai-gateway/configuration/websockets-api/non-realtime-api/ /ai-gateway/websockets-api/non-realtime-api/ 301
151+
/ai-gateway/configuration/websockets-api/realtime-api/ /ai-gateway/websockets-api/realtime-api/ 301
152+
150153

151154
# agents
152155
/agents/capabilities/mcp-server/ /agents/model-context-protocol/ 301
Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,39 @@
11
---
2-
title: AI Gateway launches Realtime WebSockets API
3-
description: AI Gateway now supports end-to-end, client-to-provider WebSockets
2+
title: AI Gateway launches Realtime WebSockets API
3+
description: AI Gateway now supports end-to-end, client-to-provider WebSockets
44
date: 2025-03-21T09:00:00Z
55
---
6-
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/).
6+
7+
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/).
78

89
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.
910

1011
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).
1112

1213
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:
14+
1315
```javascript title="OpenAI Realtime API example"
1416
import WebSocket from "ws";
1517

1618
const url =
17-
"wss://gateway.ai.cloudflare.com/v1/<account_id>/<gateway>/openai?model=gpt-4o-realtime-preview-2024-12-17";
19+
"wss://gateway.ai.cloudflare.com/v1/<account_id>/<gateway>/openai?model=gpt-4o-realtime-preview-2024-12-17";
1820
const ws = new WebSocket(url, {
19-
headers: {
20-
"cf-aig-authorization": process.env.CLOUDFLARE_API_KEY,
21-
Authorization: "Bearer " + process.env.OPENAI_API_KEY,
22-
"OpenAI-Beta": "realtime=v1",
23-
},
21+
headers: {
22+
"cf-aig-authorization": process.env.CLOUDFLARE_API_KEY,
23+
Authorization: "Bearer " + process.env.OPENAI_API_KEY,
24+
"OpenAI-Beta": "realtime=v1",
25+
},
2426
});
2527

2628
ws.on("open", () => console.log("Connected to server."));
2729
ws.on("message", (message) => console.log(JSON.parse(message.toString())));
2830

2931
ws.send(
30-
JSON.stringify({
31-
type: "response.create",
32-
response: { modalities: ["text"], instructions: "Tell me a joke" },
33-
}),
32+
JSON.stringify({
33+
type: "response.create",
34+
response: { modalities: ["text"], instructions: "Tell me a joke" },
35+
}),
3436
);
3537
```
3638

37-
Get started by checking out the [Realtime WebSockets API](/ai-gateway/configuration/websockets-api/realtime-api/) documentation.
39+
Get started by checking out the [Realtime WebSockets API](/ai-gateway/websockets-api/realtime-api/) documentation.

src/content/docs/ai-gateway/get-started.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ When setting up a new gateway, you can choose between an authenticated and unaut
3232

3333
Next, connect your AI provider to your gateway.
3434

35-
AI Gateway offers multiple endpoints for each Gateway you create - one endpoint per provider, and one Universal Endpoint. To use AI Gateway, you will need to create your own account with each provider and provide your API key. AI Gateway acts as a proxy for these requests, enabling observability, caching, and more.
35+
AI Gateway offers multiple endpoints for each Gateway you create - one endpoint per provider, and one Universal Endpoint. To use AI Gateway, you will need to create your own account with each provider and provide your API key. AI Gateway acts as a proxy for these requests, enabling observability, caching, and more.
3636

37-
Additionally, AI Gateway has a [WebSockets API](/ai-gateway/configuration/websockets-api/) which provides a single persistent connection, enabling continuous communication. This API supports all AI providers connected to AI Gateway, including those that do not natively support WebSockets.
37+
Additionally, AI Gateway has a [WebSockets API](/ai-gateway/websockets-api/) which provides a single persistent connection, enabling continuous communication. This API supports all AI providers connected to AI Gateway, including those that do not natively support WebSockets.
3838

3939
Below is a list of our supported model providers:
4040

src/content/docs/ai-gateway/universal.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ The above will send a request to Workers AI Inference API, if it fails it will p
3131

3232
## WebSockets API <Badge text="beta" variant="tip" size="small" />
3333

34-
The Universal Endpoint can also be accessed via a [WebSockets API](/ai-gateway/configuration/websockets-api/) which provides a single persistent connection, enabling continuous communication. This API supports all AI providers connected to AI Gateway, including those that do not natively support WebSockets.
34+
The Universal Endpoint can also be accessed via a [WebSockets API](/ai-gateway/websockets-api/) which provides a single persistent connection, enabling continuous communication. This API supports all AI providers connected to AI Gateway, including those that do not natively support WebSockets.
3535

3636
## WebSockets example
3737

src/content/docs/ai-gateway/configuration/websockets-api/index.mdx renamed to src/content/docs/ai-gateway/websockets-api/index.mdx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pcx_content_type: configuration
44
sidebar:
55
group:
66
badge: Beta
7+
order: 5
78
---
89

910
The AI Gateway WebSockets API provides a persistent connection for AI interactions, eliminating repeated handshakes and reducing latency. This API is divided into two categories:
@@ -20,16 +21,16 @@ WebSockets are long-lived TCP connections that enable bi-directional, real-time
2021
- **Reduced overhead**: Avoid overhead of repeated handshakes and TLS negotiations by maintaining a single, persistent connection.
2122
- **Provider compatibility**: Works with all AI providers in AI Gateway. Even if your chosen provider does not support WebSockets, Cloudflare handles it for you, managing the requests to your preferred AI provider.
2223

23-
## **Key differences**
24+
## Key differences
2425

25-
| Feature | Realtime APIs | Non-Realtime APIs |
26-
| :---------------------- | :------------------------------------------------------------------------------------------------------------------------------------ | :----------------------------------------------------------------------------------------------- |
27-
| **Purpose** | Enables real-time, multimodal AI interactions for providers that offer dedicated WebSocket endpoints. | Supports WebSocket-based AI interactions with providers that do not natively support WebSockets. |
28-
| **Use Case** | Streaming responses for voice, video, and live interactions. | Text-based queries and responses, such as LLM requests. |
29-
| **AI Provider Support** | [Limited to providers offering real-time WebSocket APIs.](/ai-gateway/configuration/websockets-api/realtime-api/#supported-providers) | [All AI providers in AI Gateway.](/ai-gateway/providers) |
30-
| **Streaming Support** | Providers natively support real-time data streaming. | AI Gateway handles streaming via WebSockets. |
26+
| Feature | Realtime APIs | Non-Realtime APIs |
27+
| :---------------------- | :---------------------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------- |
28+
| **Purpose** | Enables real-time, multimodal AI interactions for providers that offer dedicated WebSocket endpoints. | Supports WebSocket-based AI interactions with providers that do not natively support WebSockets. |
29+
| **Use Case** | Streaming responses for voice, video, and live interactions. | Text-based queries and responses, such as LLM requests. |
30+
| **AI Provider Support** | [Limited to providers offering real-time WebSocket APIs.](/ai-gateway/websockets-api/realtime-api/#supported-providers) | [All AI providers in AI Gateway.](/ai-gateway/providers/) |
31+
| **Streaming Support** | Providers natively support real-time data streaming. | AI Gateway handles streaming via WebSockets. |
3132

3233
For details on implementation, refer to the next sections:
3334

34-
- [Realtime WebSockets API](/ai-gateway/configuration/websockets-api/realtime-api/)
35-
- [Non-Realtime WebSockets API](/ai-gateway/configuration/websockets-api/non-realtime-api/)
35+
- [Realtime WebSockets API](/ai-gateway/websockets-api/realtime-api/)
36+
- [Non-Realtime WebSockets API](/ai-gateway/websockets-api/non-realtime-api/)
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)