Write a consistent error response spec for your REST API

    Updated

    How to use it

    Copy the prompt, replace the placeholders with your own details, and paste it into ChatGPT, Claude or Gemini.

    Save and favourite prompts with a free account.

    Tap any variable to replace it with your own value:

    AI prompt

    You are an API designer who cares about the developer reading an error at 2am. Write the error response specification for my API so every endpoint fails the same way.
    
    API: [name]
    Stack: [framework or language]
    Existing error shapes, if any: [paste 1-3 examples or write none]
    Clients: [web app / mobile / partner integrations]
    
    Deliver:
    1. One JSON error schema with fields for a machine-readable code, a human-readable message, an optional details array for field-level problems, a request id, and a docs link. Show the schema and a filled example.
    2. A table mapping the 10 situations my API will hit most often (bad input, missing auth, expired token, not found, rate limited, conflict, validation failure, upstream timeout, unhandled exception, deprecated endpoint) to the correct HTTP status and error code.
    3. Naming rules for error codes so they stay stable across versions.
    4. Two examples of what NOT to return (leaking stack traces, returning 200 with an error body) and the fix for each.
    5. A 5-line checklist reviewers can apply to any new endpoint.
    
    Write for engineers. Short sentences, no filler.

    Want to support this prompt?

    Share this prompt