Implementation:416rehman DeepZero LiteLLMBackend
| Knowledge Sources | |
|---|---|
| Domains | LLM_Backend, API_Integration |
| Last Updated | 2026-10-27 00:00 GMT |
Overview
Default fallback LLM backend providing API-key access to every endpoint supported by the LiteLLM library, registered as the catch-all for unregistered model schemes.
Description
The LiteLLMBackend class is the default LLM backend. Any model string whose scheme is not claimed by a more specific backend lands here: "openai/gpt-4o", "gemini/gemini-pro", "gpt-4o", etc. It wraps the litellm library, which provides a unified completion API across dozens of providers.
Key characteristics:
- Default registration: registered with default=True, making it the _DEFAULT_BACKEND that handles every unregistered scheme.
- No scheme: unlike CLI backends, LiteLLMBackend does not declare a scheme—it is not matched by name but by fallthrough.
- Error roles: litellm's exception classes (RateLimitError, ContextWindowExceededError, APIConnectionError, APIError) are resolved at construction time with safe fallbacks (_NeverRaised) for test mocks that lack the real classes.
- Non-retryable opt-out: litellm surfaces auth problems as APIError subclasses that are also in the retryable set, so there is no distinct fail-fast class. The backend declares _NeverRaised for non_retryable_errors to avoid catching too broadly.
- validate_model: checks that litellm is installed and that the required API keys are present in the environment via litellm.validate_environment().
Usage
- API-key models: set model: "openai/gpt-4o" in pipeline YAML.
- Any litellm-supported model: the scheme falls through to this backend automatically.
- Requires the [llm] extra: pip install deepzero[llm] (installs litellm).
Code Reference
Source Location
- Repository: DeepZero
- File: src/deepzero/engine/backends/litellm_backend.py
Signature
class LiteLLMBackend(LLMBackend):
display_name: ClassVar[str] = "litellm"
non_retryable_errors: ClassVar[tuple[type[BaseException], ...]] = (_NeverRaised,)
def __init__(self, model: str, **kwargs: Any): ...
def raw_complete(self, messages: list[dict[str, str]], **kwargs: Any) -> str: ...
@classmethod
def validate_model(cls, model: str) -> list[str]: ...
@property
def provider_name(self) -> str: ...
@property
def model_name(self) -> str: ...
Import
from deepzero.engine.backends.litellm_backend import LiteLLMBackend
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| model | str | Yes | Model string (e.g., "openai/gpt-4o") |
| messages | list[dict] | Yes (raw_complete) | Chat messages |
| kwargs | dict | No | Generation parameters forwarded to litellm.completion() |
Outputs
| Name | Type | Description |
|---|---|---|
| raw_complete() returns | str | Response text from litellm.completion() |
Usage Examples
Pipeline YAML (OpenAI)
# Uses LiteLLMBackend by fallthrough (scheme "openai" not registered to a CLI backend)
model: openai/gpt-4o
Environment Setup
# LiteLLM reads API keys from environment variables:
export OPENAI_API_KEY="sk-..."
export ANTHROPIC_API_KEY="sk-ant-..."
# Or via .env file (loaded by DeepZero CLI)
Related Pages
Implements Principle
- Principle:416rehman_DeepZero_LLM_Backend_Architecture
- Principle:416rehman_DeepZero_LLM_Backend_Dispatch