Skip to content

非公式 / UnofficialCloudflare, Inc. 非提携。アカウント情報は入力しないでください。Not affiliated with Cloudflare, Inc. Do not enter Cloudflare credentials here.Official docsこのサイトについてプライバシー

Mistral AI

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

Mistral AI ↗ では、Mistral の高度な AI モデルですばやく構築できます。

エンドポイント

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

前提条件

Mistral AI へリクエストするときは、次が必要です。

  • AI Gateway のアカウント ID
  • AI Gateway のゲートウェイ名
  • Mistral AI の API トークン
  • Mistral AI のモデル名

URL の構成

新しいベース URL は、上記の値を使って次の形式になります。https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/mistral/。

続けて、呼び出したいエンドポイントを付けます。例: v1/chat/completions

最終的な URL は次のようになります。https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/mistral/v1/chat/completions。

例

cURL

fetch リクエストの例bash
curl -X POST https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/mistral/v1/chat/completions \
 --header 'content-type: application/json' \
 --header 'Authorization: Bearer MISTRAL_TOKEN' \
 --data '{
    "model": "mistral-large-latest",
    "messages": [
        {
            "role": "user",
            "content": "What is Cloudflare?"
        }
    ]
}'

JavaScript で @mistralai/mistralai パッケージを使う

@mistralai/mistralai パッケージを使っている場合、エンドポイントは次のように設定できます。

JavaScript の例js
import { Mistral } from "@mistralai/mistralai";

const client = new Mistral({
	apiKey: MISTRAL_TOKEN,
	serverURL: `https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/mistral`,
});

await client.chat.create({
	model: "mistral-large-latest",
	messages: [
		{
			role: "user",
			content: "What is Cloudflare?",
		},
	],
});

OpenAI 互換エンドポイント

REST API 経由で、OpenAI API スキーマを使って Mistral モデルにもアクセスできます。リクエストの送信先は次のとおりです。

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

次を指定します。


{
"model": "mistral/{model}"
}

役に立ちましたか?