Mistral AI ↗ では、Mistral の高度な AI モデルですばやく構築できます。
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/mistralMistral AI へリクエストするときは、次が必要です。
- AI Gateway のアカウント ID
- AI Gateway のゲートウェイ名
- Mistral AI の API トークン
- Mistral AI のモデル名
新しいベース 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 -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?"
}
]
}'@mistralai/mistralai パッケージを使っている場合、エンドポイントは次のように設定できます。
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?",
},
],
});REST API 経由で、OpenAI API スキーマを使って Mistral モデルにもアクセスできます。リクエストの送信先は次のとおりです。
https://api.cloudflare.com/client/v4/accounts/{account_id}/ai/v1/chat/completions次を指定します。
{
"model": "mistral/{model}"
}