← Cloudflare AI Gateway / ai-gateway / usage / providers
OpenAI
OpenAI ↗ помогает создавать приложения на основе моделей GPT.
Конечная точка
Базовый URL
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openaiПри отправке запросов к OpenAI замените https://api.openai.com/v1 в URL, который вы сейчас используете с https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai.
Эндпойнт Chat Completions
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai/chat/completions
Эндпойнт Responses
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai/responses
Примеры
OpenAI SDK
С ключом в запросе
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "YOUR_OPENAI_API_KEY",
defaultHeaders: {
"cf-aig-authorization": `Bearer {cf_api_token}`,
},
baseURL:
"https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai",
});
const response = await client.chat.completions.create({
model: "gpt-4o-mini",
messages: [{ role: "user", content: "Hello, world!" }],
});import OpenAI from "openai";
const client = new OpenAI({
apiKey: "YOUR_OPENAI_API_KEY",
baseURL:
"https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai",
});
const response = await client.chat.completions.create({
model: "gpt-4o-mini",
messages: [{ role: "user", content: "Hello, world!" }],
});С сохранёнными ключами (BYOK) / Unified Billing
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "{cf_api_token}",
baseURL:
"https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai",
});
// Ensure your OpenAI API key is stored with BYOK
// or Unified Billing has credits
const response = await client.chat.completions.create({
model: "gpt-4o-mini",
messages: [{ role: "user", content: "Hello, world!" }],
});cURL
Responses API с API-ключом в запросе
curl -X POST https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai/responses \
--header 'Authorization: Bearer {OPENAI_API_KEY}' \
--header 'cf-aig-authorization: Bearer {CF_AIG_TOKEN}' \
--header 'Content-Type: application/json' \
--data '{
"model": "gpt-5.1",
"input": [
{
"role": "user",
"content": "Write a one-sentence bedtime story about a unicorn."
}
]
}'curl -X POST https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai/responses \
--header 'Authorization: Bearer {OPENAI_API_KEY}' \
--header 'Content-Type: application/json' \
--data '{
"model": "gpt-5.1",
"input": [
{
"role": "user",
"content": "Write a one-sentence bedtime story about a unicorn."
}
]
}'Chat Completions с API-ключом в запросе
curl -X POST https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai/chat/completions \
--header 'Authorization: Bearer {OPENAI_API_KEY}' \
--header 'cf-aig-authorization: Bearer {CF_AIG_TOKEN}' \
--header 'Content-Type: application/json' \
--data '{
"model": "gpt-4o-mini",
"messages": [
{
"role": "user",
"content": "What is Cloudflare?"
}
]
}'curl -X POST https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai/chat/completions \
--header 'Authorization: Bearer {OPENAI_API_KEY}' \
--header 'Content-Type: application/json' \
--data '{
"model": "gpt-4o-mini",
"messages": [
{
"role": "user",
"content": "What is Cloudflare?"
}
]
}'Responses API с сохранёнными ключами (BYOK) / Unified Billing
curl -X POST https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai/responses \
--header 'cf-aig-authorization: Bearer {CF_AIG_TOKEN}' \
--header 'Content-Type: application/json' \
--data '{
"model": "gpt-5.1",
"input": [
{
"role": "user",
"content": "Write a one-sentence bedtime story about a unicorn."
}
]
}'Chat Completions с сохранёнными ключами (BYOK) / Unified Billing
curl -X POST https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai/chat/completions \
--header 'cf-aig-authorization: Bearer {CF_AIG_TOKEN}' \
--header 'Content-Type: application/json' \
--data '{
"model": "gpt-4o-mini",
"messages": [
{
"role": "user",
"content": "What is Cloudflare?"
}
]
}'