Skip to main content
Mellea reaches Google Vertex AI through the LiteLLMBackend. There is no separate native Vertex backend — LiteLLM handles authentication and request translation. Prerequisites:
You also need a Google Cloud project with the Vertex AI API enabled.

Authentication

LiteLLM supports two authentication methods for Vertex AI. Run the following command once to authenticate with your Google account:
This stores credentials that LiteLLM picks up automatically. No environment variable pointing to a file is required.

Service account key file

For production deployments, create a service account in the Google Cloud console, grant it the Vertex 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:
Set 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

Use LiteLLMBackend with a vertex_ai/ or vertex_ai_beta/ model string:
Note: The vertex_project and vertex_location keys are the LiteLLM per-call override names. They take precedence over the VERTEXAI_PROJECT and VERTEXAI_LOCATION environment 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:
Use vertex_ai_beta/ for models that are only available through the Vertex AI Preview SDK endpoint. Common model strings: Check the LiteLLM Vertex AI documentation for the full list of supported model strings.

Using chat() and instruct()

Both chat() and instruct() work with LiteLLMBackend in the same way as other backends:

Structured output

Use the format parameter with a Pydantic model to get typed responses:

Model options

Pass generation parameters with ModelOption:
Options set at construction time apply to all calls on that session. Options passed to 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 a google.auth.exceptions.DefaultCredentialsError, run:
or confirm that 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 update VERTEXAI_LOCATION accordingly.

google-cloud-aiplatform not installed

Install the package:

See also: OpenAI and OpenAI-Compatible APIs | Backends and Configuration