This example demonstrates how to use NVIDIA NIM (NVIDIA Inference Microservices) models with ADK through LiteLLM integration.
For comprehensive information about using NVIDIA models with LiteLLM, refer to the official LiteLLM documentation.
Use the following procedure to get an NVIDIA NIM API key.
- Sign up at NVIDIA AI Foundation
- Navigate to API section and generate an API key
- Copy your API key
Install LiteLLM by running the following code.
pip install litellmSet the required environment variables:
export NVIDIA_NIM_API_KEY="your-nvidia-api-key"
export NVIDIA_NIM_API_BASE="https://integrate.api.nvidia.com/v1/" # Optionalfrom google.adk import Agent
from google.adk.models.lite_llm import LiteLlm
# Create agent with NVIDIA NIM model
agent = Agent(
model=LiteLlm(model="nvidia_nim/meta/llama3-8b-instruct"),
name="nvidia_agent",
instruction="You are a helpful assistant.",
description="Agent using NVIDIA model",
)All NVIDIA NIM models are supported. Use the nvidia_nim/ prefix:
# Examples of available models
models = [
"nvidia_nim/meta/llama3-8b-instruct",
"nvidia_nim/meta/llama3-70b-instruct",
"nvidia_nim/microsoft/phi-3-medium-4k-instruct",
"nvidia_nim/mistralai/mistral-7b-instruct",
"nvidia_nim/google/gemma-7b",
"nvidia_nim/nvidia/nemotron-4-340b-instruct",
# ... and many more
]ADK uses LiteLLM as a wrapper to access NVIDIA NIM models. The integration:
- Model Format: Uses
nvidia_nim/<organization>/<model-name>format - Authentication: Requires
NVIDIA_NIM_API_KEYenvironment variable - Base URL: Optional
NVIDIA_NIM_API_BASEfor custom endpoints - Compatibility: Works with all ADK features (tools, sessions, etc.)
- Supported Endpoints:
/chat/completions,/completions,/embeddings