Skip to main content

LiteLLM Integration Guide

Complete guide for using multiple LLM providers with the MCP Server with LangGraph.

Table of Contents

Overview

The MCP Server with LangGraph uses LiteLLM to support 100+ LLM providers with a unified interface. This allows you to:
  • ✅ Switch between providers without code changes
  • ✅ Use open-source models (Llama, Qwen, Mistral, etc.)
  • ✅ Implement automatic fallback between models
  • ✅ Optimize costs by provider/model selection
  • ✅ Test locally with Ollama before deploying

Supported Providers

Cloud Providers

Open-Source (Ollama)

Configuration

Environment Variables

Create or update .env:

API Keys

Provider Setup

2. Anthropic (Claude)

3. OpenAI

4. Azure OpenAI

5. AWS Bedrock

6. Ollama (Local/Open-Source)

Model Examples

Anthropic Models

OpenAI Models

Google Gemini Models (Default/Recommended)

Ollama (Open-Source)

Fallback Strategy

The agent automatically falls back to alternative models if the primary fails:

Fallback Order Example

Fallback Behavior

  1. Primary model fails → Try first fallback
  2. First fallback fails → Try second fallback
  3. All fallbacks fail → Return error
Fallback triggers on:
  • API rate limits
  • Model unavailability
  • Network errors
  • Timeout errors

Best Practices

1. Cost Optimization

2. Latency Optimization

Fastest models:

3. Context Length

Large context needs:

4. Multilingual Support

Best for non-English:

5. Code Generation

Best for coding:

Testing Different Providers

Quick Test Script

Test with MCP Server

Monitoring

LiteLLM usage is automatically tracked with OpenTelemetry:
View in Jaeger: http://localhost:16686

Troubleshooting

API Key Not Working

Ollama Connection Failed

Model Not Found

Resources

Support

For LiteLLM issues:
Last Updated: 2025-01-10