Skip to main content Switch to mobile version django-ai-gateway 0.0.2 A self-hosted LLM gateway, built in Django.
pip install django-ai-gateway Copy PIP instructions
A self-hosted LLM gateway, built in Django. SDK · SDK on PyPI · Studio · Docs Project status: read this first
This is an alpha. Here's what that means for you:
Expect breaking changes. APIs will shift as we find better patterns.
Migrations might be reset. Don't rely on database schema stability between versions.
Not for production. Use this for experimentation, prototypes, and side projects. Keep critical workloads elsewhere.
Watch the repo. Things change quickly. Star & watch to stay in the loop.
Your feedback shapes the gateway. Break things, open issues, tell us what hurts.
We'd love to have you along for the ride, just keep your seatbelt on.
Each project gets one virtual key. Apps send every model call to one URL with that key, in the API style they already use: OpenAI, Anthropic or Ollama. The gateway:
sends the call to the project's active provider, such as OpenAI, Anthropic, OpenRouter, a local Ollama or any API with one of those styles, with the project's own key for that provider;
streams the reply back unchanged;
maps model aliases, so pony-xs can mean a different model name on each provider;
limits each project's open streams, requests per minute, and tokens per day and month;
records every call's model, tokens, status and duration.
Switching a project to another provider is one choice in the dashboard. The proxy uses the new provider within a second, and the apps change nothing.
The dashboard is a set of Django pages for providers, projects, keys, limits and usage. Only active staff users can sign in, and by default they need a passkey or an authenticator app.
You need uv and just.
cp demo/.env.example demo/.env # then fill in SECRET_KEY and GATEWAY_FERNET_KEYS just migrate uv run python demo/manage.py createsuperuser just serve # the proxy on http://localhost:8080 just dashboard # the dashboard on http://localhost:8000, in a second terminal Generate the two values with:
uv run python -c "from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())" uv run python -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())" With Docker instead, after the same demo/.env:
docker compose -f compose.yaml up -d --build docker compose -f compose.yaml exec dashboard python demo/manage.py createsuperuser That runs the proxy on 127.0.0.1:8080 and the dashboard on 127.0.0.1:8000, with the SQLite database in a Docker volume.
Behind portside, just up serves the proxy at https://inference.gateway.test and the dashboard at https://admin.gateway.test. Once, run just certs and add 127.0.0.1 gateway.test inference.gateway.test admin.gateway.test to /etc/hosts.
Then sign in, add a passkey, add a provider and a project, and copy the project's virtual key. The quick start walks through each step.
Point your app at it
Change the base URL and the key. Nothing else.
django-ai-sdk, for the OpenAI generators:
OPENAI_API_URL=https://inference.gateway.test/v1 OPENAI_API_KEY=
from openai import OpenAI client = OpenAI(base_url="https://inference.gateway.test/v1", api_key="
from anthropic import Anthropic client = Anthropic(base_url="https://inference.gateway.test", api_key="
curl https://inference.gateway.test/v1/chat/completions \ -H "Authorization: Bearer
The gateway is a Django app, django_ai_gateway. To host it, make a Django project that installs the package, as demo/ does:
pip install django-ai-gateway Copy demo/settings.py, demo/urls.py and demo/asgi.py as a starting point. They add django_ai_gateway to INSTALLED_APPS next to allauth, allauth MFA and axes (demo/auth.py holds the sign-in rules), set every GATEWAY_* setting, and include the dashboard with include("django_ai_gateway.urls"). The app's tables start with gateway_.
The project runs as two processes with the same settings and database:
The proxy, the gateway command, is an aiohttp server for the model calls. It reads its configuration from a copy in memory, never from the database during a call. It checks for changes once a second and writes usage in the background.
The dashboard, uvicorn demo.asgi:application, serves the gateway's own pages. There is no Django admin.
Run one proxy process. The limits are counted in its memory, and a second process would need shared counters first.
Self-hosting covers the Docker image, the database and a production checklist.
The dashboard has these pages:
Overview: calls, tokens and failed calls over 24 hours, 7 days or 30 days.
Projects: each project's connected providers and their keys, the active provider, limits, virtual key and usage.
Providers: endpoints and model aliases. Only superusers can change them.
Usage: every call, filtered by project, provider, model and status code.
Passkeys and 2FA: the signed-in user's passkeys, authenticator app and recovery codes.
What a staff user sees and changes follows Django's model permissions on the gateway models. Provider keys are write-only. Every change is written to the gateway.audit logger.
Users are managed on the command line: manage.py createsuperuser, manage.py changepassword
The templates use Basecoat with Tailwind 4. The built stylesheet and Basecoat's scripts are committed in src/django_ai_gateway/static/gateway/, so neither Docker nor the server needs Node. After you change classes in a template, rebuild the stylesheet with just css, which needs pnpm. CI fails when the committed stylesheet is out of date. Dark mode follows the system until the toggle sets a theme cookie.
Required: SECRET_KEY, unless DEBUG is on, and GATEWAY_FERNET_KEYS, the Fernet keys that encrypt provider keys, newest first.
gateway reads DJANGO_SETTINGS_MODULE like any Django tool, and also GATEWAY_HOST, GATEWAY_PORT, GATEWAY_TLS_CERT and GATEWAY_TLS_KEY.
Commands: issue_virtual_key
Virtual keys are stored as SHA-256 hashes. The dashboard shows a new key once. A new key replaces the old one within a second.
Provider keys are encrypted with Fernet. To rotate the Fernet key, put the new key first in GATEWAY_FERNET_KEYS for both the proxy and the dashboard and restart them, run rotate_keys, then remove the old key. rotate_keys refuses to run while any stored key cannot be decrypted.
The proxy drops the app's key, cookies and forwarding headers before a call leaves, adds the provider key, and refuses compressed bodies and paths with dot segments or encoded slashes. It does not store request or reply bodies. Endpoints must use https, except for GATEWAY_PLAIN_HTTP_HOSTS.
Sign-in is django-allauth with passkeys, authenticator apps and recovery codes. Five failed passwords lock that username and IP address for an hour (django-axes, manage.py axes_reset). Sessions end when the browser closes.
Passkeys belong to one host name. Use http://localhost:8000, not 127.0.0.1, for local passkeys.
Containers run as a user without root rights, on a read-only file system, and publish ports on 127.0.0.1 only.
Security has the sign-in steps, what to do when a user loses every factor, and the full list of what the proxy forwards.
src/django_ai_gateway/ the package: models, proxy, dashboard, templates, static files, commands demo/ the example project: settings, sign-in (allauth, MFA, axes), manage.py, Dockerfile tests/ pytest, with tests/settings.py frontend/ Tailwind source for the dashboard stylesheet docs/ the documentation, built with dokk just lists every recipe. The main ones:
just hooks installs prek, which runs the hooks in .pre-commit-config.yaml on each commit: gitleaks on the staged changes, djLint on the templates, ruff check and format, and ty.
Plans and design notes are in plans/index.html.
Released: Dec 2, 2026
Author: terminalkitten
Both files in this release have provenance metadata.
View provenance details
BSD-3-Clause View SPDX License List
django llm llm-gateway ai-gateway proxy openai anthropic ollama
Development Status 3 - Alpha
Environment Web Environment
Intended Audience Developers
Natural Language English
Operating System OS Independent
Programming Language Python :: 3 :: Only
Topic Internet :: Proxy Servers
Scientific/Engineering :: Artificial Intelligence
Release files for django-ai-gateway 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
Built distribution (wheel)
Total release size: 847.6 kB
Release files / django_ai_gateway-0.0.2.tar.gz
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.
Release files / django_ai_gateway-0.0.2-py3-none-any.whl
Security for django-ai-gateway 0.0.2
Both files in this release have been uploaded with provenance metadata.
With provenance django_ai_gateway-0.0.2.tar.gz Dec 2, 2026
Attestation for django_ai_gateway-0.0.2.tar.gz
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.
Release history Release notifications | RSS feed
Dec 2, 2026 2 release files Full provenance
"PyPI", "Python Package Index", and the blocks logos are registered trademarks of the Python Software Foundation.
© 2026 Python Software Foundation
Deployed from 1875753











