Package com.tnsai.llm.errors
Class AbstractOpenAICompatibleErrorMapper
java.lang.Object
com.tnsai.llm.errors.AbstractOpenAICompatibleErrorMapper
- All Implemented Interfaces:
ProviderErrorMapper
- Direct Known Subclasses:
CerebrasProviderErrorMapper,DatabricksProviderErrorMapper,DeepInfraProviderErrorMapper,DeepSeekProviderErrorMapper,FireworksAIProviderErrorMapper,LlamaCppServerProviderErrorMapper,LMStudioProviderErrorMapper,NvidiaNIMProviderErrorMapper,PerplexityProviderErrorMapper,QwenCloudProviderErrorMapper,TencentHunyuanProviderErrorMapper,TogetherAIProviderErrorMapper,VLLMProviderErrorMapper,XAIGrokProviderErrorMapper,YiProviderErrorMapper
public abstract class AbstractOpenAICompatibleErrorMapper
extends Object
implements ProviderErrorMapper
Shared
ProviderErrorMapper for providers that clone OpenAI's
chat-completions API at the error-envelope level. Subclasses supply only
their canonical providerId and human display name; the parsing,
error-type mapping and ProviderDetails assembly are identical.
OpenAI-compatible providers (DeepSeek, Together.ai, Fireworks.ai, Perplexity, xAI Grok, DashScope, Cerebras, …) all return the same envelope:
{ "error": { "message": "...", "type": "...", "code": "...", "param": "..." } }
Native code → LLMException.ErrorType mapping is the OpenAI
standard set (the contract these providers advertise compatibility with):
context_length_exceeded→ CONTEXT_TOO_LONGrate_limit_exceeded/insufficient_quota→ MODEL_OVERLOADEDinvalid_api_key/authentication_error→ AUTHENTICATION_FAILEDmodel_not_found→ MODEL_NOT_FOUNDcontent_filter/content_policy_violation→ CONTENT_FILTEREDinvalid_request_error→ INVALID_REQUEST- HTTP-status fallback when the body has no recognised code
A provider that emits an extra native code can override
mapErrorType(String) and delegate to super for the common
cases; the 15 OpenAI-compatible providers wired in TNS-622 need no such
override and are pure two-argument subclasses.
Captured headers: retry-after, x-request-id and any
x-ratelimit-* — the rate-limit signals shared across these clones.
- Since:
- 0.12.0 (TNS-622)
-
Method Summary
Modifier and TypeMethodDescriptioncom.tnsai.exceptions.LLMExceptionmap(int httpStatus, Map<String, String> responseHeaders, String responseBody, String model, Throwable cause) Translate a raw HTTP error response into a typedLLMException.Optional<com.tnsai.exceptions.LLMException.ErrorType> mapErrorType(String providerCode) Map a provider-native error code to a frameworkLLMException.ErrorType.final String
-
Method Details
-
providerId
- Specified by:
providerIdin interfaceProviderErrorMapper- Returns:
- short, lowercase provider id (e.g.
"openai","anthropic"). Used to route a raw response to the right mapper.
-
map
public com.tnsai.exceptions.LLMException map(int httpStatus, Map<String, String> responseHeaders, String responseBody, String model, Throwable cause) Description copied from interface:ProviderErrorMapperTranslate a raw HTTP error response into a typedLLMException.- Specified by:
mapin interfaceProviderErrorMapper- Parameters:
httpStatus- HTTP status code from the responseresponseHeaders- selected response headers (lower-cased keys); empty map if none capturedresponseBody- raw response body; mapper parses provider-specific envelope (e.g. JSONerror.code)model- model identifier from the request, for the resultingLLMException.getModel()cause- underlying transport throwable, may be null when the failure is purely a non-2xx response- Returns:
- typed
LLMExceptionwithProviderDetailsattached
-
mapErrorType
Description copied from interface:ProviderErrorMapperMap a provider-native error code to a frameworkLLMException.ErrorType. Implementations should err on the side ofLLMException.ErrorType.UNKNOWNfor codes they don't recognize so that a new provider error doesn't fail the whole mapping path.- Specified by:
mapErrorTypein interfaceProviderErrorMapper- Parameters:
providerCode- native code (e.g."context_length_exceeded")- Returns:
- matching
LLMException.ErrorType, orOptional.empty()if the mapper has no opinion
-