Skip to content

feat: add LiteLLM provider adapter (v0.2.6)#14

Merged
arieradle merged 7 commits intomainfrom
feat/litellm-adapter
Mar 12, 2026
Merged

feat: add LiteLLM provider adapter (v0.2.6)#14
arieradle merged 7 commits intomainfrom
feat/litellm-adapter

Conversation

@arieradle
Copy link
Owner

Summary

  • Adds shekel/providers/litellm.pyLiteLLMAdapter implementing the ProviderAdapter ABC
  • Patches litellm.completion and litellm.acompletion (module-level functions, not class methods)
  • Supports streaming via stream_options={"include_usage": True} injection
  • Registers adapter in shekel/providers/__init__.py behind try/except ImportError
  • Adds litellm = ["litellm>=1.0.0"] optional extra and mypy override to pyproject.toml
  • Extends tests/providers/conftest.py with MockLiteLLMResponse, MockLiteLLMChunk, make_litellm_response, make_litellm_stream
  • 22 TDD tests: name, isinstance, token extraction (valid/None/missing/prefixed model), stream detection, stream wrapping, patch lifecycle, cost recording (sync + stream + async)

Design notes

  • LiteLLM uses OpenAI-compatible response format — reuses _extract_openai_tokens() in wrappers
  • Model names may include provider prefix (e.g. openai/gpt-4o) — passed through as-is to _pricing
  • Idempotent install_patches(): guarded by "litellm_sync" not in _patch._originals

Test plan

  • pytest tests/providers/test_litellm_adapter.py -v — 22/22 pass
  • pytest tests/ --ignore=tests/integrations/test_groq_integration.py --ignore=tests/integrations/test_gemini_integration.py --ignore=tests/performance/ -q — 405 passed, 0 failures
  • ruff check — clean

🤖 Generated with Claude Code

Adds LiteLLMAdapter with full sync/async patch support for litellm.completion
and litellm.acompletion, including streaming. Token extraction follows the
OpenAI-compatible format LiteLLM uses (prompt_tokens/completion_tokens).
22 TDD tests cover adapter interface, token extraction, stream wrapping, patch
lifecycle, and end-to-end cost recording.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Mar 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

arieradle and others added 6 commits March 12, 2026 12:43
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds test_patch_coverage.py covering all previously-uncovered branches:
error paths (RuntimeError/AttributeError/Exception swallowing), async stream
edge cases (no-usage fallback, broken chunk attrs), and all new LiteLLM
sync/async wrappers including the async streaming path.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Covers the ImportError branch (lines 23-24) hit when litellm is absent,
by reloading the module with litellm blocked in sys.modules.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add docs/integrations/litellm.md — full guide with basic usage, async,
  streaming, budget enforcement, fallback, multi-provider, and LangGraph
- mkdocs.yml: add LiteLLM to nav (before LangGraph), reorder integrations
- index.md: add LiteLLM install tab, update feature card, supported models
  section, and "What's New in v0.2.6" with LiteLLM + budgeted_graph cards
- installation.md: add litellm extra, dependency table row, troubleshooting
- quickstart.md: add LiteLLM example, update frameworks section with
  budgeted_graph helper
- integrations/langgraph.md: document budgeted_graph() convenience helper
- how-it-works.md: add LiteLLM to patched endpoints and token extraction
- extending.md: note that LiteLLM is now built-in
- changelog.md: document LiteLLM adapter and LangGraph helper under 0.2.6

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…d_graph()

- examples/litellm_basic.py: 6 sections covering basic tracking, multi-provider,
  streaming, fallback, call-count limit, and async usage with LiteLLM
- examples/langgraph_demo.py: updated to showcase the new budgeted_graph()
  convenience helper alongside direct budget() usage and fallback model demo

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Examples use narrative import ordering for readability and should not
be subject to strict linting rules.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@arieradle arieradle merged commit 7bab6eb into main Mar 12, 2026
9 checks passed
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