Skip to content

Feat/add litellm provider#268

Open
RheagalFire wants to merge 2 commits into
appleboy:mainfrom
RheagalFire:feat/add-litellm-provider
Open

Feat/add litellm provider#268
RheagalFire wants to merge 2 commits into
appleboy:mainfrom
RheagalFire:feat/add-litellm-provider

Conversation

@RheagalFire

Copy link
Copy Markdown

Summary

  • Adds LiteLLM as a first-class AI gateway provider, giving CodeGPT users access to 100+ LLM providers (Anthropic, Bedrock, Vertex AI, Groq, Mistral, Cohere, etc.) through a single proxy endpoint.
  • No new Go dependencies - reuses the existing go-openai SDK since the LiteLLM proxy speaks the OpenAI Chat Completions protocol.

Motivation

CodeGPT currently supports 4 providers (OpenAI, Azure, Gemini, Anthropic) plus OpenAI-compatible endpoints via base_url. Users who want to use providers like AWS Bedrock, Google Vertex AI, Groq, Mistral, or Cohere need to set up separate proxy infrastructure. LiteLLM is a widely-adopted open-source AI gateway (45k+ GitHub stars) that normalizes 100+ provider APIs into the OpenAI format - users run litellm --model anthropic/claude-sonnet-4-6 and get a local OpenAI-compatible server at localhost:4000.

Adding LiteLLM as a named provider (instead of requiring users to manually configure base_url) provides:

  • Dedicated litellm.* config namespace (api_key, base_url, api_key_helper)
  • Secure credential storage via the existing keyring system
  • Clear provider selection: codegpt config set openai.provider litellm

Changes

  • provider/litellm/litellm.go - New LiteLLM client implementing core.Generative (Completion, CompletionStream, GetSummaryPrefix with function-call fallback)
  • provider/litellm/options.go - Functional options pattern matching existing providers (WithToken, WithModel, WithBaseURL, etc.)
  • provider/litellm/func.go - Conventional commit prefix extraction via OpenAI-format tool calls
  • provider/litellm/func_test.go - Unit test for summary prefix argument parsing
  • provider/litellm/options_test.go - Config validation, defaults, and option application tests
  • provider/litellm/stream_test.go - Mock SSE server tests for streaming, completion, function calling, fallback, and error handling
  • core/platform.go - Added LiteLLM platform constant
  • cmd/provider.go - Added NewLiteLLM() factory and GetClient() dispatch
  • cmd/config_list.go - Added litellm.* config key descriptions
  • cmd/config_set.go - Added litellm.* CLI flags and viper bindings
  • cmd/cmd.go - Added litellm.api_key to sensitive credential store

Tests

1. Unit tests (12 tests, 89.9% coverage):

=== RUN   TestGetSummaryPrefixArgs
--- PASS: TestGetSummaryPrefixArgs (0.00s)
=== RUN   Test_config_valid
    --- PASS: Test_config_valid/valid_config (0.00s)
    --- PASS: Test_config_valid/missing_token (0.00s)
    --- PASS: Test_config_valid/missing_model (0.00s)
=== RUN   Test_config_defaults
--- PASS: Test_config_defaults (0.00s)
=== RUN   Test_config_options
--- PASS: Test_config_options (0.00s)
=== RUN   TestNew_missingToken
--- PASS: TestNew_missingToken (0.00s)
=== RUN   TestNew_missingModel
--- PASS: TestNew_missingModel (0.00s)
=== RUN   TestNew_success
--- PASS: TestNew_success (0.00s)
=== RUN   TestCompletionStream
--- PASS: TestCompletionStream (0.00s)
=== RUN   TestCompletion
--- PASS: TestCompletion (0.00s)
=== RUN   TestGetSummaryPrefix
--- PASS: TestGetSummaryPrefix (0.00s)
=== RUN   TestGetSummaryPrefix_fallback
--- PASS: TestGetSummaryPrefix_fallback (0.00s)
=== RUN   TestCompletion_noChoices
--- PASS: TestCompletion_noChoices (0.00s)
PASS
ok  	github.com/appleboy/CodeGPT/provider/litellm	coverage: 89.9% of statements

2. Full test suite - 0 regressions across all packages.

3. Lint clean: make lint -> 0 issues.

4. Build clean: go build ./... succeeds with no errors.

Risk / Compatibility

  • Additive only - existing providers (OpenAI, Azure, Gemini, Anthropic) are untouched.
  • No new Go dependencies - reuses the existing sashabaranov/go-openai SDK.
  • LiteLLM API key is stored in the secure credential store (keyring), same as other providers.
  • Falls back from litellm.api_key to openai.api_key if not set.

Example usage

# 1. Start a LiteLLM proxy (separate terminal)
litellm --model anthropic/claude-sonnet-4-6

# 2. Configure CodeGPT to use LiteLLM
codegpt config set openai.provider litellm
codegpt config set litellm.api_key sk-your-litellm-key
codegpt config set openai.model anthropic/claude-sonnet-4-6

# Optional: custom proxy URL (default: http://localhost:4000/v1)
codegpt config set litellm.base_url http://my-litellm-server:4000/v1

# 3. Use as normal
codegpt commit --preview
codegpt review

@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 71.86312% with 74 lines in your changes missing coverage. Please review.
✅ Project coverage is 23.63%. Comparing base (0125d86) to head (6c10e4d).
⚠️ Report is 287 commits behind head on main.

Files with missing lines Patch % Lines
cmd/provider.go 0.00% 42 Missing ⚠️
cmd/config_set.go 0.00% 17 Missing ⚠️
provider/litellm/litellm.go 93.54% 4 Missing and 4 partials ⚠️
provider/litellm/options.go 94.52% 2 Missing and 2 partials ⚠️
provider/litellm/func.go 66.66% 1 Missing and 1 partial ⚠️
core/platform.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #268      +/-   ##
==========================================
+ Coverage   21.96%   23.63%   +1.67%     
==========================================
  Files           8       39      +31     
  Lines         346     2187    +1841     
==========================================
+ Hits           76      517     +441     
- Misses        264     1629    +1365     
- Partials        6       41      +35     
Flag Coverage Δ
macos-latest 23.63% <71.86%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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