Skip to content
Cloudflare Docs
非官方翻译 - 此文档为非官方中文翻译版本,仅供参考。如有疑问请以 英文官方文档 为准。

Mistral AI

Mistral AI 帮助您使用 Mistral 的先进 AI 模型快速构建。

端点

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

前提条件

在向 Mistral AI 发出请求时,您需要:

  • AI 网关账户 ID
  • AI 网关网关名称
  • 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

示例获取请求
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 示例
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-Compatible Endpoint

You can also use the OpenAI-compatible endpoint (/ai-gateway/chat-completion/) to access Mistral models using the OpenAI API schema. To do so, send your requests to:

https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/compat/chat/completions

Specify:

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