The API beats Le Chat the moment you want to repeat a task, run it on more than a handful of items, plug it into another tool, or pin a specific model for a predictable price. It also beats it on cost for almost everyone who is not chatting for hours a day, because you pay only for the tokens you use. What you give up is the interface: no upload button, no search toggle, just JSON in and JSON out.
Get a key
Sign in at console.mistral.ai, add a payment method, and create an API key under API Keys. Store it in an environment variable named MISTRAL_API_KEY. Never paste it into a chat window, a repo, or a front-end bundle. Set a spending limit in Billing before you write a single line of code.
First call with curl
curl https://api.mistral.ai/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $MISTRAL_API_KEY" \
-d '{
"model": "mistral-small-latest",
"messages": [
{"role": "system", "content": "You are a concise assistant. No preamble."},
{"role": "user", "content": "In one sentence, what is an output token?"}
],
"max_tokens": 100
}'The response contains choices[0].message.content and a usage object with prompt_tokens, completion_tokens and total_tokens. Log usage from day one. It is the only way to know what a feature costs before the invoice arrives.
Same call with the Python SDK
import os
from mistralai import Mistral
client = Mistral(api_key=os.environ["MISTRAL_API_KEY"])
res = client.chat.complete(
model="mistral-small-latest",
messages=[
{"role": "system", "content": "You are a concise assistant. No preamble."},
{"role": "user", "content": "In one sentence, what is an output token?"},
],
max_tokens=100,
)
print(res.choices[0].message.content)
print(res.usage) # prompt_tokens, completion_tokens, total_tokensTokens and context
Two rules explain most Mistral bills. First, the whole conversation is re-sent on every turn, so a 20-turn chat costs far more than 20 single questions. Second, output tokens cost more than input on most models (Small 4 is $0.15 in and $0.60 out per 1M at the time of writing), so asking for shorter answers is a direct saving. max_tokens is your seatbelt; set it.
Batch inference
Mistral offers a batch API for jobs that do not need an answer within seconds: you upload a file of requests and collect results later, at a lower price than real-time calls. We do not quote the discount here because it is set on the official pricing page. As one data point from our catalogue, the Mistral Medium 3.5 batch row lists at $0.75 / $3.75 against $1.50 / $7.50 for the real-time row at the time of writing. If your job is a nightly classification or a bulk summarisation, batch is the default, not the exception.
Knowledge check
Which field should you log from every API response to control cost?