Recipe

Prefect primer

A focused walk through orchestrating Meridian-powered LLM workflows with Prefect 2.x. You will wire flows, tasks, and result persistence so a single command kicks off a deterministic, observable pipeline against the Meridian gateway at llm.getnimbus.net.

1.Install and configure

Install Prefect alongside the Meridian SDK. Both work in any 3.10+ environment. Set the gateway base URL and your Meridian key once at the process level so every flow run inherits the same credentials.

pip install prefect meridian-sdk openai
export MERIDIAN_API_KEY="mer_live_..."
export MERIDIAN_BASE_URL="https://llm.getnimbus.net/v1"
prefect server start &

2.Define a flow

Wrap each gateway call in a Prefect @task so retries, caching, and timeouts stay declarative. Compose tasks inside a @flow for parallelism and run-state visibility in the UI.

from prefect import flow, task
from openai import OpenAI

client = OpenAI(base_url="https://llm.getnimbus.net/v1")

@task(retries=3, retry_delay_seconds=5)
def summarize(text: str) -> str:
    resp = client.chat.completions.create(
        model="azure/model-router",
        messages=[{"role": "user", "content": f"Summarize: {text}"}],
        max_tokens=2048,
    )
    return resp.choices[0].message.content

@flow(name="meridian-summary-pipeline")
def pipeline(docs: list[str]) -> list[str]:
    return [summarize.submit(d).result() for d in docs]

3.Schedule and observe

Deploy the flow with a cron schedule, then browse runs in the Prefect UI. Pair this with Meridian usage logs to attribute spend per flow run. Failures retry automatically; successful results cache to the local Prefect store.

prefect deploy pipeline.py:pipeline \
  -n nightly-summary \
  --cron "0 3 * * *" \
  --pool default-agent-pool

prefect worker start --pool default-agent-pool