Groq ↗ 提供高速处理和低延迟性能。
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/groq
在向 Groq ↗ 发出请求时,将您当前使用的 URL 中的 https://api.groq.com/openai/v1
替换为 https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/groq
。
在向 Groq 发出请求时,确保您具有以下内容:
- 您的 AI 网关账户 ID。
- 您的 AI 网关网关名称。
- 一个有效的 Groq API 令牌。
- 您要使用的 Groq 模型的名称。
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/groq/chat/completions \ --header 'Authorization: Bearer {groq_api_key}' \ --header 'Content-Type: application/json' \ --data '{ "messages": [ { "role": "user", "content": "What is Cloudflare?" } ], "model": "llama3-8b-8192"}'
如果使用 groq-sdk
↗,这样设置您的端点:
import Groq from "groq-sdk";
const apiKey = env.GROQ_API_KEY;const accountId = "{account_id}";const gatewayId = "{gateway_id}";const baseURL = `https://gateway.ai.cloudflare.com/v1/${accountId}/${gatewayId}/groq`;
const groq = new Groq({ apiKey, baseURL,});
const messages = [{ role: "user", content: "What is Cloudflare?" }];const model = "llama3-8b-8192";
const chatCompletion = await groq.chat.completions.create({ messages, model,});
You can also use the OpenAI-compatible endpoint (/ai-gateway/chat-completion/
) to access Groq models using the OpenAI API schema. To do so, send your requests to:
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/compat/chat/completions
Specify:
{"model": "groq/{model}"}
- @2025 Cloudflare Ubitools
- Cf Repo