FastAPI primer
FastAPI is a modern Python framework for building HTTP APIs on top of Starlette and Pydantic. This primer walks you through a minimal Meridian-compatible backend in three steps: install, define routes, and connect to the Meridian gateway for LLM calls.
1Install and scaffold
FastAPI ships as a pip package, and we use uvicorn as the ASGI server during development. The snippet below gives you a working /items endpoint with automatic request validation via Pydantic.
# Install FastAPI and an ASGI server
pip install fastapi uvicorn
# main.py
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI(title="Meridian Demo")
class Item(BaseModel):
name: str
price: float
@app.get("/")
def root():
return {"status": "ok"}
@app.post("/items")
def create_item(item: Item):
return {"received": item}
# Run it
# uvicorn main:app --reload --port 80002Wire the Meridian gateway
From a FastAPI handler, call the Meridian gateway like any OpenAI-compatible endpoint. Set base_url to https://llm.getnimbus.net/v1 and pass your Meridian API key. Model routing is handled server-side, so you can use azure/model-router and let Meridian pick the cheapest capable model.
3Deploy
For production, run uvicorn behind a process manager (systemd, supervisor) or ship in a container. FastAPI emits an OpenAPI schema at /docs, which is handy when you wire it into Meridian tool-calling. For zero-config hosting, push the image to Azure Container Apps with a single revision and set the gateway key as an environment variable.