On this page
An API error can point developers to a page explaining what went wrong and how to recover. That link is most useful when it identifies a durable error category, contains no sensitive data, and can be opened without exposing credentials. These API error documentation URL best practices help you design that link without making it a dependency of error handling.
Key Takeaways
- In RFC 9457 Problem Details,
typeidentifies a category of problem;instanceidentifies a particular occurrence. - Use a stable, public HTTPS URL for human-readable type documentation. Keep secrets and user-specific information out of it.
- Clients should handle errors from the response itself, even when the documentation page is unavailable. They should not fetch the page automatically for every error.
- Maintain old URLs and test redirects when error documentation or API versions change.
Problem type versus error instance
A Problem Details response can use a type URI to identify the kind of problem. Multiple occurrences of the same problem can share that URI. When the URI resolves to a documentation page, a developer can use it to understand the problem and its remedies.
The optional instance URI identifies one particular occurrence. It is not a substitute for the type documentation URL. An instance might help a support team correlate a report, but its identifier should not expose credentials or personal information, and an instance URL must not bypass authorization if it provides access to protected details.
The following is an illustrative response, not a live endpoint. Replace the example domain with one you control. The code was not executed, and RFC 9457 was not available to consult for this article; verify its normative requirements before implementing a Problem Details format.
HTTP/1.1 429 Too Many Requests
Content-Type: application/problem+json
Retry-After: 60
{
"type": "https://api.example.com/problems/rate-limit-exceeded",
"title": "Rate limit exceeded",
"status": 429,
"detail": "Wait before retrying this request.",
"instance": "urn:example:problem-instance:7f3b9c42"
}
Here, the type URL identifies the reusable rate-limit problem. The opaque instance identifier distinguishes this occurrence without putting account information in the identifier. The response itself includes a status and retry guidance, so a client does not have to retrieve the documentation to understand the immediate next step.
Advertisement
Make the documentation URL stable and safe to open
Choose a URL that describes the problem category rather than the current documentation site's structure. For example, /problems/rate-limit-exceeded is less tied to an API release or a specific documentation generator than a deeply nested page path. Stability still requires ownership: keep the address working when the underlying page moves.
A useful type page should explain the conditions that produce the error, relevant response fields, and practical recovery options. Document whether retries are appropriate, including any backoff or rate-limit guidance. Avoid publishing internal implementation details that would create a security risk.
Keep the type URL free of API keys, session tokens, email addresses, account IDs, and request-specific diagnostics. URL paths and query strings can appear in browser history, logs, analytics, and other systems. Use a separate, access-controlled support workflow for sensitive diagnostics rather than embedding them in the link.
Serve the page over HTTPS and make it publicly readable without an API key. Public access should apply to the documentation, not to private error records. Avoid login redirects for a page intended to explain an error to any API consumer.
A safe-looking URL is not a guarantee that its destination is safe. Clients and developers should treat links from untrusted responses cautiously, check the destination, and avoid sending API credentials when opening documentation. A client UI that renders a URL as a link should also avoid interpreting response content as executable HTML.
Handle unavailable documentation without breaking the client
The API response is the primary input for error handling. Branch on the HTTP status and, where appropriate, recognized problem types or documented extension fields. Show a useful fallback message when the type is unknown or missing. For the rate-limit example, use the response's retry information rather than scraping the documentation page.
Do not fetch the type URL automatically for every error. The extra request adds latency and creates a dependency on the documentation service; it can also generate unnecessary traffic during an outage or error spike. If the response is untrusted, fetching its URL from a backend can create a server-side request forgery risk. Automatic requests can additionally disclose network metadata or credentials if the fetcher is misconfigured.
Instead, expose the link as an optional developer aid, or consult a locally maintained mapping of known problem types. If the page returns an error, times out, requires unexpected authentication, or redirects somewhere unfamiliar, continue handling the original API error and report that the documentation could not be opened. Do not retry indefinitely.
If a backend must retrieve documentation URLs, treat them as untrusted input: restrict schemes and destinations, validate resolved IP addresses, account for DNS rebinding, revalidate every redirect, enforce network egress controls, and set timeouts and response-size limits. A URL parser or hostname check alone is not a complete SSRF defense. Do not forward API authorization headers or cookies to the documentation destination.
Advertisement
Release checklist for error documentation
Before publishing or changing a problem type, check the following:
- URL and content: The type URL identifies one problem category, contains no secrets or user-specific data, and leads to guidance consistent with the actual response.
- Public access: The documentation is readable over HTTPS without API credentials. Test it in a clean browser session and without an authentication header.
- Redirects: Test the original URL and each redirect to the final page. Keep redirects on destinations you control, preserve HTTPS, avoid loops, and retain old URLs when pages move. Do not rely on forwarding credentials across redirects.
- Versioning: Decide whether API versions share a type based on whether the problem's meaning and recovery guidance remain compatible. If semantics change incompatibly, consider a new type URL and explain the distinction on both pages.
- After API changes: Update guidance when fields, retry behavior, or recovery steps change. Keep documentation for previously published types available for consumers that have not upgraded.
- Failure handling: Check that representative clients still display and handle the error when the documentation host is unreachable or returns an error.
Common Mistakes
- Putting an error occurrence in
type: A per-request URL prevents consumers from treating the type as a stable category. Useinstancefor occurrence identification when needed. - Embedding credentials or customer data in links: Even an HTTPS URL can be recorded by systems that handle it.
- Changing a URL when a page moves: Existing clients, logs, and support tickets may retain the original address. Preserve it or redirect it to equivalent guidance.
- Treating documentation as a runtime API: A page can move or become unavailable. Error handling should not depend on downloading or parsing it.
- Blindly opening or fetching a supplied URL: A response may come from an unexpected or compromised source. Apply appropriate destination checks and avoid forwarding credentials.
Best Practices
Define a naming and ownership policy for problem types before release. Document each type's meaning and recovery path, keep response fields sufficient for immediate handling, and assign a team responsibility for maintaining old links. Review both the URL and the page for sensitive information.
Conclusion
A stable problem type URL gives developers a durable path to useful guidance, while a separate instance identifier can identify an occurrence. Keep documentation public and free of secrets, preserve links across changes, and ensure clients can handle errors without opening the page.
What would your domain sell for?
A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.