Django Primer
A focused primer for wiring Meridian into a Django backend. This recipe walks through project layout, installing the SDK, and shipping your first AI-powered view without rewriting your stack. Read top to bottom or jump to the section you need.
1.Project setup
Start from a fresh virtualenv. Meridian targets Django 4.2+ and Python 3.10+. Pin the SDK inrequirements.txtso deploys stay reproducible across staging and prod.
python -m venv .venv source .venv/bin/activate pip install django meridian-sdk django-admin startproject mysite cd mysite && python manage.py startapp ai
2.Configure the client
Add your Meridian API key to environment variables and build a singleton client in your app config. Avoid instantiating the client per-request — connection reuse keeps p95 latency well under 200ms on the gateway.
- Store the key in
MERIDIAN_API_KEY - Initialize in
AppConfig.ready() - Expose through Django settings
3.Your first view
With the client live, a view becomes a thin wrapper around client.chat(). Stream tokens back with Django's StreamingHttpResponse for interactive UX, or return JSON for backend pipelines.
from django.http import JsonResponse
from meridian import Meridian
client = Meridian()
def summarize(request):
text = request.GET.get("q", "")
out = client.chat(
model="azure/model-router",
messages=[{"role": "user", "content": text}],
)
return JsonResponse({"reply": out.content})