Skip to content

非公式本サイトは非公式の日本語ドキュメントであり、Cloudflare 公式サイトではありません。最新情報はdevelopers.cloudflare.comをご確認ください。

Groq

最終更新 Markdown で表示Agent セットアップ

Groq は、高速処理と低レイテンシを提供します。

エンドポイント

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

URL の構成

Groq へリクエストを送るときは、いま使っている URL の https://api.groq.com/openai/v1https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/groq に置き換えます。

前提条件

Groq へリクエストを送るときは、次を用意します。

  • AI Gateway の Account ID。
  • AI Gateway のゲートウェイ名。
  • 有効な Groq API トークン。
  • 使いたい Groq モデルの名前。

cURL

fetch リクエストの例bash
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 を使う場合は、エンドポイントを次のように設定します。

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 スキーマを使って Groq モデルにもアクセスできます。リクエストの送信先は次のとおりです。

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

次を指定します。


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

役に立ちましたか?