Recipe

Starlette Primer

A lean, ASGI-native foundation for shipping Meridian-backed AI services. Starlette gives you routing, middleware, and async I/O without the weight of a full framework — perfect for the gateway sidecars and streaming proxies that fan out to the Meridian model pool.

1. Why Starlette for Meridian

Meridian endpoints are streaming-heavy and latency-sensitive. Starlette is pure ASGI, which means it pairs cleanly with httpx.AsyncClient upstream and Server-Sent Events downstream. There is no synchronous-context tax, no thread pool to tune, and no hidden buffering between your route handler and the wire.

2. A minimal app

The whole surface area you need for a first sidecar is three imports and a route table. Drop this into app.py and run with uvicorn app:app --reload.

from starlette.applications import Starlette
from starlette.responses import JSONResponse
from starlette.routing import Route

async def homepage(request):
    return JSONResponse({'hello': 'world'})

async def echo(request):
    body = await request.json()
    return JSONResponse({'echo': body})

routes = [
    Route('/', homepage),
    Route('/echo', echo, methods=['POST']),
]

app = Starlette(debug=True, routes=routes)

3. Wiring it to Meridian

From a Starlette handler, forward the incoming JSON body to https://llm.getnimbus.net/v1/chat/completions with your Meridian key. For streaming, return a StreamingResponse that iterates the upstream chunks as they arrive — no buffering, no reframing. The full SSE relay recipe lives in the streaming docs.