How to hit the Mistral API

Mistral's API lives at https://api.mistral.ai/v1 and follows the familiar chat-completions shape. -latest model names always point at the newest version of that model.

Authentication

Create a key in console.mistral.ai and send it as Authorization: Bearer <key>. In the examples it's written {{MISTRAL_API_KEY}}.

Full reference: https://docs.mistral.ai/api/

Chat completion

The reply is in choices[0].message.content.

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": "What is the difference between PUT and PATCH?"}]
  }'
Run in PostTaco

JSON output

response_format forces valid JSON. Say what shape you want in the prompt.

curl https://api.mistral.ai/v1/chat/completions \
  -H "Authorization: Bearer {{MISTRAL_API_KEY}}" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "mistral-small-latest",
    "response_format": {"type": "json_object"},
    "messages": [{"role": "user", "content": "List three HTTP methods as JSON: {\"methods\": [...]}"}]
  }'
Run in PostTaco

Create embeddings

One vector per input string, in data[].embedding.

curl https://api.mistral.ai/v1/embeddings \
  -H "Authorization: Bearer {{MISTRAL_API_KEY}}" \
  -H "Content-Type: application/json" \
  -d '{"model": "mistral-embed", "input": ["The quick brown fox", "A lazy dog"]}'
Run in PostTaco

List models

Every model your key can use, including the exact versions behind each -latest alias.

curl https://api.mistral.ai/v1/models \
  -H "Authorization: Bearer {{MISTRAL_API_KEY}}"
Run in PostTaco