-
Notifications
You must be signed in to change notification settings - Fork 0
feat: implement RFC 9457 structured error responses for API #419
Copy link
Copy link
Labels
prio:mediumShould do, but not blockingShould do, but not blockingscope:medium1-3 days of work1-3 days of workspec:human-interactionDESIGN_SPEC Section 13 - Human Interaction LayerDESIGN_SPEC Section 13 - Human Interaction Layertype:featureNew feature implementationNew feature implementation
Description
Summary
Replace plain-string API error responses with machine-actionable structured errors following RFC 9457 (Problem Details for HTTP APIs). Enables agent consumers to programmatically determine retry behavior.
Motivation
From Cloudflare's RFC 9457 implementation for AI agents: when AI agents consume APIs, they need machine-readable error metadata (is this retryable? how long to wait? what category of error?). Current ApiResponse(error=<plain string>) with no structured metadata forces agents to parse error strings.
Design
Phase 1 (M7) — Core Fields
Add to error responses:
retryable(bool) — can the request be retried?retry_after(int, seconds) — how long to wait before retryingerror_code(int) — internal error codeerror_category(str enum) —auth,validation,not_found,conflict,rate_limit,budget_exhausted,provider_error,internalinstance(str) — correlation ID from observability (near-free, already exists)
Phase 2 (M8+) — Full RFC 9457
application/problem+jsoncontent typetypeURI linking to error documentation- Content negotiation middleware via
Acceptheader title(human summary) +detail(occurrence-specific)
Affected Files
src/ai_company/api/errors.py(error hierarchy + category enum)src/ai_company/api/exception_handlers.py(structured response generation)src/ai_company/api/dto.py(response model update)
Research
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
prio:mediumShould do, but not blockingShould do, but not blockingscope:medium1-3 days of work1-3 days of workspec:human-interactionDESIGN_SPEC Section 13 - Human Interaction LayerDESIGN_SPEC Section 13 - Human Interaction Layertype:featureNew feature implementationNew feature implementation