I need to configure google llm to use the vertex a...
# ask-ai
r
I need to configure google llm to use the vertex ai. I already have generated the credentials json, how to configure this in livekit. when I specfy the env variable GOOGLE_APPLICATION_CREDENTIALS to the filepath of the vertex ai json, it throws the error
ValueError: API key is required for Google API either via api_key or GOOGLE_API_KEY environment variable
t
Thanks for reaching out, Taresh. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
The error
ValueError: API key is required for Google API either via api_key or GOOGLE_API_KEY environment variable
occurs when the Google Gemini API is being used without providing the required API key. However, since you are configuring Vertex AI, this error suggests a misconfiguration. To configure Vertex AI correctly in LiveKit, follow these steps: 1. Ensure the
GOOGLE_APPLICATION_CREDENTIALS
environment variable is set to the path of your service account key file:
Copy code
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your/service-account-key.json"
1. Optionally, set the following environment variables for your project and location:
Copy code
export GOOGLE_CLOUD_PROJECT="your-project-id"
export GOOGLE_CLOUD_LOCATION="us-central1"
1. To ensure Vertex AI is used, set the
GOOGLE_GENAI_USE_VERTEXAI
environment variable:
Copy code
export GOOGLE_GENAI_USE_VERTEXAI="true"
Here is an example of how to configure the Google LLM in LiveKit for Vertex AI:
Copy code
from livekit.plugins import google

google_llm = google.LLM(
    model="gemini-2.0-flash-001",
    vertexai=True,
    project="your-gcp-project-id",  # optional if set via env var
    location="us-central1"  # optional, defaults to us-central1
)
By following these steps, the configuration should work without requiring an API key, as Vertex AI uses Google Cloud authentication via the service account credentials. If you still encounter issues, double-check the environment variable values and ensure the service account has the necessary permissions for Vertex AI. Sources: livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/llm.py