{"record":{"id":"c456bec7c19f2e08","repo":"BerriAI/litellm","slug":"custom-llm-provider-capitalize-exception-err","errorCode":null,"errorMessage":"{custom_llm_provider.capitalize()}Exception - {error_str}","messagePattern":"(.+?)Exception - (.+?)","errorType":"exception","errorClass":"ContextWindowExceededError","httpStatus":400,"severity":"error","filePath":"litellm/litellm_core_utils/exception_mapping_utils.py","lineNumber":1099,"sourceCode":"    exception_provider: str,\n    extra_information: str,\n) -> None:\n    if \"Vertex AI API has not been used in project\" in error_str or \"Unable to find your project\" in error_str:\n        raise BadRequestError(\n            message=f\"litellm.BadRequestError: {custom_llm_provider}Exception - {error_str}\",\n            model=model,\n            llm_provider=custom_llm_provider,\n            response=httpx.Response(\n                status_code=400,\n                request=httpx.Request(\n                    method=\"POST\",\n                    url=\" https://cloud.google.com/vertex-ai/\",\n                ),\n            ),\n            litellm_debug_info=extra_information,\n        )\n    if \"400 Request payload size exceeds\" in error_str:\n        raise ContextWindowExceededError(\n            message=f\"{custom_llm_provider.capitalize()}Exception - {error_str}\",\n            model=model,\n            llm_provider=custom_llm_provider,\n        )\n    elif ExceptionCheckers.is_error_str_context_window_exceeded(error_str):\n        raise ContextWindowExceededError(\n            message=f\"ContextWindowExceededError: {custom_llm_provider.capitalize()}Exception - {error_str}\",\n            model=model,\n            llm_provider=custom_llm_provider,\n            litellm_debug_info=extra_information,\n        )\n    elif \"None Unknown Error.\" in error_str or \"Content has no parts.\" in error_str:\n        raise litellm.InternalServerError(\n            message=f\"litellm.InternalServerError: {custom_llm_provider}Exception - {error_str}\",\n            model=model,\n            llm_provider=custom_llm_provider,\n            response=httpx.Response(\n                status_code=500,","sourceCodeStart":1081,"sourceCodeEnd":1117,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/litellm_core_utils/exception_mapping_utils.py#L1081-L1117","documentation":"LiteLLM maps a Vertex AI '400 Request payload size exceeds' error to ContextWindowExceededError. Google rejects the request body because it exceeds the payload size limit (roughly 20 MB per request for the Vertex AI endpoint), which in practice happens when the prompt plus inline data (images, audio, video) is too large. LiteLLM classifies it as a context-window problem so existing context-window retry logic (truncation, fallback models) applies.","triggerScenarios":"A vertex_ai completion call whose serialized JSON payload (messages, base64-encoded images/files, long conversation history) exceeds Vertex AI's request payload limit; typically multimodal requests that inline large media or chat histories with many accumulated messages.","commonSituations":"Sending base64 images or PDFs inline that blow past the payload cap; long agent conversations where the message list grows unboundedly; pasting large documents into the prompt instead of using the Vertex Files API; caching disabled so full context is re-sent every turn.","solutions":["Reduce the payload: truncate the message history (keep the system prompt plus last N turns) before sending","Move large media out of the request: upload files via the Vertex AI Files API or GCS and pass a file_uri instead of inline base64","Compress or downsample images/audio before inlining them","Switch to a model/endpoint that accepts larger payloads, or split the document into chunked requests"],"exampleFix":"# before\nresp = completion(\n    model=\"vertex_ai/gemini-1.5-pro\",\n    messages=messages,  # 40 MB of base64 images + full history\n)\n\n# after: truncate history and reference uploaded files\ntrim = max(1, len(messages) - 20)\nresp = completion(\n    model=\"vertex_ai/gemini-1.5-pro\",\n    messages=[messages[0]] + messages[trim:],  # system + last 20 turns\n    # media uploaded via Files API -> file_uri, not base64 inline\n)","handlingStrategy":"validation","validationCode":"import sys\n\ndef payload_too_large(messages, limit=20 * 1024 * 1024) -> bool:\n    \"\"\"Approximate serialized request size before sending.\"\"\"\n    size = sys.getsizeof(repr(messages))\n    return size > limit, size\n\ntoo_big, size = payload_too_large(messages)\nif too_big:\n    messages = [messages[0]] + messages[-20:]  # trim history\n    # or move media to Files API / GCS file_uri references","typeGuard":null,"tryCatchPattern":"import litellm\n\ntry:\n    resp = litellm.completion(model=\"vertex_ai/gemini-1.5-pro\", messages=messages)\nexcept litellm.ContextWindowExceededError:\n    messages = [messages[0]] + messages[-20:]      # truncate and retry once\n    resp = litellm.completion(model=\"vertex_ai/gemini-1.5-pro\", messages=messages)","preventionTips":["Upload media via Files API/GCS and pass file URIs instead of base64","Cap conversation history length in agent loops","Log serialized payload size per request and alert near the 20 MB ceiling"],"tags":["litellm","vertex-ai","payload-size","context-window","multimodal"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}