Groq ↗ は、高速処理と低レイテンシを提供します。
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/groqGroq ↗ へリクエストを送るときは、いま使っている 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 のゲートウェイ名。
- 有効な 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 スキーマを使って Groq モデルにもアクセスできます。リクエストの送信先は次のとおりです。
https://api.cloudflare.com/client/v4/accounts/{account_id}/ai/v1/chat/completions次を指定します。
{
"model": "groq/{model}"
}