INSTRUCTIONS FOR LITELLM
This document provides comprehensive instructions for AI agents working in the LiteLLM repository.
OVERVIEW
LiteLLM is a unified interface for 100+ LLMs that:
- Translates inputs to provider-specific completion, embedding, and image generation endpoints
- Provides consistent OpenAI-format output across all providers
- Includes retry/fallback logic across multiple deployments (Router)
- Offers a proxy server (LLM Gateway) with budgets, rate limits, and authentication
- Supports advanced features like function calling, streaming, caching, and observability
REPOSITORY STRUCTURE
Core Components
litellm/ - Main library code
llms/ - Provider-specific implementations (OpenAI, Anthropic, Azure, etc.)
proxy/ - Proxy server implementation (LLM Gateway)
router_utils/ - Load balancing and fallback logic
types/ - Type definitions and schemas
integrations/ - Third-party integrations (observability, caching, etc.)
Key Directories
tests/ - Comprehensive test suites
docs/my-website/ - Documentation website
ui/litellm-dashboard/ - Admin dashboard UI
enterprise/ - Enterprise-specific features
DEVELOPMENT GUIDELINES
MAKING CODE CHANGES
Provider Implementations: When adding/modifying LLM providers:
- Follow existing patterns in
litellm/llms/{provider}/
- Implement proper transformation classes that inherit from
BaseConfig
- Support both sync and async operations
- Handle streaming responses appropriately
- Include proper error handling with provider-specific exceptions
Type Safety:
- Use proper type hints throughout
- Update type definitions in
litellm/types/
- Ensure compatibility with both Pydantic v1 and v2
Testing:
- Add tests in appropriate
tests/ subdirectories
- Include both unit tests and integration tests
- Test provider-specific functionality thoroughly
- Consider adding load tests for performance-critical changes
MAKING CODE CHANGES FOR THE UI (IGNORE FOR BACKEND)
Tremor is DEPRECATED, do not use Tremor components in new features/changes
- The only exception is the Tremor Table component and its required Tremor Table sub components.
Use Common Components as much as possible:
- These are usually defined in the
common_components directory
- Use these components as much as possible and avoid building new components unless needed
Testing:
- The codebase uses Vitest and React Testing Library
- Query Priority Order: Use query methods in this order:
getByRole, getByLabelText, getByPlaceholderText, getByText, getByTestId
- Always use
screen instead of destructuring from render() (e.g., use screen.getByText() not getByText)
- Wrap user interactions in
act(): Always wrap fireEvent calls with act() to ensure React state updates are properly handled
- Use
query methods for absence checks: Use queryBy* methods (not getBy*) when expecting an element to NOT be present
- Test names must start with "should": All test names should follow the pattern
it("should ...")
- Mock external dependencies: Check
setupTests.ts for global mocks and mock child components/networking calls as needed
- Structure tests properly:
- First test should verify the component renders successfully
- Subsequent tests should focus on functionality and user interactions
- Use
waitFor for async operations that aren't already awaited
- Avoid using
querySelector: Prefer React Testing Library queries over direct DOM manipulation
IMPORTANT PATTERNS
Function/Tool Calling:
- LiteLLM standardizes tool calling across providers
- OpenAI format is the standard, with transformations for other providers
- See
litellm/llms/anthropic/chat/transformation.py for complex tool handling
Streaming:
- All providers should support streaming where possible
- Use consistent chunk formatting across providers
- Handle both sync and async streaming
Error Handling:
- Use provider-specific exception classes
- Maintain consistent error formats across providers
- Include proper retry logic and fallback mechanisms
Configuration:
- Support both environment variables and programmatic configuration
- Use
BaseConfig classes for provider configurations
- Allow dynamic parameter passing
PROXY SERVER (LLM GATEWAY)
The proxy server is a critical component that provides:
- Authentication and authorization
- Rate limiting and budget management
- Load balancing across multiple models/deployments
- Observability and logging
- Admin dashboard UI
- Enterprise features
Key files:
litellm/proxy/proxy_server.py - Main server implementation
litellm/proxy/auth/ - Authentication logic
litellm/proxy/management_endpoints/ - Admin API endpoints
MCP (MODEL CONTEXT PROTOCOL) SUPPORT
LiteLLM supports MCP for agent workflows:
- MCP server integration for tool calling
- Transformation between OpenAI and MCP tool formats
- Support for external MCP servers (Zapier, Jira, Linear, etc.)
- See
litellm/experimental_mcp_client/ and litellm/proxy/_experimental/mcp_server/
RUNNING SCRIPTS
Use poetry run python script.py to run Python scripts in the project environment (for non-test files).
GITHUB TEMPLATES
When opening issues or pull requests, follow these templates:
Bug Reports (.github/ISSUE_TEMPLATE/bug_report.yml)
- Describe what happened vs. expected behavior
- Include relevant log output
- Specify LiteLLM version
- Indicate if you're part of an ML Ops team (helps with prioritization)
Feature Requests (.github/ISSUE_TEMPLATE/feature_request.yml)
- Clearly describe the feature
- Explain motivation and use case with concrete examples
Pull Requests (.github/pull_request_template.md)
- Add at least 1 test in
tests/litellm/
- Ensure
make test-unit passes
TESTING CONSIDERATIONS
- Provider Tests: Test against real provider APIs when possible
- Proxy Tests: Include authentication, rate limiting, and routing tests
- Performance Tests: Load testing for high-throughput scenarios
- Integration Tests: End-to-end workflows including tool calling
DOCUMENTATION
- Keep documentation in sync with code changes
- Update provider documentation when adding new providers
- Include code examples for new features
- Update changelog and release notes
SECURITY CONSIDERATIONS
- Handle API keys securely
- Validate all inputs, especially for proxy endpoints
- Consider rate limiting and abuse prevention
- Follow security best practices for authentication
ENTERPRISE FEATURES
- Some features are enterprise-only
- Check
enterprise/ directory for enterprise-specific code
- Maintain compatibility between open-source and enterprise versions
COMMON PITFALLS TO AVOID
- Breaking Changes: LiteLLM has many users - avoid breaking existing APIs
- Provider Specifics: Each provider has unique quirks - handle them properly
- Rate Limits: Respect provider rate limits in tests
- Memory Usage: Be mindful of memory usage in streaming scenarios
- Dependencies: Keep dependencies minimal and well-justified
- UI/Backend Contract Mismatch: When adding a new entity type to the UI, always check whether the backend endpoint accepts a single value or an array. Match the UI control accordingly (single-select vs. multi-select) to avoid silently dropping user selections
- Missing Tests for New Entity Types: When adding a new entity type (e.g., in
EntityUsage, UsageViewSelect), always add corresponding tests in the existing test files and update any icon/component mocks
HELPFUL RESOURCES
- Main documentation: https://docs.litellm.ai/
- Provider-specific docs in
docs/my-website/docs/providers/
- Admin UI for testing proxy features
WHEN IN DOUBT
- Follow existing patterns in the codebase
- Check similar provider implementations
- Ensure comprehensive test coverage
- Update documentation appropriately
- Consider backward compatibility impact
1---2name: instructions-for-litellm-23description: This document provides comprehensive instructions for AI agents working in the LiteLLM repository.4---5# INSTRUCTIONS FOR LITELLM67This document provides comprehensive instructions for AI agents working in the LiteLLM repository.89## OVERVIEW1011LiteLLM is a unified interface for 100+ LLMs that:12- Translates inputs to provider-specific completion, embedding, and image generation endpoints13- Provides consistent OpenAI-format output across all providers14- Includes retry/fallback logic across multiple deployments (Router)15- Offers a proxy server (LLM Gateway) with budgets, rate limits, and authentication16- Supports advanced features like function calling, streaming, caching, and observability1718## REPOSITORY STRUCTURE1920### Core Components21- `litellm/` - Main library code22 - `llms/` - Provider-specific implementations (OpenAI, Anthropic, Azure, etc.)23 - `proxy/` - Proxy server implementation (LLM Gateway)24 - `router_utils/` - Load balancing and fallback logic25 - `types/` - Type definitions and schemas26 - `integrations/` - Third-party integrations (observability, caching, etc.)2728### Key Directories29- `tests/` - Comprehensive test suites30- `docs/my-website/` - Documentation website31- `ui/litellm-dashboard/` - Admin dashboard UI32- `enterprise/` - Enterprise-specific features3334## DEVELOPMENT GUIDELINES3536### MAKING CODE CHANGES37381. **Provider Implementations**: When adding/modifying LLM providers:39 - Follow existing patterns in `litellm/llms/{provider}/`40 - Implement proper transformation classes that inherit from `BaseConfig`41 - Support both sync and async operations42 - Handle streaming responses appropriately43 - Include proper error handling with provider-specific exceptions44452. **Type Safety**: 46 - Use proper type hints throughout47 - Update type definitions in `litellm/types/`48 - Ensure compatibility with both Pydantic v1 and v249503. **Testing**:51 - Add tests in appropriate `tests/` subdirectories52 - Include both unit tests and integration tests53 - Test provider-specific functionality thoroughly54 - Consider adding load tests for performance-critical changes5556### MAKING CODE CHANGES FOR THE UI (IGNORE FOR BACKEND)57581. **Tremor is DEPRECATED, do not use Tremor components in new features/changes**59 - The only exception is the Tremor Table component and its required Tremor Table sub components.60612. **Use Common Components as much as possible**:62 - These are usually defined in the `common_components` directory63 - Use these components as much as possible and avoid building new components unless needed64653. **Testing**:66 - The codebase uses **Vitest** and **React Testing Library**67 - **Query Priority Order**: Use query methods in this order: `getByRole`, `getByLabelText`, `getByPlaceholderText`, `getByText`, `getByTestId`68 - **Always use `screen`** instead of destructuring from `render()` (e.g., use `screen.getByText()` not `getByText`)69 - **Wrap user interactions in `act()`**: Always wrap `fireEvent` calls with `act()` to ensure React state updates are properly handled70 - **Use `query` methods for absence checks**: Use `queryBy*` methods (not `getBy*`) when expecting an element to NOT be present71 - **Test names must start with "should"**: All test names should follow the pattern `it("should ...")`72 - **Mock external dependencies**: Check `setupTests.ts` for global mocks and mock child components/networking calls as needed73 - **Structure tests properly**:74 - First test should verify the component renders successfully75 - Subsequent tests should focus on functionality and user interactions76 - Use `waitFor` for async operations that aren't already awaited77 - **Avoid using `querySelector`**: Prefer React Testing Library queries over direct DOM manipulation7879### IMPORTANT PATTERNS80811. **Function/Tool Calling**:82 - LiteLLM standardizes tool calling across providers83 - OpenAI format is the standard, with transformations for other providers84 - See `litellm/llms/anthropic/chat/transformation.py` for complex tool handling85862. **Streaming**:87 - All providers should support streaming where possible88 - Use consistent chunk formatting across providers89 - Handle both sync and async streaming90913. **Error Handling**:92 - Use provider-specific exception classes93 - Maintain consistent error formats across providers94 - Include proper retry logic and fallback mechanisms95964. **Configuration**:97 - Support both environment variables and programmatic configuration98 - Use `BaseConfig` classes for provider configurations99 - Allow dynamic parameter passing100101## PROXY SERVER (LLM GATEWAY)102103The proxy server is a critical component that provides:104- Authentication and authorization105- Rate limiting and budget management106- Load balancing across multiple models/deployments107- Observability and logging108- Admin dashboard UI109- Enterprise features110111Key files:112- `litellm/proxy/proxy_server.py` - Main server implementation113- `litellm/proxy/auth/` - Authentication logic114- `litellm/proxy/management_endpoints/` - Admin API endpoints115116## MCP (MODEL CONTEXT PROTOCOL) SUPPORT117118LiteLLM supports MCP for agent workflows:119- MCP server integration for tool calling120- Transformation between OpenAI and MCP tool formats121- Support for external MCP servers (Zapier, Jira, Linear, etc.)122- See `litellm/experimental_mcp_client/` and `litellm/proxy/_experimental/mcp_server/`123124## RUNNING SCRIPTS125126Use `poetry run python script.py` to run Python scripts in the project environment (for non-test files).127128## GITHUB TEMPLATES129130When opening issues or pull requests, follow these templates:131132### Bug Reports (`.github/ISSUE_TEMPLATE/bug_report.yml`)133- Describe what happened vs. expected behavior134- Include relevant log output135- Specify LiteLLM version136- Indicate if you're part of an ML Ops team (helps with prioritization)137138### Feature Requests (`.github/ISSUE_TEMPLATE/feature_request.yml`)139- Clearly describe the feature140- Explain motivation and use case with concrete examples141142### Pull Requests (`.github/pull_request_template.md`)143- Add at least 1 test in `tests/litellm/`144- Ensure `make test-unit` passes145146147## TESTING CONSIDERATIONS1481491. **Provider Tests**: Test against real provider APIs when possible1502. **Proxy Tests**: Include authentication, rate limiting, and routing tests1513. **Performance Tests**: Load testing for high-throughput scenarios1524. **Integration Tests**: End-to-end workflows including tool calling153154## DOCUMENTATION155156- Keep documentation in sync with code changes157- Update provider documentation when adding new providers158- Include code examples for new features159- Update changelog and release notes160161## SECURITY CONSIDERATIONS162163- Handle API keys securely164- Validate all inputs, especially for proxy endpoints165- Consider rate limiting and abuse prevention166- Follow security best practices for authentication167168## ENTERPRISE FEATURES169170- Some features are enterprise-only171- Check `enterprise/` directory for enterprise-specific code172- Maintain compatibility between open-source and enterprise versions173174## COMMON PITFALLS TO AVOID1751761. **Breaking Changes**: LiteLLM has many users - avoid breaking existing APIs1772. **Provider Specifics**: Each provider has unique quirks - handle them properly1783. **Rate Limits**: Respect provider rate limits in tests1794. **Memory Usage**: Be mindful of memory usage in streaming scenarios1805. **Dependencies**: Keep dependencies minimal and well-justified1816. **UI/Backend Contract Mismatch**: When adding a new entity type to the UI, always check whether the backend endpoint accepts a single value or an array. Match the UI control accordingly (single-select vs. multi-select) to avoid silently dropping user selections1827. **Missing Tests for New Entity Types**: When adding a new entity type (e.g., in `EntityUsage`, `UsageViewSelect`), always add corresponding tests in the existing test files and update any icon/component mocks183184## HELPFUL RESOURCES185186- Main documentation: https://docs.litellm.ai/187- Provider-specific docs in `docs/my-website/docs/providers/`188- Admin UI for testing proxy features189190## WHEN IN DOUBT191192- Follow existing patterns in the codebase193- Check similar provider implementations194- Ensure comprehensive test coverage195- Update documentation appropriately196- Consider backward compatibility impact