Skip to content

Commit 68e13cc

Browse files
authored
Create 2025-06-02-aig-openai-compatible-endpoint.mdx
1 parent d6fd123 commit 68e13cc

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
title: AI Gateway adds OpenAI compatible endpoint
3+
description: AI Gateway has added OpenAI compatibiliy
4+
products:
5+
- ai-gateway
6+
date: 2025-06-02T12:00:00Z
7+
---
8+
Users can now use [AI Gateway](/ai-gateway/) [OpenAI Compatible endpoint](/ai-gateway/chat-completion/) to easily switch between providers, while keeping the exact same request and response formats. Launching now with the chat completions endpoint, with the embeddings endpoint coming up next.
9+
10+
To get started, simply use the OpenAI compatible chat completions endpoint URL with your own account id and gateway id and switch between providers by changing the `model` and `apiKey` parameters.
11+
12+
```bash title="OpenAI SDK Example"
13+
import OpenAI from "openai";
14+
const client = new OpenAI({
15+
apiKey: "YOUR_PROVIDER_API_KEY", // Provider API key
16+
baseURL:
17+
"https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/compat/chat/completions",
18+
});
19+
20+
const response = await client.chat.completions.create({
21+
model: "google-ai-studio/gemini-2.0-flash",
22+
messages: [{ role: "user", content: "What is Cloudflare?" }],
23+
});
24+
25+
console.log(response.choices[0].message.content);
26+
```
27+
28+
Additionally, the [OpenAI Compatible endpoint](/ai-gateway/chat-completion/) can be combined with our [Universal Endpoint](/ai-gateway/universal/) to add fallbacks across multiple providers. That means AI Gateway will return every response in the same standardized format, no extra parsing logic required!
29+
30+
Learn more in the [OpenAI Compatibility](/ai-gateway/chat-completion/) documentation.

0 commit comments

Comments
 (0)