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 Gateway Account ID。
- 你的 AI Gateway gateway 名称。
- 有效的 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,
});你也可以通过 REST API 使用 OpenAI API schema 访问 Groq 模型。将请求发送至:
https://api.cloudflare.com/client/v4/accounts/{account_id}/ai/v1/chat/completions指定:
{
"model": "groq/{model}"
}