BerriAI/litellm · error · Exception

Unable to load vertex credentials from environment. Ensure t

Error message

Unable to load vertex credentials from environment. Ensure the JSON is valid (check for unescaped newlines in private_key). Parse error: {type(e).__name__}

What it means

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.

Source

Thrown at litellm/llms/vertex_ai/vertex_llm_base.py:120

        if credentials is not None:
            if isinstance(credentials, str):
                _is_path: Final = os.path.exists(
                    credentials
                )  # credentials is from server config (litellm_params), not user input
                verbose_logger.debug(
                    "Vertex: Loading vertex credentials, is_file_path=%s, current dir %s",
                    _is_path,
                    os.getcwd(),
                )

                try:
                    if _is_path:
                        with open(credentials) as f:
                            json_obj = json.load(f)
                    else:
                        json_obj = json.loads(credentials)
                except Exception as e:
                    raise Exception(
                        "Unable to load vertex credentials from environment. "
                        "Ensure the JSON is valid (check for unescaped newlines in private_key). "
                        f"Parse error: {type(e).__name__}"
                    )
            elif isinstance(credentials, dict):
                json_obj = credentials
            else:
                raise ValueError(f"Invalid credentials type: {type(credentials)}")

            # Check if the JSON object contains Workload Identity Federation configuration
            if "type" in json_obj and json_obj["type"] == "external_account":
                # If environment_id key contains "aws" value it corresponds to an AWS config file
                credential_source: Final = json_obj.get("credential_source", {})
                environment_id: Final = (
                    credential_source.get("environment_id", "") if isinstance(credential_source, dict) else ""
                )
                if isinstance(environment_id, str) and "aws" in environment_id:
                    # Check if explicit AWS params are in the JSON (bypasses metadata)

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Fix the credentials JSON: escape newlines in private_key as \n or pass credentials via a file path instead of an env var string.
  2. Validate the JSON with json.loads() before setting the environment variable.
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at litellm/llms/vertex_ai/vertex_llm_base.py:120 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/73dc7e0be0c5248b. Report an issue: GitHub.