OpenRouter ↗ 是一个提供统一接口来访问和使用大型语言模型 (LLMs) 的平台。
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openrouter
在向 OpenRouter ↗ 发出请求时,将您当前使用的 URL 中的 https://openrouter.ai/api/v1/chat/completions
替换为 https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openrouter
。
在向 OpenRouter 发出请求时,确保您具有以下内容:
- 您的 AI 网关账户 ID。
- 您的 AI 网关网关名称。
- 一个有效的 OpenRouter API 令牌或来自原始模型提供商的令牌。
- 您要使用的 OpenRouter 模型的名称。
curl -X POST https://gateway.ai.cloudflare.com/v1/ACCOUNT_TAG/GATEWAY/openrouter/v1/chat/completions \ --header 'content-type: application/json' \ --header 'Authorization: Bearer OPENROUTER_TOKEN' \ --data '{ "model": "openai/gpt-3.5-turbo", "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-3.5-turbo", 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);}
- @2025 Cloudflare Ubitools
- Cf Repo