← All code samples

Async webhook CI (submit + poll)

Use this pattern when trigger and poll run in different workers (message queue, shared task store, cron scheduler). Each call is stateless — no blocking journey.

Flow

  1. Worker Atrigger_webhook(payload) → persist webhook_id, invocation_id, optional session_id
  2. Worker B — if no session_id, wait_for_webhook_session(...) or get_webhook_run(...)
  3. Worker Blist_session_artifacts / download_session_artifact when ready

Trigger worker

from stackgen import StackgenClient, StackgenConfig

client = StackgenClient(
    StackgenConfig(
        base_url="https://app.stackgen.com",
        api_token="stackgen_…",
        webhook_token="sg_aios_…",
        org_id="<project-uuid>",
    )
)

trigger = client.aiden.trigger_webhook(alert_body)
# Persist to queue / DB:
# trigger["webhook_id"], trigger["invocation_id"], trigger.get("session_id")

Scheduler worker

session_id = stored_session_id or client.aiden.wait_for_webhook_session(
    webhook_id,
    invocation_id,
    dispatch_run_id=trigger_run_id,
)

artifacts = client.aiden.list_session_artifacts(session_id)
path = client.aiden.download_session_artifact(
    session_id,
    "session-report.md",
    "session-report.md",
)

When to use the blocking journey instead

Single CI script that triggers and waits in one process: run_webhook_and_download_report. It implements the same dual-path logic internally.

Related: Webhook → session → artifact, Network egress.