Skip to main content

Overview

LiteLLM allows you to add custom LLM providers by implementing the CustomLLM base class. This enables you to integrate proprietary models, internal APIs, or specialized LLM services that aren’t natively supported.

When to Use Custom Providers

  • Integrate internal/proprietary LLM APIs
  • Add support for new LLM providers before native support
  • Wrap existing APIs with custom logic (rate limiting, caching, etc.)
  • Implement specialized model endpoints

Quick Start

1

Create Custom Provider Class

Inherit from CustomLLM and implement required methods:
2

Register Your Provider

Register the custom provider with LiteLLM:
3

Use Your Provider

Call your custom provider like any other:

Implementation Guide

Required Methods

Optional Methods

Complete Example

Error Handling

Always use CustomLLMError for exceptions:

Using with LiteLLM Proxy

Deploy custom providers via the proxy:
config.yaml
Load custom provider in proxy startup:

Best Practices

Leverage LiteLLM’s HTTP handlers for connection pooling:
Provide accurate usage statistics:
Implement exponential backoff:
Transform tool calls appropriately:

Testing Your Provider

Reference

Source Files

  • Base class: litellm/llms/custom_llm.py:47
  • HTTP handlers: litellm/llms/custom_httpx/http_handler.py
  • Error handling: litellm/llms/custom_llm.py:34