Skip to content

Feat/add litellm provider#685

Open
RheagalFire wants to merge 3 commits into
valentinfrlch:mainfrom
RheagalFire:feat/add-litellm-provider
Open

Feat/add litellm provider#685
RheagalFire wants to merge 3 commits into
valentinfrlch:mainfrom
RheagalFire:feat/add-litellm-provider

Conversation

@RheagalFire

Copy link
Copy Markdown

Add LiteLLM as a native provider using the LiteLLM Python SDK (litellm.acompletion), giving ha-llmvision access to 100+ LLM providers (Anthropic, Google, AWS Bedrock, Groq, Ollama, etc.) without requiring a separate proxy deployment.

Users set their provider's API key and use LiteLLM's model format (e.g. anthropic/claude-sonnet-4-6, gemini/gemini-2.0-flash). LiteLLM routes to the correct provider and translates the request format automatically. drop_params=True handles per-provider parameter differences.

Changes:

  • New LiteLLM(Provider) class in providers.py using litellm.acompletion() for both vision and text requests
  • Specific exception handling for AuthenticationError, NotFoundError, RateLimitError, ContextWindowExceededError, Timeout, and BadRequestError from litellm.exceptions
  • Timeout from HA settings (request_timeout) passed through to litellm SDK calls
  • Config flow matching Groq's pattern (API key + model + temperature/top_p, no proxy URL needed)
  • litellm>=1.80,<1.88 added to manifest.json requirements
  • 23 unit tests covering: init, kwargs building, successful completion, auth error, model not found, rate limit, context window exceeded, timeout, bad request, empty choices, null content, malformed response, vision data prep, text data prep, validate success/failure, timeout passthrough, model string format

Usage:

  1. In HA, add LLM Vision integration, select "LiteLLM"
  2. Enter your provider API key (e.g. Anthropic key, Google key)
  3. Set model in LiteLLM format: anthropic/claude-sonnet-4-6, openai/gpt-4o-mini, gemini/gemini-2.0-flash

No proxy server needed - LiteLLM SDK handles provider routing directly.

import litellm
response = litellm.completion(
    model="anthropic/claude-sonnet-4-6",
    messages=[{"role": "user", "content": "Describe this image"}],
)
print(response.choices[0].message.content)

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