LiteLLMBackend. There is no
separate native Vertex backend — LiteLLM handles authentication and request
translation.
Prerequisites:
Authentication
LiteLLM supports two authentication methods for Vertex AI.Application Default Credentials (recommended for local development)
Run the following command once to authenticate with your Google account:Service account key file
For production deployments, create a service account in the Google Cloud console, grant it theVertex AI User role, download the JSON key, and export
its path:
Note: Never commit service account key files to source control. Store them in a secrets manager or inject them as environment variables at deploy time.
Required environment variables
LiteLLM reads the project and region from these two variables:VERTEXAI_LOCATION to the region where your Vertex AI endpoints are
deployed. Common values are us-central1, europe-west4, and asia-east1.
Connecting Mellea to Vertex AI
UseLiteLLMBackend with a vertex_ai/ or vertex_ai_beta/ model string:
Note: Thevertex_projectandvertex_locationkeys are the LiteLLM per-call override names. They take precedence over theVERTEXAI_PROJECTandVERTEXAI_LOCATIONenvironment variables. If the environment variables are already set, you do not need to pass them explicitly — they are shown here for clarity and to support cases where you want to override the environment at runtime.
Model string format
The LiteLLM model string for Vertex AI follows this pattern:vertex_ai_beta/ for models that are only available through the Vertex AI
Preview SDK endpoint. Common model strings:
| Model | LiteLLM string |
|---|---|
| Gemini 1.5 Pro | vertex_ai/gemini-1.5-pro |
| Gemini 1.5 Flash | vertex_ai/gemini-1.5-flash |
| Gemini Pro | vertex_ai/gemini-pro |
| Gemini 2.0 Flash (preview) | vertex_ai_beta/gemini-2.0-flash-exp |
Using chat() and instruct()
Both chat() and instruct() work with LiteLLMBackend in the same way as
other backends:
Structured output
Use theformat parameter with a Pydantic model to get typed responses:
Model options
Pass generation parameters withModelOption:
instruct() or chat() apply to that call only and take precedence.
Troubleshooting
VERTEXAI_PROJECT or VERTEXAI_LOCATION not set
LiteLLM raises an error if the project or location cannot be determined. Export
the variables before running your script:
Authentication error
If you see agoogle.auth.exceptions.DefaultCredentialsError, run:
GOOGLE_APPLICATION_CREDENTIALS points to a valid service
account key file.
Model not available in region
Not all Gemini models are available in every Vertex AI region. Check model availability in the Vertex AI model garden and updateVERTEXAI_LOCATION accordingly.
google-cloud-aiplatform not installed
See also: OpenAI and OpenAI-Compatible APIs | Backends and Configuration