Designing APIs for AI Agents: What Should Change, and What Should Stay?
Agents misread defaults, errors, and retries. Fix the shared contract first: visible effective values, RFC 9457 errors, and a tested recovery path for timeouts, then fund an agent-specific layer only where a measured task still fails.

- Written by
- Lucas Suárez (opens in a new tab)
- Published on
- Read time
- 16 min
Some of your API's callers are now agents. One times out on a POST and sends it again without knowing whether the first one landed. Another accepts a default nobody told it about. A third gets an error written for a person, reads the prose, and guesses.
The pressure that follows is "redesign the API for agents." That redesign touches developers who integrate by hand, the logs support debugs from, and your compatibility promises. You have to decide where to spend first.
Our answer: fix the shared API first. Make its behavior explicit, make the effective values of each call visible, and write a recovery contract that says which errors to fix, which to wait out, and when to stop. Fund an agent-specific surface only when a measured task still fails after that. We found no public study showing that most agent failures have these causes, so that part is our hypothesis. The vendor reports here describe many such failures.
TL;DR
- Keep deterministic contracts, scopes, documented defaults, and versioning. Change what an agent cannot see: effective values, error details, state, and recovery rules.
- A
Retry-Afterheader says when to come back. Whether a POST is safe to send again depends on method semantics or on deduplication such as an idempotency key. - Idempotency keys bound the risk of a resend. Keys can expire, some APIs (Stripe's API v1, for one) replay stored errors, and an outcome that stays unknown needs a lookup or a person.
- Build an agent-specific tool layer when a measured task still fails on the improved API, and build it on top of that API.
Start with which agent is calling
"Agent" covers at least three caller shapes, with different tools, context budgets, and retry logic.
- An agent calling HTTP directly, often through a fetch tool or curl. Hookdeck designed for "the least capable client: GET only, no headers, possibly cached, possibly summarised."
- Code an agent writes against your SDK. The SDK's retries become the agent's retries: Stripe's SDKs "can generate idempotency keys and retry requests automatically."
- Tool abstractions, such as MCP servers or function tools over the API. Webflow found that wrapping its APIs as MCP tools made them "too low-level and overly chatty, often requiring many tool calls for simple tasks."
A fix in the HTTP contract reaches all three shapes. A fix in the MCP layer reaches only the third, which is why the contract comes first.
Keep, change, avoid
| Call | What | Why |
|---|---|---|
| Keep | Deterministic contracts | Both callers build on documented behavior. |
| Keep | Security and scopes | Give agent callers the same scope model as human integrations. |
| Keep | Sensible, documented defaults | They give people the shortest path to the common case. |
| Keep | Compatibility and versioning | Existing integrations keep working while the contract improves. |
| Change | Consequential defaults | Echo the effective values in the response so a caller can check them. |
| Change | Schemas and discoverability | Strict request schemas and errors that point at the failing field. |
| Change | Error details | A stable problem type and a documented next action for each type. |
| Change | State transitions | Slow work returns an operation with an explicit state. |
| Avoid | Wholesale rewrites | They risk every human integration to fix problems nobody measured. |
| Avoid | Agent-only parallel APIs without evidence | Two surfaces to version, secure, and debug. |
| Avoid | Rules such as "remove all defaults" or "expose every parameter" | No source here tests them, and they push cost onto every caller. |
| Avoid | Replacing the API with MCP | Curl, CLI, and SDK callers still use HTTP. |
The first round of work goes into the change rows, on the surface every caller shares.
Defaults drew the sharpest disagreement in a Hacker News thread on Freestyle's agent API post. One commenter noted that "the API designer is also making the parameters they think should be used the most have the least resistance." The post's author replied: "im not opposed to good defaults, i just believe they should be explicit." Explicit defaults are what the change rows ask for.
The options side by side
The status quo is the baseline: keep the API, then wrap it one to one as MCP tools or rely on SDK retries.
| Option | What changes | Evidence in the sources | Risk to human callers | Fits when |
|---|---|---|---|---|
| Status quo: one-to-one MCP wrapper or SDK retries | Nothing in the contract | Webflow's starting point, which it found "overly chatty" | None new | Agent callers already finish their tasks |
| Shared API made explicit | Errors, idempotency, effective values, state | Guides assert it without tests; our local service checks the contract only | Low: humans get the same fixes | Failures trace to unclear behavior or recovery |
| Intent-shaped tool layer over the API | Adds task-level tools | Webflow session analytics; SpecterOps design notes without measurements | Low while the API underneath stays | Simple tasks take many tool calls |
| One HTTP surface for the weakest client, MCP as fallback | GET-friendly flows and visible instructions | Hookdeck's own tests, mostly on its own product, with a brief comparison against other webhook testers | Hookdeck designed it to work as well for humans | Callers are fetch tools on a narrow flow |
| Separate agent-only API | A parallel surface | ASAPP lists it, but says "Most customers choose the second approach," a shared API (undated, no count) | High: humans "work around it" | No source here shows a case |
No row has a benchmark behind it; the evidence column records what each source reports, mostly about its own product.
Errors an agent can act on
In Freestyle's opinion post on agent APIs, Mika Sagindyk, co-founder of 2027.dev, writes that "Unlike humans, agents follow instructions literally, so a vague or wrong error makes them spiral instead of recover." RFC 9457, the Standards Track RFC that obsoletes RFC 7807, already defines the format. An actionable error carries five things:
- A stable type. RFC 9457 makes the
typeURI the problem type's primary identifier; without one, the type isabout:blank. - Where it failed. The RFC's example 422 has an
errorsarray with apointersuch as#/age. - What failed, for a person. Consumers should not parse
detail, and thestatusmember is "only advisory." Branch on the type. - The next actions. Document them per type, since consumers should not dereference type URIs automatically. One guide adds a field for it: a
recovery_actionmember. - A request id a person can search for, with no secrets or stack traces. The RFC warns against exposing details "such as a stack dump available through the HTTP interface."
Why a retry hint does not make a resend safe
A retry hint answers only when to come back. For a POST, safety to repeat depends on method semantics or deduplication.
The 429 status comes from RFC 6585. It means a caller sent too many requests in a given time, and the response may include Retry-After. In RFC 9110, a 503 signals temporary overload or maintenance, and Retry-After suggests how long to wait. Neither says whether the first request had an effect. GitHub's rate limit docs spell out the timing, from x-ratelimit-reset to a cap on the number of retries.
An agent's runtime (its harness) may not follow the hint at all. Hookdeck's endpoint returned 503 with Retry-After until an event landed. "The harness backgrounded it, and the session ended before the event arrived."
RFC 9110 calls a method idempotent when several identical requests have the same intended effect on the server as one. PUT, DELETE, and safe methods qualify; POST does not. The RFC says a client "SHOULD NOT automatically retry a request with a non-idempotent method unless it has some means to know that the request semantics are actually idempotent, regardless of the method, or some means to detect that the original request was never applied." After a timeout, the client cannot tell whether the server applied the request. An idempotency key lets the server recognize the resend.
The Idempotency-Key header is not an RFC. It is an Active Internet-Draft in the IETF httpapi working group, now draft -08, revised on 2026-10-22. Draft -08 answers a missing key with 400, a key reused with a different payload with 422, and a request that arrives while another with the same key is processing with 409. Google's AIP-155 uses a request_id field and lets APIs "choose any reasonable timeframe for honoring request IDs."
Stripe's API v1 shows the limits. Its API reference says Stripe stores the status code and body of the first request with a key once the endpoint starts running, and returns them to every retry with that key, including 500 errors. Keys can be pruned once they are at least 24 hours old, and a key reused with different parameters gets an error. Its error handling guide adds the recovery rules. On a 409 for a request still running, wait and resend with the same key and parameters, because a new key can start a second operation. A 500 leaves the outcome indeterminate. Past the 24-hour window, the guide is direct: "If the outcome is still unknown after that window, don't retry with either the old key or a new one." From there, a lookup or a person decides.
One request, one error, one recovery path
We wrote a small test service for this post. It is an illustrative export service: POST /v1/exports creates an export job, requires an Idempotency-Key header, validates the body, and returns RFC 9457 errors. The service, the problem type URIs under https://api.example.com/problems/, the keys, and the ids are all illustrative. Its seven tests passed on 2026-11-09 with Python 3.12.16 and pytest 9.1.1.
An invalid format gets a problem the caller can branch on, a pointer to the field, and a request id instead of a stack trace:
POST /v1/exports
Idempotency-Key: 4f6c1d2e-invalid
{"dataset": "invoices-2026-10", "format": "xlsx"}
HTTP/1.1 422 Unprocessable Content
Content-Type: application/problem+json
{
"type": "https://api.example.com/problems/validation-error",
"title": "Your request is not valid.",
"status": 422,
"errors": [
{
"detail": "must be 'csv' or 'json'",
"pointer": "#/format"
}
],
"request_id": "req_0001"
}A valid request gets a 202 that echoes the effective dataset and format and points to an operation:
POST /v1/exports
Idempotency-Key: 9b2e7a10-export
{"dataset": "invoices-2026-10", "format": "csv"}
HTTP/1.1 202 Accepted
Content-Type: application/json
Location: /v1/operations/op_0001
{
"id": "op_0001",
"state": "pending",
"dataset": "invoices-2026-10",
"format": "csv"
}The test service rejects the same key with a different body, using the status and title from the example in draft -08:
POST /v1/exports
Idempotency-Key: 9b2e7a10-export
{"dataset": "invoices-2026-10", "format": "json"}
HTTP/1.1 422 Unprocessable Content
Content-Type: application/problem+json
{
"type": "https://api.example.com/problems/idempotency-key-reused",
"title": "Idempotency-Key is already used",
"status": 422,
"detail": "This key was sent with a different body. Use a new key for a new export.",
"request_id": "req_0003"
}The tests run this client, shown complete and unedited:
import json
import time
import urllib.error
import urllib.request
PROBLEMS = "https://api.example.com/problems/"
WAIT_AND_RESEND = {
PROBLEMS + "temporarily-unavailable",
PROBLEMS + "request-in-progress",
}
class FixTheRequest(Exception):
"""A permanent error. Resending the same request will fail the same way."""
class OutcomeUnknown(Exception):
"""Retries are used up. Look up the result or ask a person before acting again."""
def create_export(base_url, body, key, attempts=4, timeout=2.0, max_wait=5):
data = json.dumps(body).encode()
for _ in range(attempts):
request = urllib.request.Request(
f"{base_url}/v1/exports",
data=data,
method="POST",
headers={"Content-Type": "application/json", "Idempotency-Key": key},
)
try:
with urllib.request.urlopen(request, timeout=timeout) as response:
return json.load(response)
except TimeoutError:
continue # outcome unknown: resend the same key and the same body
except urllib.error.HTTPError as error:
problem = json.load(error)
if problem.get("type") not in WAIT_AND_RESEND:
raise FixTheRequest(problem)
time.sleep(min(int(error.headers.get("Retry-After", "1")), max_wait))
raise OutcomeUnknown(key)The client branches on the problem type, never on detail. It waits out only two types, temporarily-unavailable (503) and request-in-progress (409); every other HTTP error raises FixTheRequest. The client encodes the body once and never changes the key, so a resend is the same request. Waits follow Retry-After, capped at max_wait, and the loop stops after attempts with OutcomeUnknown.
(opens the full-size image in a new tab)The timeout test is the hard case. The service records the first POST's work but sends its response 2 seconds late, and the client times out at 1 second. The client resends the same key and the same body. The first request is still running, so the service answers 409 request-in-progress with Retry-After: 1. After waiting, the resend gets the stored 202 with the same operation id, op_0001, and one export exists. A second test resends with a fresh key after the same timeout, as a blind retry would, and gets a second export. If the attempts run out, the client raises OutcomeUnknown and stops: look up the result or ask a person.
What the test service proves and what it does not
The tests cover one local, illustrative service. The client does not resend invalid input. It resends after a 503 only after Retry-After, a bounded number of times. The same key and body after a timeout return the original job. The service rejects the same key with a different body. A fresh key creates a duplicate. We also broke the code on purpose, and the tests caught each change: removing deduplication fails two tests, resending every error fails two, and using a fresh key after a timeout fails one.
The test service does not show agent success rates, real network partitions, key expiry windows, concurrency at scale, persistence across restarts, or any vendor's behavior. It has no result lookup either. The only read is GET /v1/operations/{id} by operation id, so a caller that never received the id cannot find its job. That is the gap OutcomeUnknown hands to a person.
Long-running work, auth, and observability
Google's AIP-151 says it is better "to return some kind of promise to the user and allow the user to check back in later" than to block. "A good rule of thumb is 10 seconds." The created resource "should indicate that it is not usable, generally with a state enum." The test service's 202, Location header, and "state": "pending" follow that shape.
Pagination follows the same rule as defaults (our recommendation): return the effective page size and an explicit next cursor, so a caller can tell a short page from the last one.
For auth, keep one scope model for both callers and keep scopes narrow. Delegated access for general-purpose agents has its own problems, covered in our post on OAuth for AI agents.
Agent failures can be quiet. Webflow's MCP observability found "a silent error affecting more than 10% of sessions" while its infrastructure looked healthy. Webflow gives no sample size or date range. Logging by problem type and request id, per task, surfaces these failures and gives a person the exact call to debug.
Task tools carry a tradeoff. Webflow moved to tools shaped around intents rather than endpoints, then hit what it calls "tool explosion": its platform supports too many valid workflows to give each one its own MCP tool. SpecterOps puts it this way: "APIs are allowed to be implementation-shaped because their callers already know what they are doing. MCP tools should be intention-shaped." A task tool cuts calls but can hide a rule the caller needs, such as an export being asynchronous, so expose those rules in the tool.
The case for a separate agent surface
The strongest objection: agents are a new caller class and need an MCP server or a separate agent API now. Freestyle's founder, Ben Swerdlow, writes "Defaults are bad." and argues an agent should fill in every field. It is an opinion with no test method. Webflow says "APIs designed for developers don't work for agents."
Hookdeck reports results from a few hundred runs across models and harnesses. Visible instructions on the page decided whether agents found its wait endpoint: 100% of the time with them, 0% without.
Wording also cut both ways for Hookdeck. When it told Codex it was fine to stop and report back, Codex's delivery rate dropped from 8/10 to 1/10.
Some models still did not complete the HTTP flow. For models that doubted they could follow it, Hookdeck says a dedicated MCP tool "would have really helped (it scored 100% in our tests)." These are Hookdeck's own tests, mostly on its own product, and the 100% and 0% figures come without a run count.
The reports show that some agents need a differently shaped layer to call. None of these reports describes replacing the human API. Webflow and SpecterOps describe changes to an MCP layer. Hookdeck kept one surface "designed to work just as well for an agent as it does for a human." freeCodeCamp's guide says "MCP isn't a substitute for good API design." The objection holds for the layer agents call, funded after the shared contract works.
Test before you fund a redesign
- Pick a few realistic tasks, such as creating a resource, recovering from a rate limit, and finishing a long-running job.
- Run the same tasks with human developers and with each agent caller shape you serve, across more than one model and harness.
- Track task success, incorrect side effects, recovery after an error, calls and cost per completed task, and whether a person can diagnose a failure from the request id.
- Change one part of the shared contract and run the same tasks again.
- Fund an agent-specific layer for the tasks that still fail.
The plan sets no expected numbers, and the vendor figures here are not targets.
Where to start
Pick one agent integration task that failed in your logs or support queue. Trace it to the hidden default, the unclassified error, or the unsafe resend. Fix that path on the shared API, then run the same task again with the same callers before you fund a broader redesign. For a written recovery contract to compare yours against, read Stripe's advanced error handling guide.
FAQ
Change the shared API first: visible effective values, RFC 9457 errors with stable types, and documented recovery rules. Add an agent-specific layer only when a measured task still fails.
Only for a resend with the same key and body inside the window the server honors. Stripe API v1 replays stored 500 errors, can prune keys after 24 hours, and says not to retry with either key once an outcome stays unknown past the window.
Possibly, as a layer over a clear HTTP contract. Hookdeck says a dedicated MCP tool would have helped models that doubted they could follow its HTTP flow; the tool scored 100% in its tests. For the interface tradeoffs, see MCP vs CLI for AI agents.
Sources
- RFC 9110: HTTP Semantics
- RFC 6585: Additional HTTP Status Codes
- RFC 9457: Problem Details for HTTP APIs
- IETF datatracker: The Idempotency-Key HTTP Header Field
- draft-ietf-httpapi-idempotency-key-header-08
- Stripe API reference: Idempotent requests
- Stripe: Advanced error handling
- Google AIP-155: Request identification
- Google AIP-151: Long-running operations
- GitHub: Rate limits for the REST API
- Freestyle: Designing APIs for Agents
- Webflow: Designing APIs for agents
- Hookdeck: How to design an HTTP API for agents that won't read your docs
- Hacker News: Designing APIs for Agents
- SpecterOps: Designing an MCP Server for AI Agents
- ASAPP: Designing APIs for GenerativeAgent
- freeCodeCamp: How to Design APIs for AI Agents
- Tian Pan: AI-Native API Design






