{
  "id": 23915626,
  "title": "Designing API Errors Agents Can Recover From",
  "url": "https://urgent.news/2026/12/06/designing-api-errors-agents-can-recover-from",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-12-06T22:06:58.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/wangdada8208/designing-api-errors-agents-can-recover-from-52ma"
  },
  "original_language": null,
  "account": "Designing API errors is crucial for agents to recover gracefully. Unlike humans, agents need a machine-readable error contract to decide on recovery actions. FinHot, a free bilingual finance intelligence service, found that an effective contract includes more than just an error status code. It also requires problem details, stable codes, request identifiers, revalidation headers, CORS behavior, and retry hints. This comprehensive contract helps agents determine whether to correct input, use cached data, wait, follow links, or stop.\n\nThe error object should be structured consistently, providing a type, code, and request identifier. This allows clients to correct input errors without relying on error messages alone. A missing resource returns a different problem code, enabling clients to treat it as a lookup failure and follow canonical links instead.\n\nPreventing unnecessary work is another key aspect of designing API errors. For example, a compact endpoint returns an ETag in the response header. A later conditional request with If-None-Match can return a 304 \"Not Modified\" status, allowing agents to keep the last good payload and avoid unnecessary transfers. This pattern is also useful for watchlists, mirrors, and feed monitors.\n\nBrowser-based agents have additional considerations. They need a successful preflight check before sending the actual request. FinHot's preflight check includes CORS headers, which prevent common integration failures. Testing this path alongside the data path ensures the API is operable.\n\nRate limiting and temporary unavailability are normal operations that should be clear to clients. FinHot's OpenAPI document advertises Retry-After on 429 and 503 responses, providing a visible recovery rule. Clients can prepare a bounded backoff path, preserve the last good response, and stop after a few retries.\n\nCompatibility should be prioritized over elegance. Adding new fields or maintaining multiple representations may seem less elegant but is necessary for client integration. Keeping existing clients functional is crucial, even if it means sacrificing a cleaner API design.\n\nTo ensure the API contract is enforced, an example script checks six production behaviors. These include compact success responses, conditional revalidation, invalid input handling, missing resource responses, browser preflight checks, and OpenAPI behavior documentation. Running this script as a periodic monitor can help maintain API reliability.\n\nIn conclusion, designing API errors is essential for agents to recover effectively. By incorporating problem details, stable codes, request identifiers, revalidation headers, CORS behavior, and retry hints, APIs can provide a reliable recovery path for agents. Testing these behaviors and maintaining compatibility with existing clients ensures a robust and operable API.",
  "summary": "Agents do not experience an API error the way a person does. A person can read a page, understand a vague message, and try again. An agent has to decide programmatically whether to correct input, use a cached copy, wait, follow another link, or stop. That decision needs a machine-readable error contract. While building the public REST API for FinHot , a free bilingual finance intelligence…",
  "summary_source": "publisher",
  "key_points": [],
  "editors_take": null,
  "opinion": false,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "outlets_capped": false,
    "also_reported_by": []
  },
  "machine_translated": false,
  "ai_generated": true,
  "disclaimer": "Accounts, briefs, key points, the editor’s take and translations are written by software from other outlets’ reporting and may contain errors. A summary whose summary_source is \"publisher\" is the outlet’s own feed text. Always check the linked original."
}