Back to Blog
API GuidesJune 22, 20257 min read

Mistral AI API Free Tier: Complete Guide for Developers (2025)

Mistral AI offers genuinely free API access to Mistral 7B and Codestral. Here's the full setup guide with Python examples and a comparison with GPT-4o.

Why Mistral AI Deserves Your Attention

Mistral AI is a French startup that has consistently punched above its weight class in model quality. Their open-weight Mistral 7B model outperformed Llama 2 13B despite being half the size. Mistral Medium competes with GPT-4 on many benchmarks. And Codestral — their code-focused model — is one of the best free options for code completion tasks.

Unlike OpenAI and Anthropic, Mistral offers a genuinely usable free tier with a permanent API key and no credit card required. For EU-based developers, Mistral is particularly attractive because they operate under GDPR with EU data residency.

Option 1 — Official Free Tier (Permanent Key)

Sign up at console.mistral.ai — email only, no credit card. You get:

  • Free access to Mistral 7B Instruct and Mixtral 8x7B
  • Rate limits: ~1 RPM on the free tier (very low for production, fine for dev)
  • Base URL: https://api.mistral.ai/v1
  • Permanent key — does not expire

Option 2 — FreeLLMKeys (Higher Rate Limit, More Models)

Via FreeLLMKeys you get Mistral Medium and Mixtral with 3–10 RPM — higher than the official free tier — plus access to all other models on the same key.

from openai import OpenAI

# Option A: Official Mistral free tier
official_client = OpenAI(
    base_url="https://api.mistral.ai/v1",
    api_key="your-official-mistral-key"
)

# Option B: FreeLLMKeys (higher limits, same models + more)
freellm_client = OpenAI(
    base_url="https://aiapiv2.pekpik.com/v1",
    api_key="sk-your-freellmkeys-key"
)

# Both use identical code — just different client objects
def ask_mistral(prompt: str, client=freellm_client) -> str:
    response = client.chat.completions.create(
        model="mistral-medium",
        messages=[{"role": "user", "content": prompt}]
    )
    return response.choices[0].message.content

Mistral Models Explained

ModelBest ForSpeedContext
Mistral 7B InstructSimple tasks, chatbots, classificationVery fast32K
Mixtral 8x7BGeneral purpose — good quality/speed tradeoffFast32K
Mistral MediumComplex reasoning, long documentsMedium128K
CodestralCode completion, generation, debuggingFast32K

Codestral for Code Completion

Codestral is Mistral's code-specific model. It supports fill-in-the-middle (FIM) completion — the same technique IDE plugins use for inline suggestions:

def code_completion(prefix: str, suffix: str = "") -> str:
    """Fill in the middle of code — perfect for IDE-style completion."""
    response = freellm_client.chat.completions.create(
        model="codestral-latest",
        messages=[{
            "role": "user",
            "content": f"Complete this code. Prefix:\n{prefix}\n\nSuffix:\n{suffix}\n\nProvide only the missing middle part."
        }]
    )
    return response.choices[0].message.content

# Example: complete a function implementation
prefix = """def binary_search(arr: list, target: int) -> int:
    left, right = 0, len(arr) - 1
    while left <= right:"""

suffix = """
    return -1"""

middle = code_completion(prefix, suffix)
print(middle)
# Output: the missing while-loop body

Mistral vs GPT-4o — When Mistral Wins

  • EU data residency requirement: Mistral stores and processes data in the EU — GPT-4o does not guarantee this
  • Cost at scale: Mistral Medium is significantly cheaper than GPT-4o per token at official pricing
  • Code completion: Codestral is competitive with GPT-4o for many coding tasks and much cheaper
  • Speed: Mistral 7B is one of the fastest hosted models available
  • Open weights: Mistral 7B and Mixtral can be self-hosted — GPT-4o cannot

Building a Simple Classifier with Mistral

def classify_text(text: str, categories: list[str]) -> str:
    cats = ", ".join(categories)
    response = freellm_client.chat.completions.create(
        model="mistral-medium",
        messages=[
            {
                "role": "system",
                "content": f"Classify the input into one of these categories: {cats}. Reply with only the category name."
            },
            {"role": "user", "content": text}
        ],
        temperature=0.1,
        max_tokens=20
    )
    return response.choices[0].message.content.strip()

# Test it
texts = [
    "My order hasn't arrived and it's been 2 weeks",
    "I want to return this product",
    "How do I reset my password?",
    "Your product is amazing, thank you!"
]

for text in texts:
    label = classify_text(text, ["shipping", "returns", "account", "compliment", "other"])
    print(f"{label:12} | {text}")

Mistral Medium is an excellent choice for classification tasks — fast, accurate, and either free via FreeLLMKeys or very cheap at official pricing. Try it alongside GPT-4o on your actual data and measure which performs better.

F
FreeLLMKeys Team
Building tools for the AI developer community