{"record":{"id":"4ed5f99177c6e98a","repo":"BerriAI/litellm","slug":"raw-response-text-4ed5f9","errorCode":null,"errorMessage":"{raw_response.text}","messagePattern":"\\{raw_response\\.text\\}","errorType":"http","errorClass":"GeminiError","httpStatus":null,"severity":"error","filePath":"litellm/llms/gemini/agents/transformation.py","lineNumber":122,"sourceCode":"        # an authenticated proxy user could set ``api_base`` to an attacker-\n        # controlled host and have the proxy ship its shared Gemini key in the\n        # ``x-goog-api-key`` header.\n        if litellm_params.get(\"api_base\") and not explicit_api_key:\n            raise ValueError(\n                \"When overriding api_base for Gemini agents, you must also \"\n                \"supply an explicit api_key. Falling back to GOOGLE_API_KEY / \"\n                \"GEMINI_API_KEY env vars with a custom api_base is refused \"\n                \"to prevent leaking the shared provider key to arbitrary hosts.\"\n            )\n        api_key: Final = GeminiModelInfo.get_api_key(explicit_api_key)\n        if not api_key:\n            raise ValueError(\"Google API key is required. Set GOOGLE_API_KEY or GEMINI_API_KEY, or pass api_key.\")\n        headers[\"x-goog-api-key\"] = api_key\n        return headers\n\n    def _raise_for_status(self, raw_response: httpx.Response) -> None:\n        if not (200 <= raw_response.status_code < 300):\n            raise GeminiError(\n                message=raw_response.text,\n                status_code=raw_response.status_code,\n                headers=dict(raw_response.headers),\n            )\n\n    # ------------------------------------------------------------------ #\n    # CREATE                                                               #\n    # ------------------------------------------------------------------ #\n\n    def transform_create_request(\n        self,\n        name: str,\n        litellm_params: dict[str, Any],\n    ) -> dict[str, Any]:\n        body: Final[dict[str, Any]] = {\"name\": name}\n        for key in _GEMINI_AGENT_BODY_KEYS:\n            value = litellm_params.get(key)\n            if value is not None:","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/gemini/agents/transformation.py#L104-L140","documentation":"_raise_for_status() in the Gemini agents transformation converts any non-2xx HTTP response into a GeminiError whose message is the raw response body text, carrying the status code and headers. The '{raw_response.text}' message is therefore Google's (or a proxy's) error payload — 400 invalid argument, 401/403 bad key, 404 unknown agent/model, 429 quota — surfaced verbatim.","triggerScenarios":"Any Gemini agents API call (agent create, list, run) that returns a non-2xx: malformed request body, invalid model name for the agent, expired API key, or exceeded quota.","commonSituations":"Agent config references a model the key has no access to; quota exhausted on the free AI Studio tier mid-run; malformed tool declarations produce a 400 with a details payload that lands in the message string.","solutions":["Read the embedded body text — Google errors are JSON with '@type' and 'message' fields that state the exact problem.","Map the carried status_code: 401/403 fix the key, 404 fix model/agent id, 400 fix the payload per the message, 429 back off or raise limits.","For 429/5xx, retry with exponential backoff; GeminiError exposes status_code so branching is straightforward."],"exampleFix":"# before\nresp = litellm.agent_create(...)\n\n# after\nfrom litellm.llms.gemini.common_utils import GeminiError\ntry:\n    resp = litellm.agent_create(...)\nexcept GeminiError as e:\n    if e.status_code == 429:\n        time.sleep(30)\n        resp = litellm.agent_create(...)\n    else:\n        raise","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from litellm.llms.gemini.common_utils import GeminiError\n\ntry:\n    resp = litellm.agent_create(...)\nexcept GeminiError as e:\n    body = e.message  # raw provider text; parse JSON if present\n    if e.status_code == 429:\n        backoff_and_retry()\n    elif e.status_code in (401, 403):\n        raise RuntimeError(\"Gemini auth failed; check API key\") from e\n    else:\n        raise","preventionTips":["Branch on e.status_code rather than string-matching the raw body.","Log status_code and headers alongside the message for quota debugging (e.g. retry-after).","Wrap agent lifecycle calls in a shared error handler so 429 backoff is consistent."],"tags":["gemini","http","api-errors","agents"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}