Skip to main content
Task-oriented recipes. Each one is self-contained and copy-paste runnable. New here? Do the quickstart first. Contents:

Switch providers with one line

Every provider implements the same interface — swap the constructor, nothing else changes.
Check which keys are configured (offline, no calls made):

Sync usage (no asyncio)

Every model has generate_sync, chat_sync, and embeddings_sync:
Inside an already-running event loop (Jupyter, FastAPI handlers), use the async methods instead.

Structured output with Pydantic

Pass a Pydantic class as response_format and get an instance back, not a string:
Works with OpenAIModel, ClaudeModel, GeminiModel, MistralAIModel, GroqModel, and DeepSeekModel.

PII-guard any model

guard() wraps a model so PII is redacted before it reaches the provider, blocked types raise, and every event lands in a JSONL audit trail:
The guard is duck-typed: anything with an async generate (and optionally chat / generate_stream) can be wrapped — including clients that are not MultiMind models:
Detects emails, phones, SSNs, credit cards (Luhn-validated), IPs, IBANs, passports, dates of birth, and API keys (entropy-checked) — including across streaming chunk boundaries. Stdlib-only, no extra dependencies.

Budget-capped calls

Budget enforces a hard spending ceiling — the call past the limit is blocked before it is dispatched:
A warning is logged at 80% of the ceiling (tune with warn_ratio). Offline demo that runs with no API key: examples/observability/cost_tracking.py.

Detect hallucinations in RAG answers

Wrap the generating model so every answer is grounding-checked against the retrieved sources. The default check is lexical (deterministic, offline, no judge LLM needed):
With sources=callable, sources are fetched per prompt — plug in your retriever for RAG. on_flag="retry" regenerates once with a strict grounding instruction. For a score without wrapping anything:
Offline end-to-end demo: examples/evaluation/hallucination_detection.py.

Switch models mid-conversation without losing knowledge

Start a conversation on one provider, move to another — the context travels with you.
Strategies: "full" (replay raw history, zero loss), "summary" (compact — best for long chats crossing context limits), "adapted" (provider-specific formatting). With max_history_tokens=... long conversations are compacted automatically. Composes with guard(...) and track_costs(...) wrappers. Runnable demo: examples/context_transfer/model_switching.py

Agents that spawn sub-agents (bounded)

The coordinator decides at runtime whether to answer, delegate, or create a new sub-agent for a subtask — inside hard safety bounds.
Pass budget_tracker= (a multimind.observability Budget-backed tracker) to cap spend across the whole agent tree, and audit_hook= to log every spawn/delegate event. Runnable demo: examples/agents/self_orchestrating_agent.py

Run the gateway API

Expose chat, generation, and model comparison over HTTP:
Then:
Provider keys are read from the environment at request time; a request naming an unconfigured model returns 400 with a clear error (503 if no provider at all is available).

Fully local stack with docker compose

Gateway plus Ollama, no API keys, nothing leaves your machine:
Swagger UI is at http://localhost:8000/docs. Models persist in the ollama_models volume. Full container reference (env vars, health checks, production notes): deployment guide.