mistralM

Docs

sideBar

Quickstart: create your first API key

Create a Mistral API key in Studio, store it, and check that it works, in about 5 minutes.
flagThis step takes ~5 minutes to complete.

In this quickstart, you create an API key in StudioarrowUpRight, store it in an environment variable, and send a test request with it. It takes about 5 minutes. The other Studio quickstarts start from this key.

Before you begin

1. Create the key

Select New key on the API Keys page

  • 1.

    Enter a Name that identifies the key, for example quickstart.
  • 2.

    Set an Expiration date.
  • 3.

    Choose a Connector access scope:
    • Shared connectors only: access only Connectors shared with the Workspace, not your private Connectors.
    • Private and shared connectors: access both your private Connectors and the Connectors shared with the Workspace.

Configure the API key with a name, an expiration date, and a connector access scope

exclamationMark

The full key appears only once. You can't retrieve it after you close the confirmation dialog.

  • 1.

    Create the key, then copy it and store it in a password manager or a secrets vault.

2. Store the key in an environment variable

The Mistral SDKs and the examples in these docs read the key from the MISTRAL_API_KEY environment variable. Set it in your terminal:

export MISTRAL_API_KEY="your-api-key"

The variable lasts for the current terminal session.

3. Send a test request

Send a chat completion request with the key:

curl https://api.mistral.ai/v1/chat/completions \
  -H "Authorization: Bearer $MISTRAL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "mistral-small-latest",
    "messages": [{"role": "user", "content": "Hello, Mistral!"}]
  }'

You should see

A JSON response with the model's reply in choices[0].message.content. The reply text varies between runs. The response also includes id, created, and usage.

{
  "object": "chat.completion",
  "model": "mistral-small-latest",
  "choices": [
    {
      "index": 0,
      "finish_reason": "stop",
      "message": {
        "role": "assistant",
        "content": "Hello! How can I assist you today?"
      }
    }
  ]
}

If you get {"detail":"Invalid API Key"} with HTTP status 401, check that MISTRAL_API_KEY holds the full key, in the terminal where you run curl.

lightbulb

Set an expiration date on every key and rotate keys regularly: create a new key, switch your code to it, then delete the old one. Delete a key as soon as you stop using it or suspect it has leaked. If an admin manages API keys for your organization, see API keys in the Admin docs.

Next quickstarts

Keep going with the next step.
Quickstart: send your first API request
logoCloud

Quickstart: send your first API request

Install the Mistral SDK and get your first answer from a Mistral model in Python, TypeScript, or curl, in about 5 minutes.

clock

5 min to complete

chevronRight
Quickstart: compare models in the playground
logoCloud

Quickstart: compare models in the playground

Send a prompt to a Mistral model in the Studio playground, change a parameter, and compare two models, in about 5 minutes.

clock

5 min to complete

chevronRight
Quickstart: build your first workflow
logoCloud

Quickstart: build your first workflow

Scaffold a workflows project, run a worker on your machine, and get the result of your first execution, in about 15 minutes.

clock

15 min to complete

chevronRight

Going further

All quickstarts
illustrationRocket

All quickstarts

Find a short, hands-on quickstart for Vibe Work, Vibe Code, Studio, inference, or Admin, and complete your first task.