Effortlessly manage your Ollama models in LiteLLM proxy with these powerful Python utilities
- π Bulk Model Management: Add all your Ollama models to LiteLLM with a single command
- π§Ή Duplicate Cleanup: Automatically detect and remove duplicate models
- π― Smart Detection: Only add new models, skip existing ones
- π Dry Run Mode: Preview changes before executing them
- πͺ Force Mode: Override duplicate detection when needed
- π¨ Beautiful CLI: Rich output with emojis and progress indicators
- π‘οΈ Error Handling: Robust error handling and detailed feedback
- π LiteLLM-Ollama Management Tools
- Python 3.7+ installed on your system
- Ollama server running and accessible
- LiteLLM proxy running with API access
- LiteLLM API key/Master key for authentication
pip install requests-
Clone or download the scripts to your local machine
-
Get your LiteLLM API key from your LiteLLM proxy setup
-
Add all your Ollama models to LiteLLM:
python3 add_new_models.py \ --ollama-url http://192.168.1.250:11434 \ --litellm-url http://localhost:4000 \ --api-key your-litellm-api-key
-
Clean up any duplicates (if needed):
python3 cleanup_duplicates.py \ --ollama-url http://192.168.1.250:11434 \ --litellm-url http://localhost:4000 \ --api-key your-litellm-api-key
Purpose: Remove duplicate models from your LiteLLM proxy
What it does:
- Scans all models in LiteLLM proxy
- Identifies models with identical names
- Keeps the first occurrence, removes duplicates
- Provides detailed reporting of actions taken
Perfect for: Cleaning up after manual additions or bulk imports that created duplicates
Purpose: Intelligently add Ollama models to LiteLLM proxy
What it does:
- Fetches all available models from your Ollama server
- Checks existing models in LiteLLM proxy
- Adds only new models (unless forced)
- Provides comprehensive progress reporting
Perfect for: Initial setup or adding new models after downloading them to Ollama
# Preview what would be added (safe to run)
python3 add_new_models.py \
--ollama-url http://192.168.1.250:11434 \
--litellm-url http://localhost:4000 \
--api-key sk-1234567890abcdef \
--dry-run
# Add only new models (recommended)
python3 add_new_models.py \
--ollama-url http://192.168.1.250:11434 \
--litellm-url http://localhost:4000 \
--api-key sk-1234567890abcdef
# Force add all models (creates duplicates)
python3 add_new_models.py \
--ollama-url http://192.168.1.250:11434 \
--litellm-url http://localhost:4000 \
--api-key sk-1234567890abcdef \
--force# Preview what would be cleaned (safe to run)
python3 cleanup_duplicates.py \
--ollama-url http://192.168.1.250:11434 \
--litellm-url http://localhost:4000 \
--api-key sk-1234567890abcdef \
--dry-run
# Actually remove duplicates
python3 cleanup_duplicates.py \
--ollama-url http://192.168.1.250:11434 \
--litellm-url http://localhost:4000 \
--api-key sk-1234567890abcdef# 1. First, see what's currently in Ollama
curl http://192.168.1.250:11434/api/tags | jq '.models[].name'
# 2. Preview what would be added to LiteLLM
python3 add_new_models.py --ollama-url http://192.168.1.250:11434 --litellm-url http://localhost:4000 --api-key YOUR_KEY --dry-run
# 3. Add the new models
python3 add_new_models.py --ollama-url http://192.168.1.250:11434 --litellm-url http://localhost:4000 --api-key YOUR_KEY
# 4. If you accidentally created duplicates, clean them up
python3 cleanup_duplicates.py --ollama-url http://192.168.1.250:11434 --litellm-url http://localhost:4000 --api-key YOUR_KEY --dry-run
python3 cleanup_duplicates.py --ollama-url http://192.168.1.250:11434 --litellm-url http://localhost:4000 --api-key YOUR_KEY| Option | Required | Description | Example |
|---|---|---|---|
--ollama-url |
β | URL of your Ollama server | http://192.168.1.250:11434 |
--litellm-url |
β | URL of your LiteLLM proxy | http://localhost:4000 |
--api-key |
β | LiteLLM API key or master key | sk-1234567890abcdef |
--dry-run |
β | Preview changes without executing | --dry-run |
| Option | Description | Use Case |
|---|---|---|
--force |
Add all models even if they exist | When you want to intentionally create duplicates |
No additional options - focused on one task: cleaning duplicates safely
| Scenario | Recommended Approach |
|---|---|
| First-time setup | Use add_new_models.py to bulk-add all your Ollama models |
| Regular maintenance | Use add_new_models.py after downloading new models to Ollama |
| After manual additions | Use cleanup_duplicates.py to remove any duplicates |
| Migration/Backup restore | Use --force with add_new_models.py, then cleanup_duplicates.py |
| Testing changes | Always use --dry-run first to preview changes |
β "Failed to get models: 401"
# Check your API key
curl -H "Authorization: Bearer YOUR_KEY" http://localhost:4000/model/infoβ "Error connecting to Ollama"
# Test Ollama connection
curl http://192.168.1.250:11434/api/tagsβ "No models found in Ollama"
# Check if Ollama has models
ollama listAdd verbose output to see exactly what's happening:
# Check the raw response structure
python3 -c "
import requests
response = requests.get('http://localhost:4000/model/info', headers={'Authorization': 'Bearer YOUR_KEY'})
print(response.status_code)
print(response.text[:500])
"- Ensure all services are running and accessible
- Check firewalls and network connectivity
- Verify URLs don't have typos (common mistake!)
GET /model/info- Retrieve existing modelsPOST /model/new- Add new modelDELETE /model/delete- Remove model by ID
GET /api/tags- List available models
{
"model_name": "llama2:latest",
"litellm_params": {
"model": "ollama/llama2:latest",
"api_base": "http://192.168.1.250:11434"
}
}We welcome contributions! Here's how you can help:
- π Report bugs - Open an issue with details
- π‘ Suggest features - Share your ideas
- π§ Submit PRs - Fix bugs or add features
- π Improve docs - Help make this README even better
# Clone the repository
git clone <your-repo-url>
# Create a virtual environment
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install requests
# Run tests
python3 add_new_models.py --help
python3 cleanup_duplicates.py --help- Follow PEP 8
- Use meaningful variable names
- Add docstrings to functions
- Include error handling
This project is licensed under the MIT License - see the LICENSE file for details.
Made with β€οΈ for the LiteLLM and Ollama community
β Star this repo if it helped you! β
Report Bug β’ Request Feature β’ Documentation