Guide

Use Mistral with the OpenAI SDK

You don't need Mistral AI's own SDK to call Mistral. Nicrron serves Mistral models through an OpenAI-compatible API, so the OpenAI SDK you already use calls them after two changes: the base URL and the key.

The same key also calls every other model on Nicrron, so trying Mistral against what you use today is a one-word change.

1. Get a key

Make an API key in the dashboard and add credit. Keep the key in an environment variable, for example NICRRON_API_KEY.

2. Point the SDK at Nicrron

Set base_url (Python) or baseURL (TypeScript) to https://api.nicrron.ai/v1, and use the model id mistral/mistral-large-4.

Python
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.nicrron.ai/v1",
    api_key=os.environ["NICRRON_API_KEY"],
)

reply = client.chat.completions.create(
    model="mistral/mistral-large-4",
    messages=[{"role": "user", "content": "Write a haiku about the sea."}],
)
print(reply.choices[0].message.content)
TypeScript
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.nicrron.ai/v1",
  apiKey: process.env.NICRRON_API_KEY,
});

const reply = await client.chat.completions.create({
  model: "mistral/mistral-large-4",
  messages: [{ role: "user", content: "Write a haiku about the sea." }],
});
console.log(reply.choices[0].message.content);

3. Pick a Mistral model

Model idContextInput / 1MOutput / 1M
mistral/mistral-small-4262k$0.15$0.60
mistral/mistral-medium-3.5262k$1.50$7.50
mistral/mistral-large-41M$1.36$4.18
mistral/mistral-large-3262k$0.50$1.50
mistral/ministral-14b262k$0.20$0.20
mistral/ministral-8b262k$0.15$0.15
mistral/ministral-3b131k$0.10$0.10
mistral/codestral256k$0.30$0.90

List prices in US dollars from the live catalog; requests paid from credit add a 5% platform fee. More on the Mistral AI models page.

4. Stream the answer

Streaming works the same as with OpenAI: pass stream=True and read the chunks.

Python
stream = client.chat.completions.create(
    model="mistral/mistral-large-4",
    messages=[{"role": "user", "content": "Explain DNS in three sentences."}],
    stream=True,
)
for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")

5. Add a fallback

Nicrron takes a models list as well as model. If Mistral Large 4 can't answer, the same request goes to the next model in the list, and reply.model says which one answered. The OpenAI SDK sends extra fields through extra_body.

Python
reply = client.chat.completions.create(
    model="mistral/mistral-large-4",
    messages=[{"role": "user", "content": "Hello!"}],
    # Tried in order if Mistral Large 4 can't answer: an outage or a rate limit.
    extra_body={"models": ["openai/gpt-6.2-sol"]},
)
print(reply.model)  # the model that actually answered

More in Fall back to another model.

Questions

Can I use Mistral with the OpenAI SDK?
Yes. Point the OpenAI SDK at https://api.nicrron.ai/v1 with a Nicrron API key, and set the model to a Mistral id such as "mistral/mistral-large-4". The request and the answer have the OpenAI chat completions shape, so the rest of your code stays the same.
Which Mistral models can I call this way?
8 right now: Mistral Small 4, Mistral Medium 3.5, Mistral Large 4, Mistral Large 3, Ministral 14B, Ministral 8B, Ministral 3B, Codestral. The ids and prices are on nicrron.ai/models.
Do streaming and function calling work with Mistral?
Streaming works with stream: true, as server-sent events of chat.completion.chunk. Tools use the OpenAI tools format; Nicrron passes them to models that support function calling.
How much does Mistral cost through Nicrron?
The provider's list price per token, shown for each model on its page. Requests paid from Nicrron credit add a 5% platform fee. API keys spend paid credit: add credit in the dashboard, with no subscription.