how to use google latest llm model on litellm
- User
how to use google latest llm model on litellm
Assistant
how to use google latest llm model on litellm
LiteLLM is a library that simplifies interacting with various large language models (LLMs), including Google's models, by providing a unified API. It acts as a translation layer, allowing you to use an OpenAI-compatible format to access over 100+ LLMs[1][2][3]. You can use LiteLLM either through its Python SDK or by setting up a LiteLLM Proxy server[2].
Here's a general approach to using Google's latest LLM models with LiteLLM:
1. Set up Google Cloud and Authentication:
aiplatform.googleapis.com[4].gcloud auth application-default login.GOOGLE_APPLICATION_CREDENTIALS environment variable to point to the key file[1][6][5].2. Install LiteLLM:
pip install litellm[5][7].pip install google-cloud-aiplatform[5].3. Configure LiteLLM for Google Models:
GEMINI_API_KEY environment variable[9]. When using Vertex AI, the GOOGLE_APPLICATION_CREDENTIALS environment variable or gcloud auth application-default login is used for authentication[5].gemini/<model-name> for Google AI Studio models or vertex-ai/<model-name> for Vertex AI models[9][5].4. Using LiteLLM (SDK or Proxy):
completion from litellm and use it like the OpenAI Chat Completions API[9][10][7]. You pass the model name (with the appropriate prefix like gemini/ or vertex-ai/) and messages[9][5].
from litellm import completion
import os
# Set your Google API key or ensure GOOGLE_APPLICATION_CREDENTIALS is set
# os.environ["GEMINI_API_KEY"] = "your-api-key" # For Google AI Studio
response = completion(
model="gemini/gemini-pro", # Or the latest model identifier
messages=[{"role": "user", "content": "Hello, how are you?"}]
)
print(response.choices[0].message.content)
You can find the latest model identifiers in the Google AI Studio or Vertex AI documentation.litellm-config.yaml) that defines the Google models you want to access via the proxy[6][11]. This configuration will include the model_name (the name you'll use to refer to the model in your requests) and litellm_params which specify the actual model identifier and potentially API keys or environment variables[11].model_name you defined in your configuration[1][6].Key Considerations:
By following these steps, you should be able to integrate and use Google's latest LLM models through LiteLLM, leveraging its unified interface and features.