Skip to main content
This document covers the multimind.gateway package: its configuration, model handlers, chat sessions, monitoring, and the FastAPI app in multimind.gateway.api. It requires the gateway extra:

Table of Contents

Core Components

Configuration

The gateway reads its settings from environment variables (a .env file in the working directory is loaded automatically via python-dotenv) into a GatewayConfig instance:
Each provider section is a ModelConfig with api_key, api_base, model_name, temperature (0.7), max_tokens (None) and timeout (30). GatewayConfig validates on construction that DEFAULT_MODEL names a known provider.

Configuration Options

Model Handlers

Getting a Model Handler

Accepted names: openai, anthropic, ollama, huggingface (dedicated handlers exported from multimind.gateway as OpenAIHandler, AnthropicHandler, OllamaHandler, HuggingFaceHandler) and claude, groq, gemini, mistral, deepseek, openrouter, together, xai, perplexity, fireworks, cerebras (wrapped SDK model classes). Unknown names raise ValueError.

Model Handler Interface

Chat Session Management

Chat Manager

Chat Session

Monitoring and Metrics

Model Monitor

Metrics Structure

Metrics are in-process only; they reset when the server restarts.

CLI Interface

The gateway’s CLI moved to multimind.cli (the multimind entry point; multimind.gateway.cli is a thin alias). The relevant commands are:
Full option lists: cli.md.

REST API

Running the server

multimind backend honours MULTIMIND_BACKEND_HOST / MULTIMIND_BACKEND_PORT and, when API_KEYS is set (comma-separated), requires an X-API-Key header on every route except /, /health, /ready and the docs pages. The standalone gateway app has no authentication of its own. Model-backed endpoints depend on at least one provider being configured (an API key, or OLLAMA_API_BASE); otherwise they return 503 "No models are properly configured". A model that is requested but not configured returns 400 "Model <name> is not available". The generated spec is in openapi-gateway.json (and openapi-platform.json for the combined app).

Endpoints

System

Chat

model defaults to DEFAULT_MODEL. Message objects may also carry model and metadata fields; they are ignored by this endpoint.

Generate

Compare

models defaults to ["openai", "anthropic", "ollama"]; models that are not configured are skipped (logged, not errored).

Sessions

POST /v1/sessions/{id}/messages appends the message, sends the whole session history to the session’s model, stores the assistant reply (with usage in its metadata) and returns it in the response. If the provider call fails the endpoint returns 502 "Model request failed". Unknown session IDs return 404 "Session not found". Sessions live in memory until saved: POST /v1/sessions/{id}/save writes chat_<id>.json to the ChatManager storage directory (chat_sessions/ by default) and POST /v1/sessions/load reads it back (returning the in-memory session if it is already active). Both return 404 for an unknown session ID, matching multimind chat save / multimind chat load.

Metrics and Health

Compliance

multimind.gateway.compliance_api mounts a router at /v1/compliance (included in both the gateway app and the combined API):
Request/response models are in the OpenAPI spec. Unknown regulation names return 400.

Error Responses

Errors use FastAPI’s standard shape:
Status codes used by the gateway:
  • 400: requested model is not configured, or the request is malformed
  • 404: chat session not found
  • 422: request body failed validation (FastAPI’s default; detail is a list of field errors)
  • 502: the model provider call failed while adding a session message
  • 503: no model provider is configured at all
  • 500: unexpected server error (details are logged, not returned)

Examples

For complete working examples, see: