Skip to content

[Bug]: LiteLLM does not authenticate Gemini with API key. Asking for Vertex credentials. #14771

Description

@sanctimon

What happened?

The LiteLLM proxy, when configured with a public Google AI Studio API key, defaults to using Google's Vertex AI endpoint and expects Application Default Credentials (ADC), causing a DefaultCredentialsError. This occurs even when the provider: gemini is explicitly set in the config.yaml.

Steps to reproduce the error:

Use a standard GEMINI_API_KEY from Google AI Studio.

Configure LiteLLM using a litellm_config.yaml with the provider: gemini and api_key: os.environ/GEMINI_API_KEY settings.

Attempt to make a chat completion request to a Gemini model (e.g., gemini-2.5-flash).

The request fails with a DefaultCredentialsError, as shown in the logs.

This issue prevents users from using a simple API key with the new LiteLLM versions, forcing them into a more complex Vertex AI authentication flow.

# litellm_config.yaml
model_list:
  - model_name: gemini-2.5-flash
    litellm_params:
      model: gemini-2.5-flash
      api_base: https://generativelanguage.googleapis.com/
      api_key: os.environ/GEMINI_API_KEY
      provider: gemini
  - model_name: gemini-2.5-pro
    litellm_params:
      model: gemini-2.5-pro
      api_base: https://generativelanguage.googleapis.com/
      api_key: os.environ/GEMINI_API_KEY
      provider: gemini

litellm_settings:
  drop_params: True
#  check_provider_endpoint: true

Relevant log output

litellm  | 23:52:19 - LiteLLM Router:INFO: router.py:1355 - litellm.acompletion(model=gemini-2.5-flash) Exception litellm.APIConnectionError: Your default credentials were not found. To set up Application Default Credentials, see https://cloud.google.com/docs/authentication/external/set-up-adc for more information.
litellm  | Traceback (most recent call last):
litellm  |   File "/usr/lib/python3.13/site-packages/litellm/main.py", line 557, in acompletion
litellm  |     response = await init_response
litellm  |                ^^^^^^^^^^^^^^^^^^^
litellm  |   File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py", line 1707, in async_streaming
litellm  |     _auth_header, vertex_project = await self._ensure_access_token_async(
litellm  |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
litellm  |     ...<3 lines>...
litellm  |     )
litellm  |     ^
litellm  |   File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/vertex_llm_base.py", line 592, in _ensure_access_token_async
litellm  |     raise e
litellm  |   File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/vertex_llm_base.py", line 587, in _ensure_access_token_async
litellm  |     return await asyncify(self.get_access_token)(
litellm  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
litellm  |     ...<2 lines>...
litellm  |     )
litellm  |     ^
litellm  |   File "/usr/lib/python3.13/site-packages/litellm/litellm_core_utils/asyncify.py", line 57, in wrapper
litellm  |     return await anyio.to_thread.run_sync(
litellm  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
litellm  |     ...<3 lines>...
litellm  |     )
litellm  |     ^
litellm  |   File "/usr/lib/python3.13/site-packages/anyio/to_thread.py", line 56, in run_sync
litellm  |     return await get_async_backend().run_sync_in_worker_thread(
litellm  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
litellm  |         func, args, abandon_on_cancel=abandon_on_cancel, limiter=limiter
litellm  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
litellm  |     )
litellm  |     ^
litellm  |   File "/usr/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 2461, in run_sync_in_worker_thread
litellm  |     return await future
litellm  |            ^^^^^^^^^^^^
litellm  |   File "/usr/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 962, in run
litellm  |     result = context.run(func, *args)
litellm  |   File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/vertex_llm_base.py", line 503, in get_access_token
litellm  |     raise e
litellm  |   File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/vertex_llm_base.py", line 496, in get_access_token
litellm  |     _credentials, credential_project_id = self.load_auth(
litellm  |                                           ~~~~~~~~~~~~~~^
litellm  |         credentials=credentials, project_id=project_id
litellm  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
litellm  |     )
litellm  |     ^
litellm  |   File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/vertex_llm_base.py", line 114, in load_auth
litellm  |     creds, creds_project_id = self._credentials_from_default_auth(
litellm  |                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
litellm  |         scopes=["https://www.googleapis.com/auth/cloud-platform"]
litellm  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
litellm  |     )
litellm  |     ^
litellm  |   File "/usr/lib/python3.13/site-packages/litellm/llms/vertex_ai/vertex_llm_base.py", line 160, in _credentials_from_default_auth
litellm  |     return google_auth.default(scopes=scopes)
litellm  |            ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
litellm  |   File "/usr/lib/python3.13/site-packages/google/auth/_default.py", line 685, in default
litellm  |     raise exceptions.DefaultCredentialsError(_CLOUD_SDK_MISSING_CREDENTIALS)
litellm  | google.auth.exceptions.DefaultCredentialsError: Your default credentials were not found. To set up Application Default Credentials, see https://cloud.google.com/docs/authentication/external/set-up-adc for more information.

Are you a ML Ops Team?

No

What LiteLLM version are you on ?

v1.77.3 OAS 3.1

Twitter / LinkedIn details

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions