Skip to content

Feat/add litellm provider - #268

Merged
appleboy merged 7 commits into
appleboy:mainfrom
RheagalFire:feat/add-litellm-provider
Sep 28, 2026
Merged

appleboy merged 7 commits into
appleboy:mainfrom
RheagalFire:feat/add-litellm-provider

Conversation

@RheagalFire

Copy link
Copy Markdown
Contributor

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 78.02198% with 60 lines in your changes missing coverage. Please review.
✅ Project coverage is 32.90%. Comparing base (0125d86) to head (9510e84).
⚠️ Report is 297 commits behind head on main.

Files with missing lines Patch % Lines
cmd/provider.go 0.00% 52 Missing ⚠️
provider/litellm/litellm.go 96.77% 4 Missing ⚠️
provider/litellm/options.go 97.26% 2 Missing ⚠️
core/platform.go 0.00% 1 Missing ⚠️
provider/litellm/func.go 83.33% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main     #268       +/-   ##
===========================================
+ Coverage   21.96%   32.90%   +10.94%     
===========================================
  Files           8       39       +31     
  Lines         346     2194     +1848     
===========================================
+ Hits           76      722      +646     
- Misses        264     1471     +1207     
+ Partials        6        1        -5     
Flag Coverage Δ
ubuntu-latest 32.90% <78.02%> (?)

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.

@appleboy

Copy link
Copy Markdown
Owner

I will take it.

- Fall back to the shared API key helper before the shared static key
- Respect helper cache intervals and propagate helper failures
- Test credential precedence and cache behavior with isolated credentials
- Group OpenAI imports according to the configured formatter
- Add LiteLLM configuration options and usage examples
- Explain credential precedence and helper cache settings
- Correct credential storage and shared key lookup documentation
@appleboy
appleboy merged commit 45e2173 into appleboy:main Sep 28, 2026
13 of 15 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.

2 participants