---
estimated_steps: 1
estimated_files: 5
skills_used: []
---

# T01: PipelineEvent model, migration, and event capture in pipeline stages

Add PipelineEvent DB model (video_id, stage, event_type, payload JSONB, token counts, created_at). Alembic migration 004. Instrument LLM client to persist events (token usage, response content) per-call. Instrument each stage to emit start/complete/error events.

## Inputs

- `backend/models.py`
- `backend/pipeline/llm_client.py`
- `backend/pipeline/stages.py`

## Expected Output

- `backend/models.py (PipelineEvent model)`
- `alembic/versions/004_pipeline_events.py`
- `backend/pipeline/llm_client.py (event persistence)`
- `backend/pipeline/stages.py (stage event emission)`

## Verification

docker exec chrysopedia-api python -c 'from models import PipelineEvent; print(OK)' && docker exec chrysopedia-api alembic upgrade head
