OpenRouter ↗ は、大規模言語モデル(LLM)へアクセスして使うための統一インターフェースを提供するプラットフォームです。
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openrouterOpenRouter ↗ へリクエストを送るときは、現在使っている URL の https://openrouter.ai/api/v1/chat/completions を https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openrouter/chat/completions に置き換えます。
OpenRouter へリクエストを送るときは、次を用意します。
- AI Gateway の Account ID
- AI Gateway のゲートウェイ名
- 有効な OpenRouter API トークン、または元のモデルプロバイダーのトークン
- 使う OpenRouter モデルの名前
curl -X POST https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openrouter/v1/chat/completions \
--header 'content-type: application/json' \
--header 'Authorization: Bearer OPENROUTER_TOKEN' \
--data '{
"model": "openai/gpt-5-mini",
"messages": [
{
"role": "user",
"content": "What is Cloudflare?"
}
]
}'JavaScript で OpenAI SDK を使う場合は、次のようにエンドポイントを設定できます。
import OpenAI from "openai";
const openai = new OpenAI({
apiKey: env.OPENROUTER_TOKEN,
baseURL:
"https://gateway.ai.cloudflare.com/v1/ACCOUNT_TAG/GATEWAY/openrouter",
});
try {
const chatCompletion = await openai.chat.completions.create({
model: "openai/gpt-5-mini",
messages: [{ role: "user", content: "What is Cloudflare?" }],
});
const response = chatCompletion.choices[0].message;
return new Response(JSON.stringify(response));
} catch (e) {
return new Response(e);
}