Skip to content

feat: add LiteLLM as AI gateway provider#502

Open
RheagalFire wants to merge 1 commit into
explosion:mainfrom
RheagalFire:feat/add-litellm-provider
Open

feat: add LiteLLM as AI gateway provider#502
RheagalFire wants to merge 1 commit into
explosion:mainfrom
RheagalFire:feat/add-litellm-provider

Conversation

@RheagalFire
Copy link
Copy Markdown

@RheagalFire RheagalFire commented May 28, 2026

Description

Adds LiteLLM as a new REST backend for spacy-llm, giving users access to 100+ LLM providers (OpenAI, Anthropic, Azure, Bedrock, Vertex AI, Groq, Ollama, etc.) through the LiteLLM Python SDK.

LiteLLM is added as a new provider under spacy_llm/models/rest/litellm/, following the exact same pattern as the existing OpenAI, Anthropic, and Cohere providers. It registers as spacy.LiteLLM.v1 in the model registry.

Files added:

  • spacy_llm/models/rest/litellm/model.py -- LiteLLM class extending REST, uses litellm.completion() with drop_params=True
  • spacy_llm/models/rest/litellm/registry.py -- @registry.llm_models("spacy.LiteLLM.v1") registration
  • spacy_llm/models/rest/litellm/__init__.py -- exports

Files modified:

  • spacy_llm/models/rest/__init__.py -- registered litellm module

Live E2E (Anthropic Claude Sonnet via Azure Foundry):

>>> litellm.completion(model='anthropic/claude-sonnet-4-6', messages=[...], drop_params=True)
Response: 4
Model: claude-sonnet-4-6

Example usage:

Config-based (spacy pipeline):

# config.cfg
[components.llm.model]
@llm_models = "spacy.LiteLLM.v1"
name = "anthropic/claude-haiku-4-5"

Python:

from spacy_llm.models.rest.litellm import LiteLLM

llm = LiteLLM(
    name="anthropic/claude-haiku-4-5",
    endpoint="",
    config={"temperature": 0},
    strict=True,
    max_tries=3,
    interval=1.0,
    max_request_time=30,
    context_length=None,
)
# Provider API keys read from env vars (e.g. ANTHROPIC_API_KEY)
responses = llm([["Summarize this text: ..."]])

Model names use the litellm provider/model-name format (e.g. anthropic/claude-haiku-4-5, openai/gpt-4o, bedrock/anthropic.claude-3-haiku).

Corresponding documentation PR

N/A

Types of change

New feature -- adds a new LLM provider backend.

Checklist

  • I confirm that I have the right to submit this contribution under the project's MIT license.
  • I ran all tests in tests and usage_examples/tests, and all new and existing tests passed. This includes
    • all external tests (i. e. pytest ran with --external)
    • all tests requiring a GPU (i. e. pytest ran with --gpu)
  • My changes don't require a change to the documentation, or if they do, I've added all required information.

@RheagalFire
Copy link
Copy Markdown
Author

cc @svlandeg @rmitsch

@svlandeg
Copy link
Copy Markdown
Contributor

Hi @RheagalFire, I'm not involved in maintaining this library anymore, so please refrain from further pings 🙏

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