Mistral API Not Working? Fix Authentication, Rate Limits & SDK Errors
Troubleshoot Mistral API errors — 401 invalid API key, 422 invalid model name, 429 rate limit exceeded, streaming issues, and function calling errors when using mistral-large-latest or mistral-small-latest.
Common errors and fixes
Authentication — 401 error
A 401 error means the API key is missing, invalid, or not being passed correctly. Use the Python SDK or REST API as shown:
# Python SDK
from mistralai import Mistral
import os
client = Mistral(api_key=os.environ["MISTRAL_API_KEY"])
response = client.chat.complete(
model="mistral-large-latest",
messages=[{"role": "user", "content": "Hello"}]
)
print(response.choices[0].message.content) # REST API with curl
curl https://api.mistral.ai/v1/chat/completions \
-H "Authorization: Bearer $MISTRAL_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "mistral-large-latest", "messages": [{"role": "user", "content": "Hello"}]}' - Get API key at console.mistral.ai — go to API Keys → Create new key. Free tier available.
- Pass as Authorization: Bearer header — or set the
MISTRAL_API_KEYenvironment variable. - Free tier keys are limited to tier 1 rate limits — upgrade at console.mistral.ai for higher limits.
- Enterprise accounts have separate key management — check with your admin if your key returns 401.
Valid model names — 422 error
A 422 error usually means you used a model name that doesn't exist. Always use the -latest suffix variants for production. Current Mistral model IDs (June 2026):
| Model ID | Notes |
|---|---|
mistral-large-latest | Most capable, function calling |
mistral-small-latest | Fast, cost-effective |
codestral-latest | Code generation and completion |
open-mistral-7b | Open weights, basic tasks |
open-mixtral-8x7b | MoE, good quality/cost |
open-mixtral-8x22b | MoE, high quality |
open-codestral-mamba | Code, experimental |
mistral-embed | Text embeddings for vector search |
Common wrong names that return 422: mistral-large (missing -latest), mistral-7b (use open-mistral-7b), mixtral-8x7b (use open-mixtral-8x7b).
Streaming not working
Use client.chat.stream() not client.chat.complete() for streaming. The stream returns a generator — iterate it with a for loop:
# Correct streaming with Python SDK
with client.chat.stream(
model="mistral-large-latest",
messages=[{"role": "user", "content": "Write a poem"}]
) as stream:
for event in stream:
if event.data.choices[0].delta.content:
print(event.data.choices[0].delta.content, end="") // JavaScript/TypeScript
const stream = await client.chat.stream({
model: "mistral-large-latest",
messages: [{ role: "user", content: "Write a poem" }],
});
for await (const chunk of stream) {
const delta = chunk.data.choices[0].delta.content;
if (delta) process.stdout.write(delta);
} - Do not call .content on the stream object directly — iterate the generator to get chunks.
- REST API: set
stream: truein the request body and consume thetext/event-streamresponse.
Rate limits and quotas — 429 error
Mistral rate limits vary by tier. Free tier: 1 request/second, 500,000 tokens/month. Tier 1 (after payment): 5 req/s, higher token limits. Add exponential backoff:
import time
import random
from mistralai import MistralException
def chat_with_retry(client, **kwargs):
for attempt in range(5):
try:
return client.chat.complete(**kwargs)
except MistralException as e:
if "429" in str(e) and attempt < 4:
wait = (2 ** attempt) + random.random()
time.sleep(wait)
else:
raise - Free tier: 1 request/second, 500,000 tokens/month — upgrade at console.mistral.ai for higher limits.
- Tier 1 (after adding payment): 5 req/s with higher token limits.
- Enterprise: custom limits — contact Mistral for dedicated capacity.
Function calling / tool use errors
Tool use requires mistral-large-latest or mistral-small-latest — not open-weight models. Full example including sending tool results back:
import json
tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current weather for a city",
"parameters": {
"type": "object",
"properties": {
"city": {"type": "string", "description": "City name"}
},
"required": ["city"]
}
}
}
]
response = client.chat.complete(
model="mistral-large-latest",
messages=[{"role": "user", "content": "What's the weather in Paris?"}],
tools=tools,
tool_choice="auto"
)
# Handle tool call
if response.choices[0].message.tool_calls:
tool_call = response.choices[0].message.tool_calls[0]
args = json.loads(tool_call.function.arguments)
weather_result = get_weather(args["city"]) # your function
# Send tool result back
messages = [
{"role": "user", "content": "What's the weather in Paris?"},
response.choices[0].message, # assistant message with tool_calls
{
"role": "tool",
"content": str(weather_result),
"tool_call_id": tool_call.id
}
]
final = client.chat.complete(model="mistral-large-latest", messages=messages) - Supported models only: tool use works with
mistral-large-latestandmistral-small-latest, not open-weight models likeopen-mistral-7b. - tool_call_id must match: when sending tool results back, the
tool_call_idmust match the ID returned in the assistant's tool_calls response. - Parameters must be JSON Schema: the
parametersobject requirestype: "object"and apropertiesfield.
Know when the Mistral API has an outage
Free email alerts. Star Mistral API on Prismix — no credit card needed.
FAQ
Mistral API vs OpenAI API pricing
Mistral is generally cheaper than OpenAI for comparable quality. mistral-small-latest is ~$0.20/1M tokens (vs $0.60 for gpt-4o-mini). mistral-large-latest is ~$2/1M tokens (vs $2.50 for gpt-4o). Both have streaming and function calling.
Can I run Mistral models locally?
Yes. Download from Hugging Face or use Ollama: ollama pull mistral or ollama pull mixtral. The API and local models use the same prompt format. For code, use ollama pull codestral locally.
Mistral La Plateforme vs Mistral chat
La Plateforme (console.mistral.ai) is the API for developers. Mistral chat (chat.mistral.ai) is the consumer product like ChatGPT. They are separate — an API key does not give chat.mistral.ai Pro access.