Zum Hauptinhalt springen

Mistral

Pass-through-Endpunkte fĂĽr Mistral - rufen Sie den anbieterspezifischen Endpunkt im nativen Format auf (keine Ăśbersetzung).

FeatureUnterstĂĽtztNotizen
Kostenverfolgung❌Nicht unterstützt
Protokollierungâś…funktioniert ĂĽber alle Integrationen hinweg
Endbenutzerverfolgung❌Sagen Sie uns Bescheid, wenn Sie dies benötigen
Streamingâś…

Ersetzen Sie einfach https://api.mistral.ai/v1 durch LITELLM_PROXY_BASE_URL/mistral 🚀

Beispielverwendung​

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

}'

UnterstĂĽtzt ALLE Mistral-Endpunkte (einschlieĂźlich Streaming).

Schnellstart​

Rufen wir den Mistral /chat/completions-Endpunkt auf

  1. FĂĽgen Sie MISTRAL_API_KEY zu Ihrer Umgebung hinzu
export MISTRAL_API_KEY="sk-1234"
  1. LiteLLM Proxy starten
litellm

# RUNNING on http://0.0.0.0:4000
  1. Testen Sie es!

Rufen wir den Mistral /ocr-Endpunkt auf

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

}'

Beispiele​

Alles nach http://0.0.0.0:4000/mistral wird als anbieterspezifische Route behandelt und entsprechend verarbeitet.

Wesentliche Änderungen

UrsprĂĽnglicher EndpunktErsetzen Sie durch
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 (verwenden Sie bearer LITELLM_VIRTUAL_KEY, wenn virtuelle SchlĂĽssel auf dem Proxy eingerichtet sind)

Beispiel 1: OCR-Endpunkt​

LiteLLM Proxy Aufruf​

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

Direkter Mistral API-Aufruf​

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

Beispiel 2: Chat API​

LiteLLM Proxy Aufruf​

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

Direkter Mistral API-Aufruf​

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

Fortgeschritten – Verwendung mit virtuellen Schlüsseln​

Voraussetzungen

Verwenden Sie dies, um zu verhindern, dass Entwickler den rohen Mistral API-Schlüssel erhalten, ihnen aber dennoch die Verwendung von Mistral-Endpunkten ermöglichen.

Verwendung​

  1. Umgebung einrichten
export DATABASE_URL=""
export LITELLM_MASTER_KEY=""
export MISTRAL_API_BASE=""
litellm

# RUNNING on http://0.0.0.0:4000
  1. Virtuellen SchlĂĽssel generieren
curl -X POST 'http://0.0.0.0:4000/key/generate' \
-H 'Authorization: Bearer sk-1234' \
-H 'Content-Type: application/json' \
-d '{}'

Erwartete Antwort

{
...
"key": "sk-1234ewknldferwedojwojw"
}
  1. Testen Sie es!
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",
}'