BerriAI/litellm · error · ValueError

Credentials are None after loading

Error message

Credentials are None after loading

What it means

A defensive check in `get_access_token` that fires when the credentials variable is still None after the cache lookup, project-id fallback, and load_auth path — i.e. the code is about to dereference `_credentials.expired` on a None object. Practically it means a None credentials entry came back from the per-instance `_credentials_project_mapping` cache (or load_auth quietly returned None), so the stored mapping is unusable. It guards against an AttributeError and surfaces the real problem: no live credentials for this cache key.

Source

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

                _credentials,
                credential_project_id,
            )

        ## VALIDATE CREDENTIALS
        verbose_logger.debug("Validating credentials")
        if project_id is None and credential_project_id is not None and isinstance(credential_project_id, str):
            project_id = credential_project_id
            # Update cache with resolved project_id for future lookups
            resolved_cache_key: Final = (cache_credentials, project_id)
            if resolved_cache_key not in self._credentials_project_mapping:
                self._credentials_project_mapping[resolved_cache_key] = (
                    _credentials,
                    credential_project_id,
                )

        # Check if credentials are None before accessing attributes
        if _credentials is None:
            raise ValueError("Credentials are None after loading")

        if _credentials.expired:
            with self._sync_refresh_lock:
                # Double-check after acquiring lock
                if _credentials.expired:
                    try:
                        verbose_logger.debug("Credentials expired, refreshing")
                        self.refresh_auth(_credentials)
                        self._credentials_project_mapping[credential_cache_key] = (
                            _credentials,
                            credential_project_id,
                        )
                    except Exception as e:
                        # if refresh fails, it's possible the user has re-authenticated via `gcloud auth application-default login`
                        # in this case, we should try to reload the credentials by clearing the cache and retrying
                        if "Reauthentication is needed" in str(e) and not _retry_reauth:
                            return self._handle_reauthentication(
                                credentials=credentials,

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Restart the process (or proxy worker) so the credentials cache `_credentials_project_mapping` is rebuilt from a valid source.
  2. Supply complete, valid credentials for the next call: vertex_credentials=<full sa.json string>, vertex_project=<id>, so a fresh cache key is used.
  3. If it persists, run with verbose logging to see the load_auth exception that produced the None entry, and fix the credential source (ADC login / env var / key file).
  4. Upgrade litellm — credential-cache handling around None entries has been tightened in newer releases.
Defensive patterns

Strategy: retry

Try / catch

try:
    litellm.completion(model="vertex_ai/...", messages=msgs, vertex_credentials=sa_json)
except ValueError as e:
    if "Credentials are None after loading" in str(e):
        # stale in-process credential cache: recycle the worker / process
        os._exit(1)  # let the supervisor restart with clean state
    raise

Prevention

When it happens

Trigger: Repeated calls on the same VertexBase handler instance where an earlier lookup cached a None result for (credentials, project_id); or a race where the cached credentials object was replaced with None; or load_auth returning None without raising (partial/invalid credentials dict).

Common situations: Long-lived LiteLLM proxy processes after credentials were removed from the environment mid-flight; tests that reuse handler instances with monkeypatched load_auth; passing `vertex_credentials={}` (empty dict) which fails JSON serialization into a real credentials object.

Related errors


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