Skip to content

Mistral

batchling is compatible with Mistral through any supported framework

The following endpoints are made batch-compatible by Mistral:

  • /v1/chat/completions
  • /v1/fim/completions
  • /v1/embeddings
  • /v1/moderations
  • /v1/chat/moderations/v1/ocr
  • /v1/classifications
  • /v1/conversations/v1/audio/transcriptions

Check model support and batch pricing

Before sending batches, review the provider's official pricing page for supported models and batch pricing details.

The Batch API docs for Mistral can be found on the following URL:

https://docs.mistral.ai/capabilities/batch/

Example Usage

API key required

Set MISTRAL_API_KEY in .env or ensure it is already loaded in your environment variables before running batches.

Here's an example showing how to use batchling with Mistral:

mistral_example.py
import asyncio
import os

from dotenv import load_dotenv
from mistralai import Mistral

from batchling import batchify

load_dotenv()


async def build_tasks() -> list:
    """Build Mistral requests."""
    client = Mistral(api_key=os.getenv(key="MISTRAL_API_KEY"))
    questions = [
        "Who is the best French painter? Answer in one short sentence.",
        "What is the capital of France?",
    ]
    return [
        client.chat.complete_async(
            model="mistral-medium-2505",
            messages=[
                {
                    "role": "user",
                    "content": question,
                }
            ],
            stream=False,
            response_format={"type": "text"},
        )
        for question in questions
    ]


async def main() -> None:
    """Run the Mistral example."""
    tasks = await build_tasks()
    responses = await asyncio.gather(*tasks)
    for response in responses:
        print(f"{response.model} answer:\n{response.choices[0].message.content}\n")


async def run_with_batchify() -> None:
    """Run `main` inside `batchify` for direct script execution."""
    async with batchify():
        await main()


if __name__ == "__main__":
    asyncio.run(run_with_batchify())

Output:

mistral-medium-2505 answer:
Claude Monet is widely regarded as one of the best French painters, renowned for his pioneering role in Impressionism.

mistral-medium-2505 answer:
The capital of France is **Paris**. It is not only the political and administrative center of the country but also a major cultural, historical, and economic hub. Paris is famous for landmarks like the Eiffel Tower, the Louvre Museum, and Notre-Dame Cathedral.