{"record":{"id":"73dc7e0be0c5248b","repo":"BerriAI/litellm","slug":"unable-to-load-vertex-credentials-from-environment","errorCode":null,"errorMessage":"Unable to load vertex credentials from environment. Ensure the JSON is valid (check for unescaped newlines in private_key). Parse error: {type(e).__name__}","messagePattern":"Unable to load vertex credentials from environment\\. Ensure the JSON is valid \\(check for unescaped newlines in private_key\\)\\. Parse error: (.+?)","errorType":"validation","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"litellm/llms/vertex_ai/vertex_llm_base.py","lineNumber":120,"sourceCode":"        if credentials is not None:\n            if isinstance(credentials, str):\n                _is_path: Final = os.path.exists(\n                    credentials\n                )  # credentials is from server config (litellm_params), not user input\n                verbose_logger.debug(\n                    \"Vertex: Loading vertex credentials, is_file_path=%s, current dir %s\",\n                    _is_path,\n                    os.getcwd(),\n                )\n\n                try:\n                    if _is_path:\n                        with open(credentials) as f:\n                            json_obj = json.load(f)\n                    else:\n                        json_obj = json.loads(credentials)\n                except Exception as e:\n                    raise Exception(\n                        \"Unable to load vertex credentials from environment. \"\n                        \"Ensure the JSON is valid (check for unescaped newlines in private_key). \"\n                        f\"Parse error: {type(e).__name__}\"\n                    )\n            elif isinstance(credentials, dict):\n                json_obj = credentials\n            else:\n                raise ValueError(f\"Invalid credentials type: {type(credentials)}\")\n\n            # Check if the JSON object contains Workload Identity Federation configuration\n            if \"type\" in json_obj and json_obj[\"type\"] == \"external_account\":\n                # If environment_id key contains \"aws\" value it corresponds to an AWS config file\n                credential_source: Final = json_obj.get(\"credential_source\", {})\n                environment_id: Final = (\n                    credential_source.get(\"environment_id\", \"\") if isinstance(credential_source, dict) else \"\"\n                )\n                if isinstance(environment_id, str) and \"aws\" in environment_id:\n                    # Check if explicit AWS params are in the JSON (bypasses metadata)","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/vertex_ai/vertex_llm_base.py#L102-L138","documentation":"Raised while parsing the vertex_credentials string: it was treated as a file path or raw JSON but json.load/json.loads threw — commonly an unescaped newline in private_key or truncated JSON. The exception type name is appended for diagnosis.","triggerScenarios":"Thrown at litellm/llms/vertex_ai/vertex_llm_base.py:120 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fix the credentials JSON: escape newlines in private_key as \\n or pass credentials via a file path instead of an env var string.","Validate the JSON with json.loads() before setting the environment variable."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}