nexent icon indicating copy to clipboard operation
nexent copied to clipboard

feat: add LiteLLM as unified LLM provider

Open RheagalFire opened this issue 6 months ago • 1 comments

Summary

  • Adds LiteLLM as a model provider, giving nexent users access to 100+ LLM providers (OpenAI, Anthropic, Google Gemini, Azure, Bedrock, Ollama, etc.) through litellm.completion() as an SDK dependency.
  • Two integration points: backend provider for model discovery + SDK model for inference.

Changes

  • backend/consts/provider.py: added LITELLM = "litellm" to ProviderEnum
  • backend/services/providers/litellm_provider.py: new LiteLLMModelProvider for model discovery via /v1/models
  • backend/services/model_provider_service.py: wired LiteLLM into get_provider_models() dispatch
  • sdk/nexent/core/models/litellm_llm.py: new LiteLLMModel with streaming, token tracking, tool calling, drop_params=True
  • sdk/nexent/core/models/__init__.py: registered LiteLLMModel
  • test/sdk/test_litellm_model.py: 17 tests (init, streaming, credentials, edge cases, live E2E)

Tests

Unit tests (17/17 pass):

TestInit::test_basic PASSED
TestInit::test_with_credentials PASSED
TestCall::test_streaming_output PASSED
TestCall::test_api_key_forwarded PASSED
TestCall::test_api_key_omitted_when_none PASSED
TestCall::test_api_base_forwarded PASSED
TestCall::test_drop_params_set PASSED
TestCall::test_response_format PASSED
TestCall::test_stop_sequences PASSED
TestCall::test_token_tracking PASSED
TestEdgeCases::test_empty_stream PASSED
TestEdgeCases::test_chunk_without_choices PASSED
TestEdgeCases::test_context_length_exceeded PASSED
TestEdgeCases::test_auth_error_propagates PASSED
TestEdgeCases::test_import_error PASSED
TestEdgeCases::test_stop_event_interrupts PASSED
TestLiveE2E::test_live_streaming PASSED
============================== 17 passed in 3.64s ==============================

Live E2E (Anthropic claude-sonnet-4-6 via Azure Foundry, streaming):

Live E2E response: 'OK'

Risk / Compatibility

  • Additive only. Existing providers and OpenAIModel untouched.
  • litellm is lazy-imported so the base install is unaffected.
  • drop_params=True ensures cross-provider compatibility.

Example usage

from nexent.core.models import LiteLLMModel

# Any LiteLLM-supported provider
model = LiteLLMModel(
    model_id="anthropic/claude-sonnet-4-20250514",
    api_key="sk-ant-...",
)

# Or Google Gemini
model = LiteLLMModel(model_id="gemini/gemini-2.5-flash")
# export GEMINI_API_KEY=...

response = model([{"role": "user", "content": "Hello!"}])
print(response.content)

RheagalFire avatar Jun 02 '26 18:06 RheagalFire

cc @Dallas98 @WMC001

RheagalFire avatar Jun 02 '26 18:06 RheagalFire

LGTM. LiteLLM integration follows the existing provider pattern. No issues found.

WMC001 avatar Jun 24 '26 07:06 WMC001