You are an AI coding agent building a Trio REST API integration.
Sources of truth:
- OpenAPI schema: docs/openapi.json (repo) or /openapi.json (published). Do not invent fields.
- Base URL: https://trio.machinefi.com/api
- Error handling: /guides/debugging
Deliverables:
1) Typed API client with auth + JSON support.
2) Endpoint wrappers:
- POST /streams/validate
- POST /prepare-stream?url=...
- POST /check-once
- POST /live-monitor
- POST /live-digest
- GET /jobs
- GET /jobs/{job_id}
- DELETE /jobs/{job_id}
3) Workflow functions:
- Preflight: validate_stream -> optional prepare_stream
- Sync check: check_once (returns triggered/explanation/latency)
- Async monitor: live_monitor -> poll_job_until_terminal -> optional cancel_job
- Async digest: live_digest -> webhook/SSE if configured; otherwise poll like monitor
4) Error handling:
- parse error response shape: { "error": { "code", "message", "remediation" } }
- handle 400/404/422/429 with actionable messages; treat JOB_NOT_FOUND as terminal
5) Tests:
- success path: validate -> live-monitor -> poll to terminal (mocked)
- success path: check-once returns triggered/explanation/latency (mocked)
- failure path: validate fails (INVALID_URL or NOT_LIVESTREAM)
Request details (from OpenAPI):
- ValidateStreamRequest: { stream_url }
- Prepare Stream: query param url (required)
- CheckOnceRequest: { stream_url, condition, input_mode, clip_duration_seconds, include_frame }
- LiveMonitorRequest: { stream_url, condition, interval_seconds, input_mode, clip_duration_seconds, enable_prefilter, webhook_url }
- LiveDigestRequest: { stream_url, window_minutes, capture_interval_seconds, include_frames, max_windows, webhook_url }
- Job status enum: pending | running | stopped | completed | failed
Constraints:
- Use Authorization: Bearer <API_KEY> and Content-Type: application/json
- Add request timeouts; retry/backoff only on 429 or transient network errors
- Emit structured logs for each step (validate, prepare, check, start, poll, cancel)
- Return clean, typed results for client callers
Output:
- Provide usage examples for the client and workflows.