Self-hosting

Self-hosting

Run the Kaimei API on your own infrastructure, against SQLite on a laptop or Postgres for a team.

The API is a FastAPI service and runs anywhere Python 3.9 does, against SQLite for a laptop or Postgres (Supabase works) for a team. Enterprise plans include a private deployment; the configuration below applies to any installation.

Configuration is through KAIMEI_* environment variables or a .env file in the working directory. The ones that matter most:

VariableDefaultMeaning
KAIMEI_DATABASE_URLsqlite:///./kaimei.dbSQLAlchemy URL. Postgres in production.
KAIMEI_SECRET_KEY(dev value)HMAC key for session tokens. At least 32 random bytes; always set it.
KAIMEI_ENVdevelopmentproduction turns email verification on by default; test turns rate limits and quotas off.
KAIMEI_PUBLIC_API_URL / KAIMEI_DASHBOARD_URLlocalhostUsed for OAuth callbacks, verification links and CORS.
KAIMEI_ALLOW_SIGNUPtrueSet false for an invite-only installation.
KAIMEI_MAX_REFERENCE_ROWS5000Reference rows kept per model.
KAIMEI_EXPLANATION_EVAL_BUDGET60000Soft ceiling on model evaluations per explanation.
KAIMEI_IMAGE_EXPLAIN_SECONDS40Time budget image explanations plan their grid to fit.
KAIMEI_MAX_TENSOR_BYTES536870912Largest single binary tensor upload, compressed.
KAIMEI_REMOTE_INFERENCE_TIMEOUT_S30Default timeout for remote endpoints.
KAIMEI_BEHIND_CLOUDFLARE / KAIMEI_TRUST_PROXYfalseRead the client IP from CF-Connecting-IP / X-Forwarded-For for rate limits.
KAIMEI_TURNSTILE_* , KAIMEI_SMTP_*, KAIMEI_GOOGLE_* , KAIMEI_GITHUB_*unsetBot protection on sign-up, verification email, OAuth sign-in.

Point the Python client at your installation with base_url or KAIMEI_BASE_URL; the dashboard with VITE_API_URL.

shell
pip install -e ".[dev]"                 # from the kaimei API repository
kaimei-api init-db                      # create tables
kaimei-api seed-demo                    # [email protected] / kaimei-demo, five reference models, an API key
kaimei-api serve --reload               # http://localhost:8000, interactive docs at /docs
kaimei-api openapi -o openapi.json      # the OpenAPI schema

# Postgres / Supabase
pip install -e ".[postgres]"
export KAIMEI_DATABASE_URL=postgresql://postgres.[ref]:[password]@aws-0-[region].pooler.supabase.com:5432/postgres
kaimei-api migrate-db --inspect         # row counts in the local SQLite file
kaimei-api migrate-db                   # copy it over