Mistral AI ↗ 帮助你使用 Mistral 的先进 AI 模型快速构建。
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/mistral向 Mistral AI 发送请求时,请确保具备以下条件:
- AI Gateway Account ID
- AI Gateway 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 schema 访问 Mistral 模型。将请求发送至:
https://api.cloudflare.com/client/v4/accounts/{account_id}/ai/v1/chat/completions指定:
{
"model": "mistral/{model}"
}