Your Mistral API key, from a new account to a printed reply

By Christophe Paka · Facts checked on 24 October 2026

Mistral AI is a French company that makes AI models. This page is for developers, or anyone handing setup to one: it shows how to get a Mistral API key and a first reply from your own code. Only want to chat? You do not need this page: the Vibe app needs no key and no code.

The docs ask for an account, a key, a variable, a library and a script. Rush it and the worst mistake is quiet: a key pasted into your code leaks with the code, and anyone who holds a copy can run up your bill.

The figure shows the whole path in five steps, and after each one something new exists that you can check. The post on what you send and what comes back reads the reply.

Five boxes left to right: account created in Studio, API key named and copied once, env variable MISTRAL_API_KEY set and not in code, first call with chat.complete(), and the response printed to the terminal.
Figure 3.1: From account to a printed reply. Five steps; after each one something new exists that you can check.
Use this diagram on your site

Free to share in your blog post, docs, course or slides, as long as the credit link stays. Paste the code below where the figure should go.

How to read this figure

  1. Account: created in Studio. Studio is Mistral's platform for developers. Sign in at console.mistral.ai with your Mistral account. API access is on by default, and the free start needs no card: it gives an included monthly amount of use. Free mode data may be used for training, so test with no client data. Your check: the Studio console opens.

  2. API key: named, copied once. An API key is a secret string that lets your code use your account, like a hotel key card. Name it for where it will run. Studio shows the full key once, so copy it into a password manager. The key form also asks for an Expiration date: set one, so a leak has an end.

  3. Env variable: set, not in code. A terminal is the text window where you type commands, such as Terminal on a Mac. An environment variable works like a sticky note that window keeps: you write the key on it once, and your code reads the note, so the key never sits in a file you might share. The note is MISTRAL_API_KEY. Your check: the terminal prints nothing.

  4. First call: chat.complete(). Here you need Python, the programming language the script uses, already on your computer. No Python, or never typed a command? Hand this step to a developer, or just read the results. Install mistralai with pip, Python's installer; it wraps the API in a few lines. In the docs' quickstart script, call the dated name mistral-large-2512 instead of mistral-large-latest, so the model cannot change under you.

  5. Response: printed to terminal. Run the script. A short description of Mistral AI prints, a few sentences long. If 401 Unauthorized prints instead, your key is wrong or not set in this terminal window. Set it again in the same window and run once more.

Key takeaways

  • Name each key for its project and give it an Expiration date in Studio's key form, so a leak has an end.
  • Call a dated model name such as mistral-large-2512 in anything you keep.
  • Read your limits and set a spending cap the day you add a card.

Try this: your first reply in one terminal window

You have a key from Studio, and a terminal with Python and pip. Run these in one terminal window, with your real key between the quotes. No terminal? Read each expected result and skip the steps.

  1. Set the key: export MISTRAL_API_KEY="your_api_key_here". The terminal prints nothing.
  2. Install the SDK: pip install mistralai. Pip ends with a line that names mistralai as installed.
  3. Save the docs' quickstart script as quickstart.py and set model="mistral-large-2512" in it.
  4. Run it: python quickstart.py.

Expected result: A few sentences about Mistral AI print. A 401 means your key is wrong or not set here, a 402 means no payment method, and a 429 means a rate limit was hit: wait, then retry.

Questions readers ask

Do I need a credit card for a Mistral API key?

No. Studio's free start needs no card, and API access is on by default. It includes a monthly amount of use within your limits; past that you buy prepaid credits. Free mode data may be used for training, so test with no client data. A 402 Payment Required error means the account has no payment method.

Why does my Mistral API return 429?

A 429 means a rate limit was hit: the most your organization may send in a period. It is the limit plus one, not a broken account. Wait, retry more slowly, and read your limits under Admin Panel, API, Limits. Readers also report paused free requests.

What if I lose my Mistral API key?

Studio shows the full key only once and cannot show it again, so create a new key. If a key leaks, create a new one, move your code to it, and remove the old one at once.

Sources: Activate Studio and generate an API key (Mistral Docs); Send your first API request (Mistral Docs); Usage and limits (Mistral Docs).

This figure is from Mistral Made Crystal Clear, chapter 3.

The chapter builds the idea step by step, with recipes you can follow, a Try it to check yourself, and every source.

Get the book

All diagrams