Skip to content

How to Create a Mistral AI API Key | Setup Guide

Learn how to create and manage Mistral AI API keys to access powerful open-source models including Mistral 7B, Mixtral 8x7B, Mistral Large, and more.


A Mistral AI API key enables you to:

  • Access Mistral’s state-of-the-art language models
  • Use open-source and proprietary models via API
  • Build AI applications with efficient inference
  • Leverage models with commercial licenses
  • Deploy multilingual AI capabilities

Before creating an API key, you need:

  1. Mistral AI Account → Sign up at https://console.mistral.ai
  2. Email Verification → Verify your email address
  3. Payment Method → Required for API usage (pay-as-you-go)
  4. Internet Connection → For API access

🔹 Step-by-Step: Creating a Mistral AI API Key

Section titled “🔹 Step-by-Step: Creating a Mistral AI API Key”
  1. Go to Mistral Console
  2. Click “Sign up” or “Get Started”
  3. Create an account using:
    • Email and password
    • Google account (OAuth)
  4. Verify your email address
  1. Log in to Mistral Console
  2. Navigate to “API Keys” in the left sidebar

Or go directly to: https://console.mistral.ai/api-keys

  1. Click “Create new key” or ”+ New API Key” button
  2. (Optional) Enter a name/description for your key
  3. Click “Create” or “Generate”

⚠️ CRITICAL: The API key is displayed only once!

  1. Copy the entire key immediately
  2. Store it in a secure location (password manager, secrets vault)
  3. Never share it publicly or commit to version control

Example API key format:

abcdef1234567890abcdef1234567890

  1. Go to API Keys
  2. You’ll see:
    • Key name
    • Key preview (partial key)
    • Created date
    • Last used timestamp
    • Actions (Delete)
  1. Find the key you want to remove
  2. Click the trash icon or “Delete” button
  3. Confirm the deletion

⚠️ Warning: Deleting a key immediately stops all services using it.


  • Store keys in environment variables
  • Use .env files for local development
  • Rotate keys regularly
  • Use separate keys for dev/staging/production
  • Set up usage alerts
  • Monitor API consumption
  • Hardcode keys in source code
  • Commit keys to Git repositories
  • Share keys in public forums
  • Reuse keys across multiple projects
  • Embed keys in client-side applications

Section titled “Method 1: Environment Variable (Recommended)”

Linux/macOS:

Terminal window
export MISTRAL_API_KEY="your-api-key-here"

Windows CMD:

Terminal window
set MISTRAL_API_KEY="your-api-key-here"

Windows PowerShell:

Terminal window
$env:MISTRAL_API_KEY="your-api-key-here"

Create a .env file:

MISTRAL_API_KEY=your-api-key-here

Load it in your code:

Python:

from dotenv import load_dotenv
import os
load_dotenv()
api_key = os.getenv("MISTRAL_API_KEY")

Node.js:

require('dotenv').config();
const apiKey = process.env.MISTRAL_API_KEY;

from mistralai.client import MistralClient
import os
client = MistralClient(api_key=os.getenv("MISTRAL_API_KEY"))
response = client.chat(
model="mistral-small-latest",
messages=[
{"role": "user", "content": "Hello, Mistral!"}
]
)
print(response.choices[0].message.content)
Terminal window
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!"}
]
}'
import MistralClient from '@mistralai/mistralai';
const client = new MistralClient(process.env.MISTRAL_API_KEY);
async function chat() {
const response = await client.chat({
model: 'mistral-small-latest',
messages: [
{ role: 'user', content: 'Hello, Mistral!' }
],
});
console.log(response.choices[0].message.content);
}
chat();

ModelDescriptionBest For
mistral-large-latestMost capable modelComplex reasoning, analysis
mistral-medium-latestBalanced performanceGeneral-purpose tasks
mistral-small-latestFast and efficientQuick responses, cost-effective
mistral-tinyUltra-fastSimple tasks, low latency
mixtral-8x7bMixture of ExpertsComplex, diverse tasks
mistral-embedEmbeddingsSemantic search, RAG

Note: Model names and availability may change. Check the documentation for the latest models.


Mistral AI uses pay-as-you-go pricing:

  • Based on tokens processed (input + output)
  • Varies by model tier
  • Charged per million tokens

Approximate Pricing (check official site):

Section titled “Approximate Pricing (check official site):”
  • Mistral Small: Lower cost per token
  • Mistral Medium: Mid-range pricing
  • Mistral Large: Higher cost, best quality

Check latest pricing: https://mistral.ai/technology/#pricing

  1. Go to Usage Dashboard
  2. Track:
    • API calls
    • Token consumption
    • Cost breakdown

To use the API:

  1. Go to Billing in the console
  2. Click “Add Payment Method”
  3. Enter your credit card details
  4. Set spending limits (optional but recommended)
  5. Save your payment information

Mistral AI implements rate limits:

  • Requests per minute (RPM): Varies by model and plan
  • Tokens per minute (TPM): Model-dependent
  • Concurrent requests: Limited
  • Implement exponential backoff
  • Cache responses when possible
  • Monitor usage patterns

To request higher limits, contact Mistral AI support.


Solution:

  • Verify the key is correct (no spaces)
  • Check if key was deleted
  • Ensure key is properly set in environment

Solution:

  • Implement retry logic with backoff
  • Reduce request frequency
  • Request limit increase if needed

Solution:

  • Add payment method
  • Check billing settings
  • Verify card is not expired

Solution:

  • Check model name spelling
  • Verify model is still supported
  • Use latest model names

Terminal window
pip install mistralai
Terminal window
npm install @mistralai/mistralai

No installation needed - use directly with API endpoints


from mistralai.client import MistralClient
import os
client = MistralClient(api_key=os.getenv("MISTRAL_API_KEY"))
for chunk in client.chat_stream(
model="mistral-small-latest",
messages=[{"role": "user", "content": "Tell me a story"}]
):
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end='', flush=True)
from mistralai.client import MistralClient
import os
client = MistralClient(api_key=os.getenv("MISTRAL_API_KEY"))
tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get weather information",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string"}
}
}
}
}
]
response = client.chat(
model="mistral-large-latest",
messages=[{"role": "user", "content": "What's the weather in Paris?"}],
tools=tools
)
from mistralai.client import MistralClient
import os
client = MistralClient(api_key=os.getenv("MISTRAL_API_KEY"))
embeddings = client.embeddings(
model="mistral-embed",
input=["Hello, world!", "Mistral AI is powerful"]
)
print(embeddings.data[0].embedding)

Mistral AI API is compatible with OpenAI’s API format:

import openai
openai.api_key = os.getenv("MISTRAL_API_KEY")
openai.api_base = "https://api.mistral.ai/v1"
response = openai.ChatCompletion.create(
model="mistral-small-latest",
messages=[{"role": "user", "content": "Hello!"}]
)


You now know how to: ✅ Create and manage Mistral AI API keys
✅ Use different Mistral models
✅ Implement advanced features
✅ Monitor usage and costs
✅ Troubleshoot common issues

Start building with Mistral’s powerful open-source models! 🎯