Skip to content

Add LiteLLM provider integration - #9

Merged
anilmurty merged 2 commits into
mainfrom
add-litellm-integration
Apr 7, 2026
Merged

anilmurty merged 2 commits into
mainfrom
add-litellm-integration

Conversation

@anilmurty

Copy link
Copy Markdown
Contributor

Summary

  • Adds patch_litellm() integration that wraps litellm.completion and litellm.acompletion (sync + async, including streaming) to create OTel spans with correct per-provider attribution
  • Uses contextvars.ContextVar to prevent double-counted spans when both patch_litellm() and patch_openai()/patch_anthropic() are active — LiteLLM patch wins, inner provider patches skip span creation
  • Adds litellm optional dependency in pyproject.toml
  • Includes 9 unit tests, example agent (examples/single_provider/litellm_agent.py), and doc updates to README.md, examples/README.md, and CLAUDE.md

Test plan

  • 9 new unit tests covering: span creation, provider attribution (from custom_llm_provider and model prefix fallback), sync/async streaming, error handling, uninstall, context var suppression
  • All 232 tests pass
  • ruff check clean

🤖 Generated with Claude Code

anilmurty and others added 2 commits April 7, 2026 15:28
Patches litellm.completion and litellm.acompletion (sync/async, including
streaming) to create OTel spans with correct per-provider attribution via
LiteLLM's custom_llm_provider. A single patch_litellm() covers all 100+
providers that LiteLLM supports.

Uses a contextvars.ContextVar to prevent double-counted spans when both
patch_litellm() and patch_openai()/patch_anthropic() are active — the
LiteLLM patch wins and inner provider patches skip span creation.

Includes 9 unit tests, example agent, and doc updates.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@anilmurty
anilmurty merged commit f1eef61 into main Apr 7, 2026
4 checks passed
@anilmurty
anilmurty deleted the add-litellm-integration branch April 7, 2026 22:33
anilmurty added a commit that referenced this pull request Jun 19, 2026
…#10,#13)

Smoke-test playbook (tests/manual-new-release-tests.md):

- #3 (and #8/#9/#11/#12/#14/#16 — same root cause): code blocks are now
  command-only; the inline "# comments" and "# [ ]" checklists that the markdown
  copy button was pulling into copied commands moved to prose / "- [ ]" lists
  around each block. Added a note explaining the convention.
- #10: corrected the Section 4 trim expectation — with [capture] prompts=false
  (default), trim checks the capture prereq first and prints the capture hint,
  NOT the tokenjam[bloat] install hint (only reachable once capture is on).
- #13: export file is "claude-code-<date>.jsonc", not ".json".

Doc-only; no code changes.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
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