Skip to content

Remove LiteLLM, replace with OpenAI + Anthropic SDKs#14

Merged
strickvl merged 3 commits into
mainfrom
feat/remove-litellm
Apr 3, 2026
Merged

Remove LiteLLM, replace with OpenAI + Anthropic SDKs#14
strickvl merged 3 commits into
mainfrom
feat/remove-litellm

Conversation

@strickvl

@strickvl strickvl commented Apr 3, 2026

Copy link
Copy Markdown
Owner

Summary

  • Remove litellm dependency due to recent security vulnerability, replacing with direct SDK usage
  • Add provider routing layer (src/utils/provider_routing.py) that resolves model prefixes (gemini/, openai/, anthropic/, ollama/, openrouter/) to the correct SDK + endpoint
  • Migrate LLM transport: instructor.from_litellminstructor.from_openai / instructor.from_anthropic based on model prefix
  • Unify cloud_generation/local_generation into shared _structured_generation(), eliminating ~200 lines of duplicated retry/recovery logic and fixing a latent Anthropic guard bug
  • Migrate cloud embeddings from litellm.embedding() to OpenAI SDK embeddings.create()
  • Clean up dead code: get_llm_callbacks, BRAINTRUST_PROJECT_ID, get_ollama_model_name, OLLAMA_API_KEY, disable_llm_callbacks
  • Dependency changes: bump instructor>=1.14, add openai>=1.0, add anthropic as optional extra (pip install hinbox[anthropic])
  • Bump extraction cache version to v2 (transport change invalidates cached extractions)

Supported model prefixes

Prefix SDK Example
gemini/ OpenAI (Google's compatible endpoint) gemini/gemini-2.0-flash
openai/ OpenAI openai/gpt-4o
anthropic/ Anthropic anthropic/claude-sonnet-4-20250514
ollama/ OpenAI (local) ollama/qwen2.5:32b
openrouter/ OpenAI (OpenRouter) openrouter/anthropic/claude-3.5-sonnet

Test plan

  • All 289 existing tests pass
  • 20 new provider routing tests added
  • Lint and format clean (just ci passes)
  • Smoke test with live Gemini model (just process)
  • Smoke test with local Ollama model (just process --local)

LiteLLM had a significant security vulnerability. This replaces it with
direct SDK usage routed through a new provider routing layer.

- Add src/utils/provider_routing.py for model prefix → SDK target resolution
- Migrate src/utils/llm.py: replace instructor.from_litellm with
  instructor.from_openai / from_anthropic based on model prefix
- Unify cloud_generation/local_generation into shared _structured_generation
  (eliminates ~200 lines of duplicated retry/recovery logic)
- Migrate cloud embeddings from litellm.embedding to OpenAI SDK
- Remove dead code: get_llm_callbacks, BRAINTRUST_PROJECT_ID,
  get_ollama_model_name, OLLAMA_API_KEY, disable_llm_callbacks
- Bump instructor>=1.14 (adds from_anthropic), add openai>=1.0,
  add anthropic as optional extra
- Bump extraction cache version to v2 (transport change)
- Update docs: README, CLAUDE.md, AGENTS.md
@strickvl strickvl added the enhancement New feature or request label Apr 3, 2026
strickvl added 2 commits April 3, 2026 17:44
Ruff 0.15 (local) and 0.9 (CI lockfile) disagree on import grouping
for this file. Restore the main-branch version to avoid CI lint failure.
The unpinned "ruff" dep resolved to 0.9.6 in CI but 0.15.7 locally,
causing import sorting disagreements. Pin to >=0.15 so both environments
use the same rules.
@strickvl strickvl merged commit 5b5c634 into main Apr 3, 2026
2 checks passed
@strickvl strickvl deleted the feat/remove-litellm branch April 3, 2026 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant