Skip to main content

Prerequisites

  • Python 3.10+
  • A StewAI API key
  • A published recipe ID

1. Install

pip install stewai

2. Create a run

from stewai import Client

client = Client(api_key="your-api-key")

run = client.runs.create(
    recipe_id="01JEXAMPLE00000000000000000",
    inputs={"topic": "AI safety"},
)

print(run["id"], run["status"])
create() waits by default (wait=True) until the run reaches a terminal status.

3. Read step results

trace = client.runs.steps(run["id"])

for step in trace["steps"]:
    print(step["id"], step["kind"], step["status"])
    print(step["output_flat"])
In v1, step payloads are returned as output_flat.

4. Handle failures

from stewai import (
    RunFailedError,
    RunCancelledError,
    RunBlockedError,
    StewAITimeoutError,
)

try:
    run = client.runs.create(recipe_id="01JEXAMPLE00000000000000000", timeout=120)
except RunFailedError as e:
    print("run failed", e.run_id)
except RunCancelledError as e:
    print("run cancelled", e.run_id)
except RunBlockedError as e:
    print("run blocked", e.run_id)
except StewAITimeoutError as e:
    print("timed out", e.run_id, e.last_status)

5. Close the client

client.close()
Or:
from stewai import Client

with Client(api_key="your-api-key") as client:
    run = client.runs.create(recipe_id="01JEXAMPLE00000000000000000")

Next steps