Skip to main content

Generations

Generation records track individual LLM generation runs started by agents, including their lifecycle status and any failure details.

Overview

Every agent generation (POST /agents/:id/generate, session generation, sub-agent calls) creates a generation record before the model is called. The record tracks the run through its lifecycle and — when the run fails — stores a structured error payload so failed generations are distinguishable from pending ones and can be debugged post-mortem.

Generation IDs for a trace can be listed via GET /traces/:trace_id/generations, and each record can be retrieved via GET /generations/:generation_id.

See the Permissions Reference for the IAM action strings for this module.

Data Model

FieldTypeDescription
idstringPublic identifier for the generation
project_idstringProject the generation belongs to
agent_idstringAgent that ran the generation
trace_idstringTrace this generation belongs to
initiator_generation_idstring | nullGeneration that triggered this one via a sub-agent call; null for top-level generations
started_by_principal_typestring | nullType of the principal that started the generation
started_by_principal_idstring | nullID of the principal that started the generation
statusstringLifecycle status: in_progress, requires_action, completed, or failed
started_atstringWhen the generation started
completed_atstring | nullWhen the generation reached a terminal state
last_activity_atstring | nullLast activity timestamp
stop_reasonstring | nullWhy the generation stopped (e.g. stop, error, depth_guard)
errorobject | nullStructured error payload recorded when the generation failed (see Error Recording)
created_atstringISO 8601 creation timestamp
updated_atstringISO 8601 last-update timestamp

Key Concepts

Lifecycle

A generation starts as in_progress. It transitions to:

  • requires_action when a client tool call pauses the run and the caller must submit tool outputs.
  • completed when the model finishes (the stop_reason carries the finish reason).
  • failed when the run errors — for example when the upstream AI provider returns an error or is unreachable. stop_reason is set to error and the error field carries the failure details.

Error Recording

When a generation fails, the failure is persisted on both the generation record and its trace:

{
"id": "gen_abc123",
"status": "failed",
"stop_reason": "error",
"error": {
"code": "AI_PROVIDER_ERROR",
"message": "Provider returned 402: insufficient credits"
}
}

The error object always contains message. code is set for mapped errors — most notably AI_PROVIDER_ERROR, which is used when the upstream AI provider returns an error (e.g. exhausted credits, rate limit) or is unreachable.

Provider Error Surfacing (AI_PROVIDER_ERROR)

Generation endpoints return HTTP 502 with the AI_PROVIDER_ERROR code when the upstream AI provider fails:

{
"error": {
"code": "AI_PROVIDER_ERROR",
"message": "Provider returned 402: insufficient credits",
"meta": {
"provider_status_code": 402,
"generation_id": "gen_abc123",
"trace_id": "trace_xyz789"
}
}
}

The meta field includes the generation_id and trace_id of the failed run so the failure can be inspected post-mortem via GET /generations/:generation_id and GET /traces/:trace_id.

Internal Metadata

Generation records carry internal coordination state (e.g. pending tool-call context used to resume requires_action runs). This state is not exposed through the API.