Skip to content

LLM Providers

CodeBuddy supports 8 LLM providers through a unified factory system. You can switch providers with a single setting, and the failover system automatically routes to a backup if your primary provider goes down.

ProviderLangChain wrapperDefault modelNotes
AnthropicChatAnthropicclaude-sonnet-4-5Native SDK
OpenAIChatOpenAIgpt-4oNative SDK
Google GeminiChatGoogleGenerativeAIgemini-2.5-proNative SDK
GroqChatGroqllama-3.1-70b-versatileNative SDK
DeepSeekChatOpenAIdeepseek-chatOpenAI-compatible, custom base URL
QwenChatOpenAIqwen-maxOpenAI-compatible (DashScope)
GLM (Zhipu AI)ChatOpenAIglm-4OpenAI-compatible
LocalChatOpenAIqwen2.5-coderOpenAI-compatible, localhost

DeepSeek, Qwen, GLM, and Local all use the ChatOpenAI wrapper with a custom baseURL, since they expose OpenAI-compatible APIs.

sequenceDiagram participant User as Editor Config participant GM as getGenerativeAiModel() participant KM as getAPIKeyAndModel() participant SS as SecretStorage<br/>(OS keychain) participant Set as settings.json participant Proxy as Credential Proxy participant BC as buildChatModel() User->>GM: generativeAi.option = "Anthropic" GM->>KM: getAPIKeyAndModel("Anthropic") KM->>SS: Check OS keychain alt Key in keychain SS-->>KM: API key else Fallback KM->>Set: Check settings.json Set-->>KM: API key end KM->>KM: Reject placeholder keys<br/>("apiKey", "YOUR_API_KEY_HERE") opt Credential proxy enabled KM->>Proxy: Route through local proxy Proxy-->>KM: Proxied credentials end KM-->>GM: {apiKey, model} GM->>BC: Build LangChain ChatModel instance BC-->>User: Ready for agent / inline completion

CodeBuddy uses different provider paths depending on the mode:

ModeFactoryOutput
Agent modebuildChatModel() → LangChain wrapperFed into LangGraph pipeline via AgentFactory
Inline completionCompletionProviderFactory.getProvider()Returns ICodeCompleter implementation (GroqLLM, QwenLLM, GeminiLLM, LocalLLM)

API keys are resolved in order:

  1. SecretStorage (OS keychain) — most secure, never written to disk
  2. Settingssettings.json values
  3. Credential proxy — if codebuddy.credentialProxy.enabled is true, API calls are routed through a local proxy that injects credentials from the OS keychain. The keys never reach the SDK clients directly.

Placeholder keys like "apiKey" or "YOUR_API_KEY_HERE" are automatically rejected.

The ProviderFailoverService monitors provider health and automatically switches to a backup when the primary fails.

The service classifies errors by inspecting HTTP status codes and error messages (walking the cause chain up to 5 levels deep):

ReasonTriggersCooldown
authHTTP 401, 40310 minutes
rate_limitHTTP 4291 minute
billingBilling/quota errors30 minutes
timeoutRequest timeout30 seconds
overloadedHTTP 503, 5292 minutes
model_not_foundHTTP 4041 hour
formatSchema/format errors
unknownEverything else
stateDiagram-v2 healthy --> degraded : 1-2 errors degraded --> down : 3+ errors down --> healthy : probe recovery

Probe recovery starts 30 seconds before a cooldown expires, attempting to restore the provider without waiting for the full cooldown.

When resolveProvider(primary) is called:

  1. Check if the primary provider is healthy → use it
  2. If not, iterate the candidate list (respecting cooldown timers)
  3. Return the first candidate with valid credentials
  4. The response includes an isFallback flag so the caller knows a switch occurred

Events emitted: provider_switch, health_update, probe_recovery.

SettingDefaultDescription
codebuddy.failover.enabledtrueEnable automatic failover
codebuddy.failover.providers[]Ordered fallback list. Empty = auto-detect from configured keys

The CostTrackingService tracks token usage and costs across all providers.

  • 30+ models with per-million-token pricing (separate input/output rates)
  • recordUsage(threadId, provider, model, inputTokens, outputTokens) — accumulates per conversation
  • getCostSummary() — totals, per-provider breakdowns, per-conversation records

See Cost Tracking for the user-facing details.

Each provider has its own API key and model settings. See the Settings Reference for the full list under Provider API keys & models.

SettingDescription
generativeAi.optionActive provider: Gemini, Groq, Anthropic, XGrok, Deepseek, OpenAI, Qwen, GLM, Local
{provider}.apiKeyAPI key for the provider
{provider}.modelModel name to use
local.baseUrlBase URL for local LLM (Ollama or Docker Model Runner)