How to Create Helpful Error Messages in Your API Documentation

Picture this: It’s late at night and a developer keeps getting the same message when their API call fails. “Invalid request format” plays over and over again on their screen. However, there’s no explanation of what’s wrong.  

When something breaks, good API documentation should help developers understand three things: what went wrong, why it happened, and how to fix it. Traditional error messages give none of these

The most frustrating part is the API knows exactly what’s wrong. When it says “invalid format,” it has already found the specific problem. Maybe it’s broken JSON. Maybe it’s a date in the wrong format. But the API keeps that valuable information to itself, and what could be a five-minute fix turns into hours of detective work.

In this guide, we’ll show you a better way that transform your API’s error messages from dead ends into helpful guides.

The problem with traditional error messages

Traditional API error messages fail simply because they tell developers something went wrong, but not how to fix it. 

When developers interact with your API, they want to do something specific, such as process a payment, create a user account, update data, etc. Each error means they have to stop what they’re doing and decode a cryptic error message.

A typical error response when a payment request fails would look like this:



“error”: “Invalid payment parameters”, “code”: “PAY_ERR_001” 
}

To solve the issue, you could check the error code PAY_ERR_001 in the documentation. However, you’ll also have to figure out how this general error applies to your specific situation. 

What you really need at that moment is clear, actionable directions.

To create more helpful error messages in your API, here’s an analogy that you can use.

The bowling bumpers analogy 

A good analogy to understand how API error messages should work is the Bowling Bumpers Approach

Imagine watching someone learn how to bowl for the first time. Without bumpers, their ball often veers into the gutter, which only discourages them.

But when you add bumpers, they gently guide the ball toward the pins, instead of ending up in the gutter. Each contact with a bumper becomes a learning opportunity, showing exactly how to adjust the next throw.

Instead of letting developers’ requests fall into the metaphorical gutter with an unhelpful “Invalid request” message, your API should provide guardrails that guide them back toward success. Each error becomes an opportunity to learn and correct course, rather than a frustrating dead end.

Consider the example of how traditional API errors look from the previous section:


{  
“error”: “Invalid payment amount”,  
“code”: “PAY_ERR_001”
}

This is the equivalent of letting the ball fall into the gutter.

However, a bumper-style error message should look like this:


{  
“error”: “Payment amount needs adjustment”,  
“details”: “The amount $-5.999 has two issues: it cannot be negative and must have exactly two decimal places”,  
“suggestions”: [    
“Ensure the amount is positive (greater than 0)”,    
“Format the amount with exactly two decimal places (e.g., 5.99)”  
],  
“documentation”: “/docs/payments#amount-formatting”,  
“correct_examples”: [“10.99”, “5.00”, “199.99”]
}

This error message acts as a bumper by providing:

  • Constructive language: “Payment amount needs adjustment” guides developers toward a solution instead of just saying “Invalid payment amount.”
  • Specific context: The details show exactly what’s wrong: “$-5.999 has two issues: negative value and incorrect decimals.” 
  • Actionable steps: Clear instructions on how to fix each issue, with the suggestions providing specific steps to correct the problems.
  • Documentation link: Direct path to relevant documentation section. No hunting through pages to find help.
  • Real examples: Shows what good looks like with examples like “10.99”, “5.00”, “199.99” so developers can pattern-match correct formats.

How to create actionable error messages

Consider this common but unhelpful error message:


{    
“error”: “Invalid customer data”,    
“code”: “CUST_ERR_001”
}

Now, let’s add each of the components that transforms it into an actionable message:

Best practiceExplanation
Clear problem descriptionWhat it is: A specific explanation of what validation failed and why
Why it matters: Eliminates guesswork and immediately orients the developer
Example code:
“message”: “The provided phone number ‘+1-555-INVALID’ doesn’t match required format”
Specific technical detailsWhat it is: Structured information about the exact point of failure
Why it matters: Provides debugging-specific information
Example code:
“details”: {    
“field”: “phone_number”,    
“required_format”: “+1-XXX-XXX-XXXX”,    
“validation_error”: “Contains non-numeric characters”
}
Next stepsWhat it is: Ordered list of actions to fix the problem
Why it matters: Transforms the error from a roadblock into a guide
Example code:
“suggestions”: [    
“Use only numbers and hyphens”,    
“Ensure country code is included”,    
“Check that area code is valid”
]
Example usageWhat it is: Both correct and incorrect examples to illustrate proper usage
Why it matters: Helps developers pattern-match their way to success
Example code:
“examples”: {    
“valid”: [“+1-555-123-4567”, “+1-212-555-0123”],    
“common_mistakes”: [       
 “+1-555-CALL-NOW (letters not allowed)”,        
“555-123-4567 (missing country code)”   
 ]
}
Support informationWhat it is: Links to documentation and support resources
Why it matters: Provides a safety net for complex issues
Example code:
“support”: {   
“documentation_url”: “/docs/customers#phone-format”,    
“request_id”: “req_abc123”,    
“contact”: “[email protected]
}

If you apply all of these best practices, you’ll get a well-structured error message like this:


{   
“error”: “Customer creation failed”,    
“message”: “The provided phone number ‘+1-555-INVALID’ doesn’t match required format”,   
“details”: {        
“field”: “phone_number”,       
 “required_format”: “+1-XXX-XXX-XXXX”,        
“validation_error”: “Contains non-numeric characters”    
},    
“suggestions”: [        
“Use only numbers and hyphens”,       
  “Ensure country code is included”,        
“Check that area code is valid”    
],    
“examples”: {        
“valid”: [“+1-555-123-4567”, “+1-212-555-0123”],        
“common_mistakes”: [            
“+1-555-CALL-NOW (letters not allowed)”,            
“555-123-4567 (missing country code)”        
]    
},    
“documentation_url”: “/docs/customers#phone-format”,    
“support”: {       
“request_id”: “req_abc123”,        
“contact”: “[email protected]”    
}
}

This structure creates a natural progression from problem identification to solution. It answers three critical questions every developer has when encountering an error: “What went wrong?”, “Why did it fail?”, and “How do I fix it?”

Pro Tip: Creating comprehensive error messages requires close collaboration between your API development and documentation teams. Set up a system where your validation logic automatically generates detailed error contexts. 

For example, when defining validation rules in your code, create corresponding error message templates and examples. Use a centralized error message registry that maps each validation rule to its human-readable explanation, suggested fixes, and relevant documentation links.

Errors should move developers forward

Error messages shouldn’t just tell developers they’ve hit a wall. They should help them find a path around it. 

When you transform your error messages from mere failure notifications into comprehensive guides, you fundamentally change how developers interact with your API. Each error becomes an opportunity to learn, improve, and move forward.

Remember the bowling bumpers analogy: good error messages guide developers back toward success rather than letting them fall into the gutter.

Ready to transform your API error messages from frustrating roadblocks into helpful guides? ReadMe helps you create comprehensive, actionable error responses that truly help developers succeed. 

Our platform enables you to implement the “bowling bumpers” approach with detailed error contexts, relevant documentation links, and clear paths to solutions. Request a demo today to learn more.