Designing Stable Problem Type URLs for API Errors

Learn how to design stable RFC 9457 problem type URIs, maintain their documentation, and handle API errors without fetching a URL on every response.

Published
Reading time
7 min read
Designing Stable Problem Type URLs for API Errors
On this page

A problem type URI gives an API error a machine-readable identity. A well-designed URI lets clients recognize the same class of problem even as its documentation improves, its wording changes, or individual errors occur on different requests.

This guide covers RFC 9457 problem type URI best practices: choosing identifiers, maintaining documentation, and designing clients that do not depend on fetching a URL for every error. RFC 9457 was not available to consult while preparing this article; verify implementation details against the standard before adopting them.

Key Takeaways

  • Treat type as the identifier of a class of problems, not as the failed API endpoint or a unique occurrence.
  • Use a URI under a domain your organization controls and can maintain. An HTTPS URL that serves useful documentation is a practical choice.
  • Keep the URI stable when wording or documentation changes. Introduce a new type when the problem's meaning changes incompatibly.
  • Clients should interpret known types from their own configuration or code, without fetching the type URI for each response.
  • If documentation is unavailable or a type is unknown, use the HTTP status and other response information for a safe fallback.

What the problem type URI identifies

A problem details response can include a type member: a URI identifying the kind of problem. Multiple occurrences of the same problem can share a type URI, even when their detail and instance values differ.

IdentifierPurposeExample
typeIdentifies a class of problemshttps://api.example.com/problems/insufficient-credit
Request targetIdentifies the resource or operation the client tried to access/orders
instanceIdentifies a particular occurrence of the problem/problem-occurrences/7f3a

The type URI is not necessarily an API endpoint that clients should call to resolve the error. The optional instance member has a different purpose: distinguishing one occurrence from another, for example when correlating a support request. An instance URI should not expose sensitive information.

If type is omitted, the default is about:blank, which indicates that the problem has no additional semantics beyond those of the HTTP status code. Use a specific type when clients need to distinguish a condition more precisely.

Advertisement

Design a stable RFC 9457 problem type URI

Choose an identifier you can own

A URL under a domain controlled by the API provider is a useful default:

https://api.example.com/problems/insufficient-credit

This is a fictional example, not a live documentation link. The path describes the problem rather than a particular request, user, or deployment. A type URI is a URI, not necessarily an HTTPS URL, but an HTTPS URL can also give developers a convenient place to read documentation. HTTPS availability is an operational recommendation, not a guarantee that every client can reach it.

Prefer a type name that remains meaningful across endpoint changes. For example, if insufficient account credit has the same semantics across several operations, a single shared type may be appropriate. If two conditions require materially different client behavior, give them distinct types.

Avoid embedding transient details such as timestamps, request IDs, localized text, or internal exception class names in the type URI. Those details either belong elsewhere in the response or should remain internal.

Define the contract behind the URI

Document each type's meaning, the HTTP statuses with which your API uses it, and any extension members clients can rely on. Describe recovery options where they are useful. Treat title and detail as human-readable text, not as stable machine-readable codes.

The following is a constructed example, not a captured response. Assume the server sends it with HTTP status 403 and Content-Type: application/problem+json:

{
  "type": "https://api.example.com/problems/insufficient-credit",
  "title": "Insufficient credit",
  "status": 403,
  "detail": "The account does not have enough credit to complete this order.",
  "instance": "/problem-occurrences/7f3a"
}

The provider can rewrite the documentation page, add examples, or clarify recovery instructions without changing type. It can also change the wording of title or detail without changing the problem's identity. If the type's meaning changes incompatibly—for example, clients must now take a fundamentally different action—publish a new type instead of silently redefining the old one.

The HTTP response status remains important independently of the body. If a body's status member disagrees with the actual HTTP status, clients and intermediaries still need to handle the actual response status.

Prefer absolute URIs for interoperability

A relative type URI needs to be resolved against the applicable base URI before it identifies the type. That can make the same text resolve differently in different contexts. Publishing absolute type URIs avoids that ambiguity and makes client matching and documentation easier. If your API accepts or emits relative references, specify and test how they are resolved.

Make documentation useful without making it a runtime dependency

When the type URI is an HTTPS URL, maintain a human-readable page at that address. Explain what the problem means, relevant extension members, and actions a client or operator can take. Keep old type pages available for as long as supported clients may encounter them, including after an API endpoint or documentation site moves.

Assign an owner to the domain and its renewal, DNS, TLS certificates, and documentation hosting. If a page moves, preserve the original URL where practical, such as by maintaining a redirect. Monitor availability and link health. A stable identifier can still identify a type if its page is temporarily unreachable, but broken documentation makes the API harder to use.

Clients should not fetch the type URI to interpret every response. Network requests add failure modes, and a server-provided URI is untrusted input. A developer-facing tool may offer a link or controlled lookup, but ordinary error handling should work offline from the documentation site.

Advertisement

Handle known, unknown, and unreachable types

A practical client can follow this sequence:

  1. Read the actual HTTP status and, when the response is a problem details document, parse its members.
  2. Resolve a relative type reference if applicable; otherwise use the absolute identifier. If type is absent, treat it as about:blank.
  3. Match recognized type identifiers against the client's supported error contract. Apply type-specific behavior only when its required data is present and valid.
  4. For an unknown type, fall back to handling the HTTP status and presenting an appropriate message. Do not assume that every unknown type is safe to retry.
  5. Ignore extension members the client does not understand, while validating any members it uses.

Whether the documentation URL returns an error, times out, or is unreachable should not prevent these steps. If a user-facing application displays detail, treat it as untrusted text and escape it for the display context. Do not expose sensitive server diagnostics through problem details.

If tooling does fetch type documentation, restrict destinations and redirects and apply appropriate network controls; blindly fetching arbitrary type URIs can create server-side request forgery risk. Such tooling should remain separate from the normal error-handling path.

Common Mistakes

  • Using a unique type for each failure. Put per-occurrence identity in instance, not in type.
  • Parsing title or detail for program logic. Wording and localization can change. Match a documented type and validate any relevant extensions instead.
  • Reusing one type for incompatible meanings. Clients may make the wrong recovery decision if a familiar identifier silently changes semantics.
  • Assuming a URL must be reachable to be meaningful. Documentation can be unavailable while the identifier remains useful.
  • Fetching every type URI automatically. This makes error handling depend on another network request and can introduce security risks.
  • Treating a type URI as proof of trust. A response can contain a URI chosen by an untrusted party; recognizing a string does not authenticate the response.

Best Practices

  • Maintain a registry of problem types, their owners, meanings, and supported extensions.
  • Test client behavior for known types, unknown types, missing type, missing optional members, and malformed responses.
  • Keep documentation URLs and older type definitions available through domain and platform migrations.
  • Review changes to type semantics as API contract changes, not merely documentation edits.
  • Use stable, non-sensitive occurrence identifiers if support teams need correlation.

Conclusion

A good problem type URI is a durable contract identifier. Keep its meaning stable, maintain documentation at HTTPS URLs you control where practical, and ensure clients can handle errors even when that documentation cannot be reached.

What would your domain sell for?

A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.