Skip to content
Cloudflare Docs
非官方翻译 - 此文档为非官方中文翻译版本,仅供参考。如有疑问请以 英文官方文档 为准。

Groq

Groq 提供高速处理和低延迟性能。

端点

https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/groq

URL 结构

在向 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

示例获取请求
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"
}'

在 JavaScript 中使用 Groq SDK

如果使用 groq-sdk,这样设置您的端点:

JavaScript
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,
});

OpenAI-Compatible Endpoint

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}"
}