Integrate LLM Providers with LiteLLM
Promptfoo example evaluating OpenAI, Anthropic, and Google models through LiteLLM's unified proxy interface.
code-scan-action-0.1Add to Favorites
Why it matters
Connect to various Large Language Models (LLMs) using the LiteLLM library. This asset helps in abstracting away the complexities of different LLM APIs, allowing for easier integration and experimentation.
Outcomes
What it gets done
Abstract LLM API calls through a unified interface.
Facilitate switching between different LLM providers.
Enable programmatic interaction with various LLM services.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/pfoo-provider-litellm | bash Steps
Steps in the chain
Overview
Provider Litellm
A promptfoo example evaluating OpenAI, Anthropic, and Google models through LiteLLM's unified proxy interface with one provider syntax. Use when you want to evaluate models across many providers through one unified interface instead of configuring each provider separately.
What it does
This example demonstrates how to use the LiteLLM provider with promptfoo to evaluate multiple models through a unified interface. LiteLLM provides a unified interface to 400+ LLMs, so instead of managing different APIs and authentication for each provider you use one interface to access models from OpenAI, Anthropic, Google, and many more. The example evaluates translation and creative writing tasks across three chat providers (GPT-4.1, Claude Sonnet 4.6, Gemini 2.5 Pro) plus an embedding model for similarity assertions.
When to use - and when NOT to
Use this example when you want a single provider syntax to run evals across many different model providers without configuring each one's API separately, and when you want centralized cost tracking or load balancing across providers via the LiteLLM proxy. It is not a guide to LiteLLM's full feature set - it documents the promptfoo-specific proxy setup and provider syntax.
Inputs and outputs
Set OPENAI_API_KEY and optionally ANTHROPIC_API_KEY/GOOGLE_AI_API_KEY, then start the LiteLLM proxy with the provided ./start-proxy.sh script or manually via pip install litellm[proxy] and litellm --model gpt-4.1 --model claude-sonnet-4-6 --model gemini-2.5-pro --model text-embedding-3-large. Run the eval with npx promptfoo@latest eval. The LiteLLM provider connects to the proxy server (default port 4000), which handles authentication/routing to each provider, standardizes request/response formats, handles errors and retries, and optionally provides caching and rate limiting. Three files make up the example: promptfooconfig.yaml (main eval config), litellm_config.yaml (proxy server config), and start-proxy.sh (helper script). Config uses providers like litellm:gpt-4.1, litellm:claude-sonnet-4-6, and litellm:gemini-2.5-pro, with defaultTest.options.provider.embedding set to litellm:embedding:text-embedding-3-large for similarity assertions.
Integrations
Integrates LiteLLM as a unified proxy in front of OpenAI, Anthropic, Google, and other providers. A custom proxy host/port is set via apiBaseUrl in the provider config (for a LiteLLM proxy running on a different host or port than the local default), for example configuring the litellm:gpt-4.1 provider's config.apiBaseUrl to point at https://your-litellm-server.com; more complex setups run the proxy with litellm --config litellm_config.yaml rather than the inline --model flags. Documented troubleshooting: "Connection refused 0.0.0.0:4000" means the proxy isn't running (start it first); "API key not found" means the provider's env var wasn't set before starting the proxy; "Model not found" means the model wasn't included when starting the proxy. Setup can be verified two ways: confirming the proxy is up with curl http://localhost:4000/health, and confirming a key is actually set by echoing the relevant environment variable (e.g. echo $OPENAI_API_KEY).
Who it's for
Teams evaluating models across multiple providers (OpenAI, Anthropic, Google, or others in LiteLLM's 400+ catalog) who want one provider syntax, centralized cost tracking, and load balancing instead of configuring each provider's API separately in promptfoo.
Source README
provider-litellm (LiteLLM Provider)
You can run this example with:
npx promptfoo@latest init --example provider-litellm
cd provider-litellm
This example demonstrates how to use the LiteLLM provider with promptfoo to evaluate multiple models through a unified interface.
What is LiteLLM?
LiteLLM provides a unified interface to 400+ LLMs. Instead of managing different APIs and authentication methods for each provider, you can use a single interface to access models from OpenAI, Anthropic, Google, and many more.
Quick Start
Set your API keys:
export OPENAI_API_KEY=your-openai-key # Optional: Add other providers export ANTHROPIC_API_KEY=your-anthropic-key export GOOGLE_AI_API_KEY=your-google-keyStart the LiteLLM proxy:
# Use the provided script ./start-proxy.sh # Or manually: pip install litellm[proxy] litellm --model gpt-4.1 --model claude-sonnet-4-6 --model gemini-2.5-pro --model text-embedding-3-largeRun the evaluation:
npx promptfoo@latest eval
Features
- Unified Interface: Access OpenAI, Anthropic, Google, and 400+ other models through one API
- Chat Models: GPT-4.1, Claude Sonnet 4.6, Gemini 2.5
- Embedding Models: Support for similarity assertions via embedding models
- Simple Configuration: One provider syntax for all models
- Cost Tracking: LiteLLM proxy can track usage across providers
- Load Balancing: Distribute requests across multiple instances
How It Works
The LiteLLM provider in promptfoo connects to a LiteLLM proxy server (default port 4000). The proxy handles:
- Authentication and routing to various providers
- Standardizing request/response formats
- Error handling and retries
- Optional features like caching and rate limiting
Configuration Files
promptfooconfig.yaml- Main evaluation configurationlitellm_config.yaml- LiteLLM proxy server configurationstart-proxy.sh- Helper script to start the proxy
Example Configuration
The example evaluates translation and creative writing tasks across three different providers:
providers:
- litellm:gpt-4.1
- litellm:claude-sonnet-4-6
- litellm:gemini-2.5-pro
defaultTest:
options:
provider:
embedding: litellm:embedding:text-embedding-3-large
Troubleshooting
Common Errors
- "Connection refused 0.0.0.0:4000": The LiteLLM proxy server is not running. Start it first with
./start-proxy.sh - "API key not found": Set the appropriate environment variables before starting the proxy
- "Model not found": Ensure the model is included when starting the proxy server
Verify Setup
Check proxy is running:
curl http://localhost:4000/healthVerify API keys:
echo $OPENAI_API_KEY
Advanced Usage
Custom Server URL
If your LiteLLM proxy runs on a different host or port:
providers:
- id: litellm:gpt-4.1
config:
apiBaseUrl: https://your-litellm-server.com
Using Config File
For more complex setups, use the config file:
litellm --config litellm_config.yaml
Learn More
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.