跳转到内容
搜索文档

Groq

最后更新 查看 MarkdownAgent 设置

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 Gateway Account ID。
  • 你的 AI Gateway gateway 名称。
  • 有效的 Groq API 令牌。
  • 要使用的 Groq 模型名称。

示例

cURL

Example fetch requestbash
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 与 JavaScript

如果使用 groq-sdk,可以这样设置端点:

JavaScriptjs
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 兼容端点

你也可以通过 REST API 使用 OpenAI API schema 访问 Groq 模型。将请求发送至:

https://api.cloudflare.com/client/v4/accounts/{account_id}/ai/v1/chat/completions

指定:


{
"model": "groq/{model}"
}

这篇文档对您有帮助吗?