How mozilla-ai/otari works
Otari is a self-hosted, OpenAI-compatible LLM gateway with standalone, hosted, and hybrid deployment modes. Its principal workflow accepts a client inference request, authenticates it, checks budget and guardrails, dispatches to a model provider (optionally through tools), settles the reservation, and records usage. The repository also includes management APIs and a dashboard for keys, providers, routing, budgets, and usage, plus optional tool and file capabilities. The graph follows documented flows and sampled wiring; unsampled subsystem links are omitted rather than inferred.
Main entry points: _pipeline.py Inference pipeline · main.py Management APIs · _tool_loop.py Tool execution · database.py Relational database
Components 24
Request handling
- API router
src/gateway/api/main.py - Inference pipeline
src/gateway/api/routes/_pipeline.py - Credential authentication
src/gateway/api/deps.py
Inference operations
- Budget enforcement
src/gateway/services/budgets/_service.py - Inference guardrails
src/gateway/services/guardrails.py - Model routing
src/gateway/services/routing/_service.py - Model provider port
src/gateway/ports/model_provider_port.py - Model providers
src/gateway/adapters/model_provider_adapter.py
Management and identity
- Admin dashboard
web/src/app/App.tsx - Management APIs
src/gateway/api/main.py - OAuth sign-in
src/gateway/services/oauth_service.py - Virtual API keys
src/gateway/services/api_keys/_service.py
State and metering
- Usage settlement
src/gateway/services/inference/_stream_cost.py - Usage log writer
src/gateway/services/log_writer.py - Relational database
src/gateway/core/database.py - Unit of work
src/gateway/core/unit_of_work.py - Domain models
src/gateway/models/tenancy.py
Tools and integrations
- Tool execution
src/gateway/services/_tool_loop.py - Search and fetch
src/gateway/services/search_backend.py - Code execution
src/gateway/services/code_execution/containers.py - File understanding
src/gateway/ports/file_storage_port.py
Other components
- Client application
- Model response
- Tool services
Connections 24
- Client application → API router: sends request
README.md - API router → Inference pipeline: routes inference
- API router → Management APIs: registers routes
src/gateway/api/main.py - Inference pipeline → Credential authentication: authenticates
src/gateway/api/routes/_pipeline.py - Inference pipeline → Budget enforcement: checks budget
src/gateway/api/routes/_pipeline.py - Inference pipeline → Inference guardrails: applies guardrails
src/gateway/api/routes/_pipeline.py - Inference pipeline → Tool execution: dispatches optionally
src/gateway/api/routes/_pipeline.py - Inference pipeline → Model provider port: dispatches request
README.md - Model provider port → Model providers: adapts provider calls
- Model providers → Model response: returns completion
README.md - Inference pipeline → Model response: returns response
- Inference pipeline → Usage settlement: settles spend
src/gateway/api/routes/_pipeline.py - Inference pipeline → Usage log writer: records usage
src/gateway/api/routes/_pipeline.py - Usage settlement → Relational database: persists settlement
- Usage log writer → Relational database: writes usage
- Unit of work → Relational database: commits transactions
src/gateway/core/unit_of_work.py - Admin dashboard → Management APIs: manages gateway
README.md - Management APIs → Virtual API keys: manages credentials
- Management APIs → OAuth sign-in: supports sign-in
- Tool execution → Search and fetch: dispatches search
- Tool execution → Code execution: dispatches execution
- Tool execution → Tool services: calls integrations
- Inference pipeline → File understanding: uses file capability
- Management APIs → Domain models: manages domain state