This guide provides comprehensive instructions for setting up and running the ExLLM test suite.
-
Copy the test environment template:
cp .env.test.example .env.test
-
Add at least one API key to
.env.test:# Recommended for core functionality testing OPENAI_API_KEY=your-openai-key-here ANTHROPIC_API_KEY=your-anthropic-key-here -
Run tests:
source .env.test && mix test --include integration
The test suite supports testing with multiple LLM providers. Each provider requires its own API key:
| Provider | Environment Variable | How to Get API Key |
|---|---|---|
| OpenAI | OPENAI_API_KEY |
https://platform.openai.com/api-keys |
| Anthropic | ANTHROPIC_API_KEY |
https://console.anthropic.com/settings/keys |
| Google Gemini | GEMINI_API_KEY |
https://aistudio.google.com/app/apikey |
| Groq | GROQ_API_KEY |
https://console.groq.com/keys |
| Mistral | MISTRAL_API_KEY |
https://console.mistral.ai/api-keys |
| OpenRouter | OPENROUTER_API_KEY |
https://openrouter.ai/settings/keys |
| Perplexity | PERPLEXITY_API_KEY |
https://www.perplexity.ai/settings/api |
| X.AI | XAI_API_KEY |
https://console.x.ai/team |
Some providers run locally and don't require API keys:
# Install Ollama
curl -fsSL https://ollama.ai/install.sh | sh
# Start Ollama service
ollama serve
# Pull a model for testing
ollama pull llama3.2
# Set environment variable (if not using default port)
export OLLAMA_HOST=http://localhost:11434- Download from https://lmstudio.ai
- Start the local server (usually on port 1234)
- Load a model in the UI
- Set environment variable if needed:
export LMSTUDIO_HOST=http://localhost:1234
For Gemini's tuned models and corpus APIs:
-
Set OAuth2 credentials:
export GOOGLE_CLIENT_ID=your-client-id.apps.googleusercontent.com export GOOGLE_CLIENT_SECRET=your-client-secret
-
Run OAuth2 setup:
elixir scripts/setup_oauth2.exs
mix testmix test --include integration# Test a single provider
mix test.openai
mix test.anthropic
mix test.gemini
# Test local providers
mix test.local# Excludes slow and integration tests
mix test.fast# Enable caching for faster repeated test runs
export EX_LLM_TEST_CACHE_ENABLED=true
mix test --include integration
# Force live API calls (bypass cache)
MIX_RUN_LIVE=true mix test --include integration- Symptom: 401/403 errors in tests
- Solution: Verify API keys are correctly set in
.env.test - Debug:
# Check if environment variables are loaded echo $OPENAI_API_KEY
- Symptom: "Service ollama is not available" skip messages
- Solution: Start the required service (Ollama/LM Studio)
- Note: Tests will skip gracefully if services aren't running
- Symptom: Bumblebee tests fail with ModelLoader errors
- Solution: This is expected in test environment; tests handle it gracefully
- Note: ModelLoader is not started in test mode by design
- Symptom: Tests expecting different default models
- Solution: Pull latest changes; configuration has been updated
Enable detailed logging:
export EX_LLM_LOG_LEVEL=debug
mix testFor GitHub Actions or other CI systems:
-
Add secrets for each provider:
OPENAI_API_KEYANTHROPIC_API_KEY- etc.
-
Use restricted API keys with low quotas for testing
-
Enable test caching in CI for faster builds:
env: EX_LLM_TEST_CACHE_ENABLED: true
Tests are organized with tags:
:unit- Pure unit tests (no external dependencies):integration- Tests requiring API calls:streaming- Streaming functionality tests:vision- Multimodal/vision tests:oauth2- OAuth2-required tests:requires_service- Local service tests:slow- Tests taking >5 seconds:quota_sensitive- Tests consuming significant API quota
- Start with minimal providers - You don't need all API keys to contribute
- Use test caching during development to save API costs
- Run
mix test.fastfor quick feedback during development - Check for skipped tests in output to understand coverage
- Local services are optional - tests skip gracefully if not available
- Check test output for specific error messages
- Enable debug logging for detailed information
- Review ENVIRONMENT.md for all configuration options
- Open an issue if you encounter persistent problems