Skip to content

feat: add LiteLLM API handler for 100+ LLM providers#97

Open
RheagalFire wants to merge 4 commits into
SomeOddCodeGuy:masterfrom
RheagalFire:feat/add-litellm-provider
Open

feat: add LiteLLM API handler for 100+ LLM providers#97
RheagalFire wants to merge 4 commits into
SomeOddCodeGuy:masterfrom
RheagalFire:feat/add-litellm-provider

Conversation

@RheagalFire

Copy link
Copy Markdown

Summary

  • Add LiteLLM as an API handler type (litellmChatCompletion) using the litellm Python SDK, enabling access to 100+ LLM providers (Anthropic, Bedrock, Vertex, Gemini, Cohere, Mistral, etc.) without needing a separate proxy
  • Uses litellm.completion() with drop_params=True for cross-provider compatibility
  • Supports both streaming and non-streaming, tool calling, and any litellm model string

Changes

  • Middleware/llmapis/handlers/impl/litellm_api_handler.py - new LiteLLMApiHandler using litellm SDK
  • Middleware/llmapis/llm_api.py - registered "litellmChatCompletion" in handler factory

Tests

Non-streaming E2E (litellm SDK, anthropic/claude-sonnet-4-6):

from Middleware.llmapis.handlers.impl.litellm_api_handler import LiteLLMApiHandler

handler = LiteLLMApiHandler(
    base_url='', api_key=os.environ['ANTHROPIC_API_KEY'],
    gen_input={'temperature': 0.0},
    model_name='anthropic/claude-sonnet-4-6',
    headers={}, stream=False,
    api_type_config={'type': 'litellmChatCompletion',
                     'maxNewTokensPropertyName': 'max_tokens',
                     'streamPropertyName': 'stream'},
    endpoint_config={'maxContextTokenSize': 4096},
    max_tokens=50, dont_include_model=False,
)
result = handler.handle_non_streaming(prompt='What is 2+2? Answer in one word.')
Non-streaming: 'Four'
Streaming: '1, 2, 3, 4, 5!'
SDK E2E PASSED

Usage

Set the API type to litellmChatCompletion in your endpoint's API type config, and set modelNameToSendToAPI to any litellm model string. litellm reads provider API keys from env vars (ANTHROPIC_API_KEY, OPENAI_API_KEY, etc.) automatically.

Risk / Compatibility

  • Additive only. All existing handlers untouched.
  • litellm is an optional dependency, imported at handler init time.

@RheagalFire

Copy link
Copy Markdown
Author

cc @SomeOddCodeGuy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant