OverpayingForAIPricing desk

Lesson 7 of 8 · 10 min read · Beginner

Mistral API quickstart

When the API beats Le Chat, how to make your first call with curl and the official Python SDK, and how tokens, context and batch inference change the bill.

In this lesson you will

  • Decide when the API is the cheaper or more controllable option than Le Chat
  • Make a working chat completion call with curl and with the mistralai Python package
  • Understand tokens, context and batch inference well enough to predict a bill

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

bashChat completion via the official endpoint. The request body is OpenAI-compatible.
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

pythonpip install mistralai. The client reads the key from the argument; pass it from the environment.
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_tokens

Tokens and context

Tokens and the context windowA token is roughly ¾ of an English word. The context window is the maximum tokens the model can hold at once — everything you send plus everything it writes.System prompt + instructionsConversation history + documentsNew answerfreeWhy it costs moneyEvery turn re-sends the whole history. A 40-message chat with a pasted PDF bills that PDF 40 times unless the provider caches it.“1M context” is a ceiling, not a target. Filling it on every request is the fastest way to overpay.rule of thumb: 1,000 tokens ≈ 750 words ≈ 1.5 pages
Figure 1.Everything in the context window is billed as input on every call: system prompt, history, documents and the new question. Output is billed separately and usually at a higher rate.

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?

Lesson FAQ

Is the Mistral API compatible with OpenAI code?

The chat completions request and response shapes are OpenAI-compatible, so most code ports with a base URL, key and model change. Verify tool calling and structured output separately.

Does Mistral have a batch API?

Yes. Batch inference runs queued requests at a discount to real-time pricing. The current discount is on the official pricing page; our catalogue shows Medium 3.5 batch at half the real-time rate at the time of writing.

Which model should my first API call use?

mistral-small-latest for the first ten minutes, then a pinned dated id such as mistral-small-2603. Move up to Large 3 only if Small fails on your task.

Finished reading?

Mark it done to track your progress through the course.

Compare, calculate, decide — for Mistral (Le Chat)

If our calculators helped you cut down on hidden AI wallet leaks, consider buying us a coffee. A tiny fraction of your savings keeps our pricing indexes updated daily.

Not sure which AI is cheapest for your use case? Find out in 30 seconds — no signup required.

AI cost intelligence

Stop overpaying for AI tools

Join the OverpayingForAI list for pricing updates, cheaper alternatives, and practical buying guidance.

Now tracking 50+ AI tools, models, platforms, subscriptions, coding tools, and automation products.

We use your email only for OverpayingForAI updates. Unsubscribe anytime.