跳转到内容
搜索文档

Mistral AI

最后更新 查看 MarkdownAgent 设置

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 结构

你的新基础 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

Example fetch requestbash
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 包与 JavaScript

如果你使用 @mistralai/mistralai 包,可以这样设置端点:

JavaScript examplejs
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 schema 访问 Mistral 模型。将请求发送至:

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

指定:


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

这篇文档对您有帮助吗?