Skip to content

feat: add LiteLLM as provider for 100+ LLM backends#299

Open
RheagalFire wants to merge 2 commits into
msoedov:mainfrom
RheagalFire:feat/add-litellm-provider
Open

feat: add LiteLLM as provider for 100+ LLM backends#299
RheagalFire wants to merge 2 commits into
msoedov:mainfrom
RheagalFire:feat/add-litellm-provider

Conversation

@RheagalFire
Copy link
Copy Markdown

@RheagalFire RheagalFire commented May 18, 2026

cc @msoedov

Summary

Adds LiteLLM as a provider, enabling vulnerability scanning against any of LiteLLM's 100+ supported LLM backends (OpenAI, Anthropic, Google, Groq, Together AI, AWS Bedrock, Azure, Mistral, etc.) through a single provider class.

Changes

File What
agentic_security/llm_providers/litellm_provider.py New LiteLLMProvider(BaseLLMProvider) with async/sync generate() and chat(). Uses drop_params=True for cross-provider compat. Maps litellm.exceptions.RateLimitError to LLMRateLimitError.
agentic_security/llm_providers/factory.py Register "litellm" in _PROVIDERS dict.
agentic_security/llm_providers/__init__.py Import and export LiteLLMProvider.
tests/unit/llm_providers/test_litellm_provider.py 29 unit tests covering init, kwargs, sync/async generate/chat, error handling, factory registration.

Tests

LiteLLM provider tests -- 29 passed:

tests/unit/llm_providers/test_litellm_provider.py::TestLiteLLMProviderInit          5 passed
tests/unit/llm_providers/test_litellm_provider.py::TestLiteLLMProviderCallKwargs    6 passed
tests/unit/llm_providers/test_litellm_provider.py::TestLiteLLMProviderMethods       5 passed
tests/unit/llm_providers/test_litellm_provider.py::TestLiteLLMProviderSync          3 passed
tests/unit/llm_providers/test_litellm_provider.py::TestLiteLLMProviderAsync         2 passed
tests/unit/llm_providers/test_litellm_provider.py::TestLiteLLMProviderErrors        5 passed
tests/unit/llm_providers/test_litellm_provider.py::TestLiteLLMProviderFactory       3 passed
29 passed in 1.04s

Full unit suite -- 317 passed, 0 failures:

$ python -m pytest tests/unit/ -q
317 passed in 16.30s

Lint:

$ ruff check agentic_security/llm_providers/litellm_provider.py tests/unit/llm_providers/test_litellm_provider.py
All checks passed!

Edge cases covered:

  • drop_params=True always set
  • API key/base forwarded when set, omitted when None (env var fallback)
  • Null content returns empty string
  • No usage returns None
  • Rate limit error maps to LLMRateLimitError
  • Auth error, timeout, model-not-found map to LLMProviderError
  • Factory creates provider by name, lists it, uses default model
  • System prompt forwarded correctly

Example usage

from agentic_security.llm_providers import create_provider

# Via factory
provider = create_provider(
    "litellm",
    model="anthropic/claude-sonnet-4-6",
    # api_key omitted -- reads from ANTHROPIC_API_KEY env var
)

# Direct instantiation
from agentic_security.llm_providers import LiteLLMProvider

provider = LiteLLMProvider(
    model="groq/llama-3.3-70b-versatile",
    api_key="gsk-...",
)

# Async
response = await provider.generate("Test prompt for vulnerability scan")

# Sync
response = provider.sync_generate("Test prompt for vulnerability scan")

Any LiteLLM model string works. See LiteLLM provider docs for the full list.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new LiteLLM-backed LLM provider intended to route scans through many LiteLLM-supported backends via the existing provider abstraction and factory.

Changes:

  • Introduces LiteLLMProvider with sync/async generate and chat implementations.
  • Registers and exports the provider through the LLM provider package and factory.
  • Adds unit tests for initialization, request kwargs, response parsing, errors, and factory behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
agentic_security/llm_providers/litellm_provider.py Adds the LiteLLM provider implementation.
agentic_security/llm_providers/factory.py Registers litellm as a built-in provider.
agentic_security/llm_providers/__init__.py Exports LiteLLMProvider from the provider package.
tests/unit/llm_providers/test_litellm_provider.py Adds unit coverage for the new provider.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


from typing import Any

import litellm
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.

2 participants