Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Designing API Errors Agents Can Recover From

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…

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.

The 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.

Preventing 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.

Browser-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.

Rate 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.

Compatibility 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.

To 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.

In 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.

Rewritten by urgent.news; may contain errors — check the original. How we use AI.

Source: dev.to

Read the original at dev.to →

More from Dev.to on urgent.news

Get the news by email. Yesterday's most-covered stories, every morning.

We track opens and clicks to improve the newsletter.

See today's edition · More options

More in Tech

A Web Development Roadmap for 2027 That Ends With a Working Site

Originally published at Code & Cipher . Code-writing tools have become better. That has not made the basics irrelevant. It has made understanding them the difference between using a shortcut and being…

  • Begin with understanding web development fundamentals before shortcuts
  • Progress through HTML, CSS, JavaScript, and framework learning
  • Prioritize security and performance throughout development

JLScript na prática | Do primeiro código aos pequenos projetos

A melhor maneira de entender uma linguagem é escrever código. Hoje vamos conhecer o JLScript na prática: da primeira mensagem no terminal a uma calculadora, um sistema de cadastro e um cálculo de…

  • Create 'ola.jls' file with 'mostrar("Olá, mundo!");' command
  • Develop basic calculator project in 'calculadora.jls'
  • Implement user registration mini project in 'cadastro.jls'

More from Sunday, 6 December 2026 →