跳到主要内容

Mistral

Mistral 的透传端点 - 以原生格式调用提供商特定的端点(无翻译)。

功能支持备注
成本跟踪不支持
日志记录适用于所有集成
终端用户跟踪如果您需要此功能,请告诉我们
流式传输

只需将 https://api.mistral.ai/v1 替换为 LITELLM_PROXY_BASE_URL/mistral 🚀

示例用法

curl -L -X POST 'http://0.0.0.0:4000/mistral/v1/ocr' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer sk-1234' \
-d '{
"model": "mistral-ocr-latest",
"document": {
"type": "image_url",
"image_url": "https://raw.githubusercontent.com/mistralai/cookbook/refs/heads/main/mistral/ocr/receipt.png"
}

}'

支持所有 Mistral 端点(包括流式传输)。

快速开始

让我们调用 Mistral 的 /chat/completions 端点

  1. 将 MISTRAL_API_KEY 添加到您的环境变量中
export MISTRAL_API_KEY="sk-1234"
  1. 启动 LiteLLM 代理
litellm

# RUNNING on http://0.0.0.0:4000
  1. 测试一下!

让我们调用 Mistral 的 /ocr 端点

curl -L -X POST 'http://0.0.0.0:4000/mistral/v1/ocr' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer sk-1234' \
-d '{
"model": "mistral-ocr-latest",
"document": {
"type": "image_url",
"image_url": "https://raw.githubusercontent.com/mistralai/cookbook/refs/heads/main/mistral/ocr/receipt.png"
}

}'

示例

http://0.0.0.0:4000/mistral 之后的内容被视为提供商特定的路由,并相应处理。

关键变化

原始端点替换为
https://api.mistral.ai/v1http://0.0.0.0:4000/mistral (LITELLM_PROXY_BASE_URL="http://0.0.0.0:4000")
bearer $MISTRAL_API_KEYbearer anything (如果在代理上设置了虚拟密钥,请使用 bearer LITELLM_VIRTUAL_KEY

示例 1:OCR 端点

LiteLLM 代理调用

curl -L -X POST 'http://0.0.0.0:4000/mistral/v1/ocr' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer $LITELLM_API_KEY' \
-d '{
"model": "mistral-ocr-latest",
"document": {
"type": "image_url",
"image_url": "https://raw.githubusercontent.com/mistralai/cookbook/refs/heads/main/mistral/ocr/receipt.png"
}
}'

直接调用 Mistral API

curl https://api.mistral.ai/v1/ocr \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${MISTRAL_API_KEY}" \
-d '{
"model": "mistral-ocr-latest",
"document": {
"type": "document_url",
"document_url": "https://arxiv.org/pdf/2201.04234"
},
"include_image_base64": true
}'

示例 2:聊天 API

LiteLLM 代理调用

curl -L -X POST 'http://0.0.0.0:4000/mistral/v1/chat/completions' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer $LITELLM_VIRTUAL_KEY' \
-d '{
"messages": [
{
"role": "user",
"content": "I am going to Paris, what should I see?"
}
],
"max_tokens": 2048,
"temperature": 0.8,
"top_p": 0.1,
"model": "mistral-large-latest",
}'

直接调用 Mistral API

curl -L -X POST 'https://api.mistral.ai/v1/chat/completions' \
-H 'Content-Type: application/json' \
-d '{
"messages": [
{
"role": "user",
"content": "I am going to Paris, what should I see?"
}
],
"max_tokens": 2048,
"temperature": 0.8,
"top_p": 0.1,
"model": "mistral-large-latest",
}'

高级用法 - 结合虚拟密钥使用

先决条件

使用此方法可以避免向开发人员提供原始的 Mistral API 密钥,同时仍允许他们使用 Mistral 端点。

用法

  1. 设置环境变量
export DATABASE_URL=""
export LITELLM_MASTER_KEY=""
export MISTRAL_API_BASE=""
litellm

# RUNNING on http://0.0.0.0:4000
  1. 生成虚拟密钥
curl -X POST 'http://0.0.0.0:4000/key/generate' \
-H 'Authorization: Bearer sk-1234' \
-H 'Content-Type: application/json' \
-d '{}'

预期响应

{
...
"key": "sk-1234ewknldferwedojwojw"
}
  1. 测试一下!
curl -L -X POST 'http://0.0.0.0:4000/mistral/v1/chat/completions' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer sk-1234ewknldferwedojwojw' \
--data '{
"messages": [
{
"role": "user",
"content": "I am going to Paris, what should I see?"
}
],
"max_tokens": 2048,
"temperature": 0.8,
"top_p": 0.1,
"model": "qwen2.5-7b-instruct",
}'