{"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/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/litellm_core_utils/exception_mapping_utils.py#L1081-L1117","documentation":"Vertex rejected the request with '400 Request payload size exceeds...' and litellm maps it to ContextWindowExceededError (message form '<Provider>Exception - <error_str>'). It fires when the raw request payload exceeds Vertex's request-size limit, which in practice happens with huge inline base64 media or genuinely oversized prompts.","triggerScenarios":"Multimodal litellm calls passing large base64-encoded images/audio/video inline; very long prompt text pushed past Vertex's per-request payload cap; RAG pipelines stuffing too many retrieved chunks into one request.","commonSituations":"Whole documents pasted into prompts; high-resolution images sent inline instead of by reference; conversations that grew until the serialized body crossed the limit.","solutions":["Shrink the payload: downscale/compress images, trim documents, and send media via GCS URI where the model supports it instead of inline base64","Chunk inputs and use map-reduce/summarize instead of one giant prompt","Count tokens before sending: litellm.token_counter(model, messages=messages) and stay under the model limit in model_prices_and_context_window.json"],"exampleFix":"# before\nlitellm.completion(\n    model='vertex_ai/gemini-1.5-pro',\n    messages=[{'role': 'user', 'content': [\n        {'type': 'image_url', 'image_url': {'url': 'data:image/png;base64,' + huge_b64}},  # 30 MB inline\n        {'type': 'text', 'text': huge_doc},\n    ]}],\n)\n\n# after\nlitellm.completion(\n    model='vertex_ai/gemini-1.5-pro',\n    messages=[{'role': 'user', 'content': [\n        {'type': 'image_url', 'image_url': {'url': 'gs://my-bucket/img.png'}},  # by reference\n        {'type': 'text', 'text': huge_doc[:100_000]},  # trimmed\n    ]}],\n)","handlingStrategy":"validation","validationCode":"import base64\n\nMAX_INLINE_BYTES = 10 * 1024 * 1024  # stay well under Vertex payload cap\n\ndef payload_fits(parts: list[dict]) -> bool:\n    size = 0\n    for p in parts:\n        if p.get('type') == 'image_url':\n            url = p['image_url']['url']\n            if url.startswith('data:'):\n                size += len(base64.b64decode(url.split(',', 1)[1]))\n        else:\n            size += len(p.get('text', ''))\n    return size < MAX_INLINE_BYTES\n\nassert payload_fits(content_parts), 'payload too large - reference media via gs:// instead'","typeGuard":"import litellm\n\ndef is_vertex_payload_too_large(exc: BaseException) -> bool:\n    return isinstance(exc, litellm.exceptions.ContextWindowExceededError) and 'Request payload size exceeds' in str(exc)","tryCatchPattern":"import litellm\nfrom litellm.exceptions import ContextWindowExceededError\n\ntry:\n    resp = litellm.completion(model='vertex_ai/gemini-1.5-pro', messages=messages)\nexcept ContextWindowExceededError as e:\n    if 'Request payload size exceeds' in str(e):\n        messages = downscale_inline_media(messages)  # compress or move to gs:// URIs\n        resp = litellm.completion(model='vertex_ai/gemini-1.5-pro', messages=messages)\n    raise","preventionTips":["Reference large media by gs:// URI instead of inlining base64","Compress/downscale images client-side before attaching them","Add a payload-size pre-check on multimodal requests so failures happen before the API call"],"tags":["vertex-ai","gcp","context-window","payload-size","litellm"],"backgroundTag":"context-window-exceeded","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}