Record Class ProviderDetails

java.lang.Object
java.lang.Record
com.tnsai.exceptions.ProviderDetails
Record Components:
provider - non-null provider id (e.g. "openai", "anthropic")
providerCode - provider-native error code (when surfaced)
providerType - coarser provider-native error type
providerParam - request parameter the error refers to
httpStatus - HTTP status when applicable
relevantHeaders - selected response headers (retry-after, x-request-id, etc.); empty when none
rawBody - full response body for forensics; pass through redaction before serialization

public record ProviderDetails(String provider, Optional<String> providerCode, Optional<String> providerType, Optional<String> providerParam, Optional<Integer> httpStatus, Map<String,String> relevantHeaders, String rawBody) extends Record
Native error details surfaced from an upstream LLM (or external) provider.

When a provider returns a structured error body, the framework parses the meaningful fields out and attaches them to LLMException via this record. Consumers can then route on providerCode() (e.g. "context_length_exceeded" → summarize + retry, "rate_limit_exceeded" → backoff + different model), and operators get provider-native fields in dashboards for vendor-specific drill-down.

All fields except provider() are optional — providers vary in how rich their error envelopes are, and HTTP-only failures (DNS, connection reset) carry only a status code at best.

Example — OpenAI error body


 {
   "error": {
     "message": "...",
     "type":  "invalid_request_error",
     "code":  "context_length_exceeded",
     "param": "messages"
   }
 }
 
Maps to:

 new ProviderDetails(
     "openai",
     Optional.of("context_length_exceeded"),
     Optional.of("invalid_request_error"),
     Optional.of("messages"),
     Optional.of(400),
     Map.of("openai-version", "2026-04-01"),
     "<raw response body, redaction applied>")
 
Since:
0.5.0 (issue #87)
  • Constructor Details

  • Method Details

    • of

      public static ProviderDetails of(String provider)
      Construct minimal details — just the provider id. Useful when the provider returned no structured envelope (transport-layer failure).
    • builder

      public static ProviderDetails.Builder builder(String provider)
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • provider

      public String provider()
      Returns the value of the provider record component.
      Returns:
      the value of the provider record component
    • providerCode

      public Optional<String> providerCode()
      Returns the value of the providerCode record component.
      Returns:
      the value of the providerCode record component
    • providerType

      public Optional<String> providerType()
      Returns the value of the providerType record component.
      Returns:
      the value of the providerType record component
    • providerParam

      public Optional<String> providerParam()
      Returns the value of the providerParam record component.
      Returns:
      the value of the providerParam record component
    • httpStatus

      public Optional<Integer> httpStatus()
      Returns the value of the httpStatus record component.
      Returns:
      the value of the httpStatus record component
    • relevantHeaders

      public Map<String,String> relevantHeaders()
      Returns the value of the relevantHeaders record component.
      Returns:
      the value of the relevantHeaders record component
    • rawBody

      public String rawBody()
      Returns the value of the rawBody record component.
      Returns:
      the value of the rawBody record component