← All code samples

SRE → investigate alert

Start an SRE Copilot investigation from an alert that already exists in the SRE app, then poll until the investigation record has RCA fields. Requires the SRE app installed on the project and an API token.

Step What the SDK does
1. List or get alert GET /app/sre/api/v1/alerts or GET /app/sre/api/v1/alerts/{id}
2. Investigate POST /app/sre/api/v1/alerts/{id}/investigate (returns immediately)
3. Poll GET /app/sre/api/v1/investigations/{id} until status is terminal
4. Optional Use guild_session_id with Aiden artifact/export APIs for the session file

Prefer this path when the alert is already in Copilot and you want the investigation record plus structured RCA. Use Ask → artifact when you only have a free-text prompt and no SRE alert id.

Minimal — list, investigate, poll

import time

from stackgen import StackgenClient, StackgenConfig

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

alerts = client.sre.list_alerts(status="active", q="checkout CPU")
items = alerts.get("items") or []
alert_id = items[0]["id"]

started = client.sre.investigate_alert(
    alert_id,
    body={"operator_message": "Investigate checkout CPU in prod"},
)
inv_id = started["investigation"]["id"]

while True:
    inv = client.sre.get_investigation(inv_id)
    status = inv.get("status")
    if status in ("completed", "failed", "cancelled", "error"):
        break
    time.sleep(5)

print(inv.get("result_summary"))
print(inv.get("guild_session_id"))

Notes

Related: Automation surface · Ask → artifact