跳至主要內容

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 Proxy
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 (若 proxy 上已設定 Virtual Keys,請使用 bearer LITELLM_VIRTUAL_KEY)

範例 1:OCR 端點

LiteLLM Proxy 呼叫

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:Chat API

LiteLLM Proxy 呼叫

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",
}'

進階 - 搭配 Virtual Keys 使用

前置需求

請使用這個方式,避免將原始 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. 產生 virtual key
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",
}'
🚅
LiteLLM Enterprise
為正式環境打造的 SSO/SAML、稽核記錄、支出追蹤、多團隊管理與防護欄。
深入瞭解 →