Quick answer: API debugging is the systematic work of locating where a request goes wrong — the client, the network, the gateway, or the service — by capturing the actual request and response, reproducing it deterministically, and narrowing from the boundary inward. The single most useful artifact is a reproducible request (the exact URL, headers, body, and environment), not a screenshot or a verbal description. Most "it works for me" bugs dissolve once the caller's environment — auth, content type, origin, proxy — is captured along with the error.

This guide covers the handoff that makes debugging possible, the recurring failures (CORS, content type, auth), how to debug across protocols, and how to hand a failure to an AI agent without handing it your conclusion. Follow the links for the concrete cases.

All articles in this guide

Each article below is a focused, pain-point-driven read that belongs to this hub. New ones are added on a regular schedule; the ones still in progress are marked.

1Case

Pasting an Error into an Agent Hands It Your Conclusion

When you paste an error with your own diagnosis, the agent tends to confirm it. How to ask so it actually investigates.

Read the article →
2Case

A Broad try-catch the Agent Added Hides Real Failures

A catch-all that makes errors disappear instead of surfacing them. Why it ships and how to catch it.

Read the article →
3Case

A catch Block That Swallows the Error the Agent Was Hunting

A catch that logs nothing and continues. The exact failure mode that made the bug invisible.

Read the article →
4Case

A Debug Print the Agent Left in the Shipped Handler

A console.log the agent used to debug, now shipping in the handler. What to scan before merge.

Read the article →
5Case

The Agent Logged an Authorization Header in Plaintext

The agent added request logging that writes credentials to logs. The security review this needs.

Read the article →
6Case

A curl Command Is Not an API Handoff

A curl proves one call worked once; it is not reproducible documentation. What a real handoff contains.

Read the article →
7Case

curl Works but the Browser Fails: Debugging CORS

The request succeeds in curl and fails in the browser. The preflight and header checks that find it.

Read the article →
8Case

Valid JSON, Wrong Content-Type: Debugging a 415

The body is valid JSON but the server rejects it. Walking a 415 back to the missing header.

Read the article →
9Case

Debugging a 401: The Token Was Valid but the Audience Was Wrong

A valid-signature 401 is usually an audience mismatch; decode the claims and compare them to the resource.

Read the article →
10Case

The URL Was Double-Encoded: Debugging a 400 from %2520

Encode exactly once at the URL boundary and assert the literal wire format in a test.

Read the article →
11Case

The 404 Was a Base Path and a Trailing Slash the Client Quietly Dropped

How a dropped base path or trailing slash produces a routing 404, and how to read the literal request line.

Read the article →
12Case

The 504 Wasn't Our Code: Debugging an Upstream Gateway Timeout

How to identify the hop that timed out, measure the upstream directly, and choose between a fix and an async job.

Read the article →
13Case

The 409 Conflict Was a Stale Version Field, Not a Duplicate Request

Why a 409 marks a stale version and how to reconcile the change instead of blindly retrying.

Read the article →
14Case

The 302 Redirect Turned Your POST into a GET and Dropped the Body

How a 302 silently rewrites a POST into a GET, drops the body, and points you at the wrong endpoint.

Read the article →
15Case

The 412 Precondition Failed: A Stale If-Match Header Rejected Your Update

How a stale If-Match validator triggers a 412, and why stripping the header is the wrong fix.

Read the article →
16Case

The 406 Not Acceptable: Your Accept Header Named a Format the API Doesn't Return

How to read a 406 and fix content negotiation through the Accept header.

Read the article →
17Case

The 422 Unprocessable Entity: The JSON Parsed but a Validation Rule Rejected It

How to read a 422 as a semantic validation failure and find the rule that rejected the payload.

Read the article →

A reproducible request is the starting point

Debugging cannot begin from "it returns an error." Capture the full request and the environment it ran in. The structure of a good handoff is in an API debugging handoff: caller, environment, and state, and a saved, working request is the most durable form of documentation — see a working curl command as API documentation. A curl command alone is not a complete handoff, though; a curl command is not an API handoff explains what it leaves out.

CORS: works in curl, fails in the browser

The classic signature is that a request succeeds from curl or Postman but fails from the browser, because the browser enforces the Same-Origin Policy and the server never returns the right CORS headers. The diagnosis and the headers you need are in curl works, browser CORS debugging. The key insight is that CORS is enforced by the browser, not the server — a successful curl proves nothing about whether the browser will allow the call.

Valid JSON, wrong content type

Another request that "looks right" but fails: the body is valid JSON, yet the server rejects it with 415 because the Content-Type header is missing or set to something the endpoint does not accept. Walk through it in valid JSON, wrong content type (415). On the response side, make sure errors are returned in a consistent, machine-readable shape using RFC 9457 problem details, so clients can branch on the type rather than parse prose.

Debugging across protocols

HTTP is one of several transports a modern service uses, and switching tools for each one wastes the context you have built. The case for debugging REST, SSE, WebSocket, and gRPC in one workspace is in debug every protocol in one workspace. For streams, the failure modes are sequence and timing rather than a single response; see debugging SSE and debugging WebSocket. Agent-to-agent communication adds another layer; debug agent-to-agent (A2A) like REST treats it with the same discipline.

From a curl command to a contract

When all you have is a captured request, convert it into something the team can build on. convert curl or Postman to OpenAPI turns a single request into a documented operation. Pasting raw curl into a chat window is a weaker move; stop pasting curl into ChatGPT explains why a structured tool or MCP server gives the model better context.

Handing a failure to an AI agent

When you ask an AI to debug, how you present the error determines whether it investigates or just echoes your guess. pasting an error to an agent hands it your conclusion shows the bias this introduces. A few code-level mistakes also make debugging much harder and are worth removing: a broad try-catch that hides failures, a catch that swallows the error, a debug print left in the shipped handler, and the security failure in logging an authorization header in plaintext.

Where to go next

Powerduck is the local-first, OpenAPI-first workspace that carries this whole flow — from the contract through debug, test, mock, and the tools an agent can call. See it on the Powerduck homepage.

Once a bug is reproduced, lock it down with a regression test from the API testing guide; if the service is unavailable, reproduce it with the API mocking guide. To give AI agents the context to debug APIs themselves, read the MCP server guide.

Frequently asked questions

Q

Why does my API work in Postman but not in my app?

A

Almost always an environment difference: the browser's CORS enforcement, a missing header Postman adds automatically, a proxy, or a different auth token. Capture both requests and diff them header by header.

Q

What is the first thing to check on a 401 or 403?

A

Confirm the token is present, unexpired, and sent with the correct scheme and scope; then check whether the gateway strips or forwards it. The contract for auth is in documenting authentication with security schemes.

Q

How do I debug a failure that only happens intermittently?

A

Add structured logging around the boundary, capture the request IDs of failures, and look for ordering, timing, or shared-state causes; a sleep is not a fix. Reproduce under load and in CI rather than waiting for the next occurrence.