Mistral AI LLM provider
Mistral AI provider for Piko's LLM service. Chat completions, streaming, tool/function calling, and embeddings against the Mistral API at api.mistral.ai.
Overview
This provider implements llm.ProviderPort and llm.EmbeddingProviderPort against Mistral's hosted API. One registration delivers chat completions, streaming, tool/function calling, structured output, and embeddings. Mistral publishes open weights for part of its model family, and the hosted and self-hosted variants share the same API surface. The BaseURL field accepts any OpenAI-compatible endpoint, so a self-hosted vLLM or Ollama deployment serving Mistral weights can replace the hosted endpoint with a single field change.
The provider degrades safely against a slow or hostile endpoint. It caps each response body at 16 MiB, recovers from panics on every call path, and drains then closes connections so they return to the pool for reuse. It emits OpenTelemetry counters and latency histograms for completion, streaming, and embedding calls through Piko's metrics. Close cancels a provider-level context and waits on in-flight streaming goroutines, so shutdown stays graceful when the container tears the service down.
The default model is mistral-large-latest. The default embedding model is mistral-embed (1024 dimensions).
Requirements
- A Mistral API key from
console.mistral.ai. - Network egress to
api.mistral.ai(or yourBaseURLoverride for self-hosted endpoints).
The provider is pure Go and needs no build tag or CGO. You wire it through piko.New options, so it runs in compiled mode only. Interpreted dev mode (dev-i) does not expose the provider package.
Configuration
import (
"os"
"piko.sh/piko/wdk/llm/llm_provider_mistral"
)
provider, err := llm_provider_mistral.NewMistralProvider(llm_provider_mistral.Config{
APIKey: os.Getenv("MISTRAL_API_KEY"), // required
BaseURL: "", // empty for https://api.mistral.ai
DefaultModel: "mistral-large-latest", // optional; package default if empty
DefaultEmbeddingModel: "mistral-embed", // optional; package default if empty
EmbeddingDimensions: 0, // 0 = use the model's default (1024)
})
if err != nil {
return err
}
Config.Validate() rejects missing API keys at construction time. Config.WithDefaults() fills DefaultModel, BaseURL, DefaultEmbeddingModel, and EmbeddingDimensions when zero.
Bootstrap
ssr := piko.New(
piko.WithLLMProvider("mistral", provider),
piko.WithDefaultLLMProvider("mistral"),
)
This single registration also covers embeddings. Piko auto-detects embedding support from a completion provider that implements EmbeddingProviderPort, so the Mistral provider needs no separate WithEmbeddingProvider call. Add one only to route embeddings to a different provider.
See also
Other LLM providers:
- Anthropic Claude, long-context, strong tool use.
- OpenAI, widest model selection, native structured-output API.
- Gemini, cheapest competent option, multimodal-native.
- Grok, xAI provider.
- Ollama, local inference (can serve Mistral's open weights).
- Voyage, embeddings-only specialist.
Framework docs:
- How to use LLMs, embeddings, and RAG, wiring the LLM service end-to-end.
- LLM API reference, every type and method on the LLM service.
External:
- Mistral API documentation, authoritative reference.
- Mistral open weights, checkpoint downloads for self-hosting.