UniterRouter
API 参考Mistral AI

Mistral AI

Mistral API 集成 - 通过 UniterRouter 访问 Mistral Large、Mistral Medium、Codestral。OpenAI 兼容格式,支持函数调用和 JSON 模式。

Mistral AI API

通过 UniterRouter 使用 OpenAI 兼容 API 格式访问 Mistral AI 模型。Mistral 提供欧洲开发的高效模型,具有强大的多语言能力。

快速开始

curl https://api.uniterouter.ai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $UNITEROUTER_API_KEY" \
  -d '{
    "model": "mistral-large-latest",
    "messages": [
      {"role": "user", "content": "解释相对论"}
    ]
  }'
from openai import OpenAI

client = OpenAI(
    base_url="https://api.uniterouter.ai/v1",
    api_key="your_uniterouter_api_key",
)

response = client.chat.completions.create(
    model="mistral-large-latest",
    messages=[
        {"role": "user", "content": "解释相对论"}
    ]
)
print(response.choices[0].message.content)
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.uniterouter.ai/v1",
  apiKey: process.env.UNITEROUTER_API_KEY,
});

const response = await client.chat.completions.create({
  model: "mistral-large-latest",
  messages: [
    { role: "user", content: "解释相对论" }
  ],
});
console.log(response.choices[0].message.content);

可用模型

模型描述上下文最适合
mistral-large-latest最强大的模型128K复杂任务、推理
mistral-medium-latest平衡性能32K通用场景
mistral-small-latest快速高效32K快速任务、节省成本
open-mistral-nemo开放权重模型128K开源使用场景
codestral-latest代码专用32K编程、调试
pixtral-large-latest视觉模型128K图像理解

函数调用

Mistral 模型支持函数调用:

tools = [
    {
        "type": "function",
        "function": {
            "name": "get_weather",
            "description": "获取某个位置的当前天气",
            "parameters": {
                "type": "object",
                "properties": {
                    "location": {"type": "string", "description": "城市名称"},
                    "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
                },
                "required": ["location"]
            }
        }
    }
]

response = client.chat.completions.create(
    model="mistral-large-latest",
    messages=[{"role": "user", "content": "巴黎的天气怎么样?"}],
    tools=tools,
    tool_choice="auto"
)

JSON 模式

请求结构化 JSON 输出:

response = client.chat.completions.create(
    model="mistral-large-latest",
    messages=[
        {"role": "user", "content": "列出 3 种编程语言及其用途"}
    ],
    response_format={"type": "json_object"}
)

视觉 (Pixtral)

使用 Pixtral 进行图像理解:

response = client.chat.completions.create(
    model="pixtral-large-latest",
    messages=[
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "这张图片里有什么?"},
                {
                    "type": "image_url",
                    "image_url": {"url": "https://example.com/image.jpg"}
                }
            ]
        }
    ]
)

功能特点

  • 多语言:对欧洲语言有出色的支持
  • 高效:优化的推理速度
  • 函数调用:完整的工具使用支持
  • 视觉:Pixtral 支持图像理解
  • 代码:专用编程模型

相关文档

How is this guide?