{"record":{"id":"55e431f48d47a6e5","repo":"BerriAI/litellm","slug":"custom-llm-provider-capitalize-exception-rate","errorCode":null,"errorMessage":"{custom_llm_provider.capitalize()}Exception: Rate Limit Errror - {error_str}","messagePattern":"(.+?)Exception: Rate Limit Errror - (.+?)","errorType":"exception","errorClass":"RateLimitError","httpStatus":429,"severity":"error","filePath":"litellm/litellm_core_utils/exception_mapping_utils.py","lineNumber":733,"sourceCode":"            error_str += \"XXXXXXX\" + '\"'\n\n        raise AuthenticationError(\n            message=f\"{custom_llm_provider.capitalize()}Exception: Authentication Error - {error_str}\",\n            llm_provider=custom_llm_provider,\n            model=model,\n            response=getattr(original_exception, \"response\", None),\n            litellm_debug_info=extra_information,\n        )\n    elif ExceptionCheckers.is_error_str_context_window_exceeded(error_str):\n        raise ContextWindowExceededError(\n            message=f\"{custom_llm_provider.capitalize()}Exception: Context Window Error - {error_str}\",\n            model=model,\n            llm_provider=custom_llm_provider,\n            response=getattr(original_exception, \"response\", None),\n            litellm_debug_info=extra_information,\n        )\n    elif \"token_quota_reached\" in error_str:\n        raise RateLimitError(\n            message=f\"{custom_llm_provider.capitalize()}Exception: Rate Limit Errror - {error_str}\",\n            llm_provider=custom_llm_provider,\n            model=model,\n            response=getattr(original_exception, \"response\", None),\n        )\n    elif \"The server received an invalid response from an upstream server.\" in error_str:\n        raise litellm.InternalServerError(\n            message=f\"{custom_llm_provider.capitalize()}Exception - {original_exception.message}\",\n            llm_provider=custom_llm_provider,\n            model=model,\n        )\n    elif \"model_no_support_for_function\" in error_str:\n        raise BadRequestError(\n            message=f\"{custom_llm_provider.capitalize()}Exception - Use 'watsonx_text' route instead. IBM WatsonX does not support `/text/chat` endpoint. - {error_str}\",\n            llm_provider=custom_llm_provider,\n            model=model,\n        )\n    elif hasattr(original_exception, \"status_code\"):","sourceCodeStart":715,"sourceCodeEnd":751,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/litellm_core_utils/exception_mapping_utils.py#L715-L751","documentation":"LiteLLM raises RateLimitError when the provider's error string contains the literal 'token_quota_reached', i.e. your account or key exhausted its token quota for the period. Note the message contains a typo ('Rate Limit Errror' with three r's), so string-matching on the message is unreliable — catch the exception type instead.","triggerScenarios":"A completion() call against a provider/gateway (e.g. Cloudflare AI Gateway or an internal gateway) that returns 'token_quota_reached' in its error body once the configured token budget is spent.","commonSituations":"Teams with per-key token budgets on a gateway, free-tier keys with daily caps, CI loops burning through quota, or shared proxy keys where one workload exhausts the pool.","solutions":["Wait for the quota window to reset, or request a quota increase / top up the key.","Switch to a different API key or provider via litellm.Router fallbacks.","Track token usage (litellm's success callbacks) and alert before hitting the cap.","If you control the gateway, raise the token quota for that key."],"exampleFix":"# before\ntry:\n    resp = litellm.completion(model=..., messages=msgs)\nexcept litellm.RateLimitError as e:\n    if \"Errror\" in str(e):  # fragile string matching\n        ...\n\n# after\ntry:\n    resp = litellm.completion(model=..., messages=msgs)\nexcept litellm.RateLimitError:\n    # handle by type; message text ('Rate Limit Errror') may change between versions\n    time.sleep(60)\n    resp = litellm.completion(model=..., messages=msgs)","handlingStrategy":"retry","validationCode":null,"typeGuard":"import litellm\n\ndef is_token_quota_error(e: BaseException) -> bool:\n    return isinstance(e, litellm.RateLimitError) and \"token_quota_reached\" in str(e)","tryCatchPattern":"try:\n    resp = litellm.completion(model=m, messages=msgs)\nexcept litellm.RateLimitError as e:\n    if \"token_quota_reached\" in str(e):\n        wait_until_quota_reset()  # or rotate to another key/model\n    else:\n        raise","preventionTips":["Monitor cumulative token usage with litellm success callbacks and alert near the quota.","Do not match on the message text (it contains a typo and may change); match the exception type plus the provider token.","Keep a secondary API key/model configured for quota exhaustion."],"tags":["rate-limit","quota","litellm","billing"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}