Design API error contracts

Use Autohand Code with REST API design guidance to standardize status codes, error bodies, validation messages, and client-facing examples.

Make failures predictable for clients

API design Build and change Implementation Code

autohand -p "Standardize this API error contract and update tests and docs"

Consistent error responses, updated tests, and client-facing examples.

Design API error contracts with Autohand Code is an API design workflow that standardizes validation errors, status codes, error envelopes, examples, and tests around client-facing failure behavior. ### At a glance | Question | Answer | | --- | --- | | Best for | APIs with inconsistent errors, unclear validation responses, or client SDKs that need stable failure shapes | | Primary inputs | Target endpoints and current error examples; Expected client behavior for validation, auth, conflict, and missing resource cases; API tests, docs, or SDK methods that consume the errors | | Autohand Code returns | Consistent error responses, updated tests, and client-facing examples. | | Avoid when | the endpoint is private throwaway code with no client contract | ### How Autohand Code handles this workflow 1. Reads current endpoint behavior and existing error helpers. 2. Defines a narrow error envelope and maps common failure classes. 3. Updates handlers, tests, and examples together. 4. Calls out compatibility risk for clients that already parse older errors. ### Best inputs - Target endpoints and current error examples - Expected client behavior for validation, auth, conflict, and missing resource cases - API tests, docs, or SDK methods that consume the errors ### Strong prompt autohand -p "Standardize this API error contract and update tests and docs" ### Autohand Code CLI options - Use `/skills use api-design-restful` before changing endpoint contracts. - Run `autohand -p "Standardize this API error contract and update tests and docs"` with sample failing requests. - Use `--patch` when contract changes need API-owner review before application. ### Review before accepting Review status codes, response bodies, tests, docs examples, and any compatibility notes for existing clients. ### Source and validation signals Autohand AI maintains this workflow as first-party product guidance for Autohand Code. Use the [Autohand CLI Playbook](https://github.com/autohandai/code-cli/blob/main/docs/AUTOHAND_PLAYBOOK.md), [CLI reference](/docs/working-with-autohand-code/cli-reference.html), and [configuration reference](https://github.com/autohandai/code-cli/blob/main/docs/config-reference.md) when choosing between interactive mode, command mode, auto-mode, feature-enabled /goal, /settings, skills, MCP, and permission settings. The related resources below link to product docs and tutorials for the workflow, and the final answer should name repository-specific files, commands, outputs, or docs that a reviewer can verify. ### Frequently asked questions ### What is Design API error contracts with Autohand Code? Design API error contracts with Autohand Code is an API design workflow that standardizes validation errors, status codes, error envelopes, examples, and tests around client-facing failure behavior. ### When should a team use Design API error contracts? Use it before exposing an API to clients or generating SDK code from endpoint behavior. ### What evidence should reviewers check for Design API error contracts? Review status codes, response bodies, tests, docs examples, and any compatibility notes for existing clients.

Skill Skilled: RESTful API Design Use REST contract and error-handling guidance. https://skilled.autohand.ai/skill/api-design-restful Reference Custom Tools Model typed behavior around external tool calls. /docs/agent-sdk/tools/custom-tools.html Tutorial Scaffold a REST API from Scratch Pair endpoint design with validation and tests. /docs/tutorials/scaffold-rest-api.html