Andrew Tate / / 5 min read
Errors are ideal documentation entrypoints
// they should have been all along
Agents take errors seriously, and if yours are wack, it means more token burn, worse end products, and probably just a low-lift shift to a competitor.
Messing up from an agent’s point of view
Imagine you’re an agent. One minute, you’re an ethereal, stateless weight in Dario Amodei’s eye; the next you’ve got to integrate durable execution and payments into a vibe-coded app.
Of course, you don’t one-shot it. You get an error. What do you do next?
It depends on the status code, since that says whose problem it is:
- 400 / 422 (bad request): my request is wrong. I read the response body, which usually names the bad field, then check the API's current docs or SDK types instead of guessing at the shape from memory.
- 401 / 403 (auth): I check that the key is loaded, has the right scope, and matches the environment. If the credential is missing or lacks permission, I tell you instead of working around it, because access is your call.
- 404: I check the endpoint path, API version, and whether the resource ID exists.
- 429 (rate limit): I honor Retry-After, back off, and slow my own calls. If the code I'm writing will hit this in production, I build in backoff with jitter.
- 5xx / timeouts: these are probably transient, so I retry a few times with backoff. If it persists, I check the provider's status page and tell you it's on their side.
Across all of these:
- I look at the raw response. SDK wrappers often hide the useful part, so I log the status, body, and request ID.
- I reproduce it in isolation. A minimal curl or script tells me whether the problem is the API or my surrounding code.
- I don't retry what can't succeed. A 400 fails the same way every time, so retries are only for transient failures.
- I'm careful with non-idempotent calls. If a POST that creates or charges something times out, I check whether it went through before retrying, or use an idempotency key.
- I don't hide the failure. I won't catch the error and return fake or empty data to make the code look like it works.
If I can't fix it (a provider outage, a missing permission, a quota that needs a plan change), I show you the exact error and what I ruled out.
Status code, followed by detail, followed by docs.
You don’t always need docs. If the problem is simple, you don’t want to send an agent on a trip to your documentation if you can give detailed information in the error message itself. Clerk gives you a short message for code and a longer one for whoever's reading. Create a user with a bad email address:
{
"errors": [
{
"message": "is invalid",
"long_message": "Email address must be a valid email address.",
"code": "form_param_format_invalid",
"meta": { "param_name": "email_address" }
}
],
"clerk_trace_id": "692de0db2a2ca675b155dd53472ccc86"
}
Resend also provides clear messaging:
{
"message":"Invalid to field. The email address needs to follow the email@example.com or Name <email@example.com> format.",
"name":"validation_error",
"statusCode":422
}
Look back at the agent's playbook. “I read the response body, which usually names the bad field, then check the API's current docs.” That second step is only there in case the first one falls short. With Clerk and Resend it doesn't.
But what about errors where the fix doesn't fit in a sentence?
Good AX errors
Here is a Stripe error when you create a PaymentIntent without a currency:
HTTP/2 400
content-type: application/json
{
"error": {
"code": "parameter_missing",
"doc_url": "https://stripe.com/docs/error-codes/parameter-missing",
"message": "Missing required param: currency.",
"param": "currency",
"request_log_url": "https://dashboard.stripe.com/acct_.../test/workbench/logs?object=req_4XGSOTLWEGztyY",
"type": "invalid_request_error"
}
}
For an agent, this is easy to reason about. You have the status code. You have the detail, with param naming the field and message saying what's missing. And if the agent needs more, doc_url goes straight to a page about this exact error. The agent can add a currency, resend the request, and move on.
GitHub does something similar:
{
"message": "Validation Failed",
"errors": [
{
"resource": "Search",
"field": "q",
"code": "missing"
}
],
"documentation_url": "https://docs.github.com/v3/search",
"status": "422"
}
It includes a docs link, the status repeated in the body, and a structured list of what's wrong.
These structures give the agent exactly what it needs: code, detail, documentation. Going forward, errors should look like this. Not this exact format (more on that in a moment), but should always contain:
-
The status code. The first thing the agent looks at to work out whether it messed up the request, the credentials are wrong, or your service is having a bad day.
-
The detail. Which field is wrong and what you wanted there instead, so the agent can fix things without going anywhere else.
-
The documentation. If the fix takes more than a sentence, link to a page about this exact error.
This is what we mean by errors as an entrypoint. It's progressive disclosure applied to your docs. The error is the first layer, and it should hold just enough for the agent to fix the simple stuff on the spot. When the fix needs more than that, the link takes the agent down a layer, straight to the page about this exact problem. The agent reads only what it needs, and it never has to hunt for the next layer.
Bad AX errors
This is the point where you want us to show the APIs doing this poorly. We won’t (though we tested 10 different services, and have shown only four here, so that should give you an idea); instead, for examples of bad AX errors, we’ll point to… Stripe and GitHub.
Great errors, A+, no notes for both, right up until the agent clicks the link. For Stripe, that link takes you to just this line:
One or more required values are missing. Check our API documentation to see which values are required to create or modify the specified resource.
The “API documentation” link goes to the general API doc page. Useless for an agent struggling. GitHub is maybe worse as you get:
The REST API is now versioned. For more information, see "About API versioning."
Then a list of eight other search-related docs pages to trawl through.
The point is this: neither company would make these mistakes with human-focused documentation. Stripe, in particular, is the doyenne of developer experience. Yet, with agents, there's little thought about how they reach and use this documentation to fulfill their tasks.
A person who lands on that Stripe page shrugs, uses the search bar, and has the answer in a minute. An agent fetches the page, reads one sentence telling it to go check the API documentation, and ends up back at the top of the reference, which is where it would have been if the error had no link at all.
If docs are an entry point, that entry point has to be useful.
Give agents the problem details
If you are following RFC 9457, Problem Details for HTTP APIs, your errors should look something like this:
HTTP/1.1 403 Forbidden
Content-Type: application/problem+json
Content-Language: en
{
"type": "https://example.com/probs/out-of-credit",
"title": "You do not have enough credit.",
"detail": "Your current balance is 30, but that costs 50.",
"instance": "/account/12345/msgs/abc",
"balance": 30,
"accounts": ["/account/12345",
"/account/67890"]
}
You’re probably not, so it probably doesn’t. But it should have since 2016, when the original RFC 7807 came out, and it definitely should have since 2023, when RFC 9457 superseded it.
But this format is ideally suited for agents. It gives them both:
-
type. A URL that identifies the kind of error and, according to the spec, should point to human-readable documentation for it. That makes it the link to the page about this exact problem, built into the format.
-
detail. An explanation of what went wrong with this particular request, like "Your current balance is 30, but that costs 50." You can also add your own fields next to it, like balance and accounts in the example, so the agent gets the numbers without having to pull them out of a sentence.
Those two fields line up with the layers from earlier. detail is the first layer, and it fixes the simple stuff on the spot. type is the second, the link for when the fix needs more than a sentence.
Stripe's missing-currency error could look like this as problem details:
HTTP/1.1 400 Bad Request
Content-Type: application/problem+json
{
"type": "https://stripe.com/docs/error-codes/parameter-missing",
"title": "A required parameter is missing.",
"status": 400,
"detail": "Missing required param: currency.",
"instance": "/v1/payment_intents",
"param": "currency",
"request_id": "req_4XGSOTLWEGztyY"
}
doc_url becomes type, message becomes detail, and param stays as an extension field. Agents are great at parsing the vagaries of code, but standardization never hurt anyone.
Give agents the problem solution
type gets the agent to a page, but you decide what's on that page. There are two ways to do it:
-
A page for each error. https://example.com/probs/parameter-missing exists only to explain that one error, so it can say exactly what causes it and how to fix it, with a request that works. The agent reads it and gets straight back to the code.
-
A link into your existing docs. This works too, as long as the link goes to the part that answers the question. For a missing currency, that's the currency parameter on the endpoint the agent just called. The top of the API reference doesn't help, and neither does a list of eight related pages.
You don't have to choose between them. type can stay a stable identifier with its own /probs/ page, while an extension field points to the exact spot in the reference:
{
"type": "https://example.com/probs/parameter-missing",
"title": "A required parameter is missing.",
"status": 400,
"detail": "Missing required param: currency.",
"param": "currency",
"docs": "https://example.com/docs/api/payment-intents/create#currency"
}
Now the agent gets the general explanation and the specific reference from the same error.
The catch is keeping those links correct, because they can break from either side. Change the API by adding a parameter, renaming a field, or adding a new error, and the docs and links have to change with it. Reorganize the docs, and every URL in your error responses points somewhere that doesn't exist anymore.
Nobody is going to keep that in sync by hand, so automate it:
-
Keep one list of error types in your codebase, and generate both the error responses and the /probs/ pages from it.
-
Check every type and docs URL in CI, so a broken link fails the build instead of reaching an agent.
-
When docs move, redirect the old URLs.
Those redirects matter more than they used to. Your errors get copied into logs, GitHub issues, and forum posts, and some of that ends up in training data. An agent might try a link from your error responses two years after you moved the page.