Last updated 2026-05-17
Mistral Provider
The mistral provider implements
Provider
(chat) and
Embedder
against
api.mistral.ai.
Mistral's REST surface is OpenAI-compatible, so this provider is a
thin wrapper that pins the base URL and known model ids; under the
hood it reuses the
OpenAI provider
machinery.
Import path
import ( "github.com/elloloop/llmrouter" "github.com/elloloop/llmrouter/providers/mistral")Construction
p, err := mistral.New( llmrouter.WithAPIKey(os.Getenv("MISTRAL_API_KEY")),)
Default endpoint: https://api.mistral.ai/v1. Auth via
Authorization: Bearer <key>.
Chat models
mistral-large-latest— flagship.mistral-small-latest— balanced cost/quality.codestral-latest— code-specialised.open-mistral-nemo— open-weights 12B.pixtral-large-latest— multimodal (image input).ministral-8b-latest,ministral-3b-latest— small models.
Chat example
stream, err := p.CompletionStream(ctx, llmrouter.ChatRequest{ Model: "mistral-large-latest", Messages: []llmrouter.Message{ llmrouter.TextMessage("system", "You are concise."), llmrouter.TextMessage("user", "What is Mixture of Experts?"), },})
for chunk := range stream.Chunks() { for _, c := range chunk.Choices { fmt.Print(c.Delta.Content) }}Embeddings
Mistral exposes a single embedding model:
mistral-embed— 1024 dims, multilingual.
resp, err := p.Embed(ctx, llmrouter.EmbedRequest{ Model: "mistral-embed", Inputs: []string{"Bonjour le monde"},}) TaskType is not modelled on the wire; the library
ignores it for Mistral.
Error handling
Non-2xx responses surface as
*llmrouter.ErrUpstream
with Provider == "mistral".
Caveats
- Strict JSON mode. Mistral's
response_formatis OpenAI-compatible; pass viaRaw. - EU data residency. Mistral hosts in the EU by default. For US users, latency is slightly higher than US-hosted vendors.
See also
- OpenAI-compatible endpoints — same machinery, different base URLs.
- Embeddings concept.