-
Notifications
You must be signed in to change notification settings - Fork 10k
Closed
Labels
content:editRequest for content editsRequest for content editsdocumentationDocumentation editsDocumentation editsproduct:ai-gatewayAI Gateway: https://developers.cloudflare.com/ai-gateway/AI Gateway: https://developers.cloudflare.com/ai-gateway/
Description
Existing documentation URL(s)
- https://developers.cloudflare.com/ai-gateway/chat-completion/
- https://developers.cloudflare.com/ai-gateway/chat-completion/#openai-sdk
What changes are you suggesting?
The OpenAI SDK example for the new AI Gateway OpenAI compatible endpoint have a base url of https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/compat/chat/completions. This results in a 500 error, because the OpenAI SDK automatically appends /chat/completions to baseURL.
The example should be changed to the following:
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "YOUR_PROVIDER_API_KEY", // Provider API key
baseURL:
"https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/compat", // <-- CHANGE HERE
});
const response = await client.chat.completions.create({
model: "google-ai-studio/gemini-2.0-flash",
messages: [{ role: "user", content: "What is Cloudflare?" }],
});
console.log(response.choices[0].message.content);A note should also be added to make sure people understand this difference.
Additional information
No response
Metadata
Metadata
Labels
content:editRequest for content editsRequest for content editsdocumentationDocumentation editsDocumentation editsproduct:ai-gatewayAI Gateway: https://developers.cloudflare.com/ai-gateway/AI Gateway: https://developers.cloudflare.com/ai-gateway/