Class ZhipuAIProviderErrorMapper

java.lang.Object
com.tnsai.llm.errors.ZhipuAIProviderErrorMapper
All Implemented Interfaces:
ProviderErrorMapper

public class ZhipuAIProviderErrorMapper extends Object implements ProviderErrorMapper
ProviderErrorMapper for ZhipuAI (Z.AI / GLM) — thirteenth and final pilot mapper for the original SPI matrix.

ZhipuAI's chat-completions envelope mirrors OpenAI's shape but uses numeric-string codes instead of OpenAI's lexical ones:


 { "error": { "code": "1110", "message": "rate limit exceeded" } }
 

The numeric vocabulary clusters by leading digit: 100x for authentication / billing, 11xx for quota / rate, 12xx for input shape / context, 13xx for server-side. Mapping reflects those clusters so a previously-unseen code in a known family (e.g. 1115) still routes sensibly via HTTP fallback.

Status mappings:

  • 1001/1002/1003/1004 (key / account / expired) → AUTHENTICATION_FAILED
  • 1110/1112/1113 (rate / frequency) → MODEL_OVERLOADED
  • 1209/1210 (invalid params) → INVALID_REQUEST
  • 1211 (invalid model) → MODEL_NOT_FOUND
  • 1213 (tokens exceeded) / 1214 (context too long) → CONTEXT_TOO_LONG
  • 1300 (internal) / 1301 (server busy) / 1302 (timeout) → SERVER_ERROR
  • HTTP fallback for unrecognised codes

Captured headers: retry-after, x-request-id. ZhipuAI exposes a request id via x-request-id on most responses — invaluable for the support team's bigmodel.cn back-end trace lookup.

Since:
0.5.3 (issue #87 follow-up — thirteenth and final mapper)
  • Constructor Details

    • ZhipuAIProviderErrorMapper

      public ZhipuAIProviderErrorMapper()
  • Method Details

    • providerId

      public String providerId()
      Specified by:
      providerId in interface ProviderErrorMapper
      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: ProviderErrorMapper
      Translate a raw HTTP error response into a typed LLMException.
      Specified by:
      map in interface ProviderErrorMapper
      Parameters:
      httpStatus - HTTP status code from the response
      responseHeaders - selected response headers (lower-cased keys); empty map if none captured
      responseBody - raw response body; mapper parses provider-specific envelope (e.g. JSON error.code)
      model - model identifier from the request, for the resulting LLMException.getModel()
      cause - underlying transport throwable, may be null when the failure is purely a non-2xx response
      Returns:
      typed LLMException with ProviderDetails attached
    • mapErrorType

      public Optional<com.tnsai.exceptions.LLMException.ErrorType> mapErrorType(String providerCode)
      Description copied from interface: ProviderErrorMapper
      Map a provider-native error code to a framework LLMException.ErrorType. Implementations should err on the side of LLMException.ErrorType.UNKNOWN for codes they don't recognize so that a new provider error doesn't fail the whole mapping path.
      Specified by:
      mapErrorType in interface ProviderErrorMapper
      Parameters:
      providerCode - native code (e.g. "context_length_exceeded")
      Returns:
      matching LLMException.ErrorType, or Optional.empty() if the mapper has no opinion