feat(llm): Anthropic driver base_url override (GLM/Zhipu support)#28
Conversation
Adds AnthropicBlock.BaseURL, threaded into both binaries' buildLLM via llmgate's anthropic.Config.BaseURL (which the provider already supports). Empty = official api.anthropic.com. This lets the existing `anthropic` driver target any Anthropic-compatible gateway. The immediate use is GLM/Zhipu's https://api.z.ai/api/anthropic endpoint (glm-4.6), which speaks the Messages API and sidesteps the Gemini free-tier daily quota that was 429-ing every ingest's summarize / HyDE / TOC-builder calls. Wiring: - pkg/config: AnthropicBlock.BaseURL (yaml: base_url) + VLE_LLM_ANTHROPIC_{API_KEY,BASE_URL,MODEL} env overrides. - internal/config (server): forwards VLS_/VLE_LLM_ANTHROPIC_BASE_URL and _MODEL onto the nested engine config so the deployed cmd/server can be flipped to GLM by env var alone — no secret edit. - cmd/engine + cmd/server buildLLM: pass BaseURL through. go build/vet/test green.
Reviewer's GuideAdds support for overriding the Anthropic driver base URL and model via config/env so the Anthropic llmgate client can be pointed at Anthropic-compatible gateways (e.g., GLM/Zhipu) in both server and engine binaries. Flow diagram for Anthropic base_url override and gateway selectionflowchart LR
subgraph Environment
ENV_API_KEY[VLE_LLM_ANTHROPIC_API_KEY]
ENV_BASE_URL[VLE_LLM_ANTHROPIC_BASE_URL]
ENV_MODEL[VLE_LLM_ANTHROPIC_MODEL]
end
subgraph Config
ApplyEnv[applyEnvOverrides]
AnthropicBlock[LLM.Anthropic
- APIKey
- Model
- BaseURL]
end
subgraph Binaries
Engine[cmd/engine buildLLM]
Server[cmd/server buildLLM]
end
subgraph Llmgate
AnthropicClient[anthropic.New
Config.BaseURL]
end
subgraph Endpoints
AnthropicAPI[api.anthropic.com]
GLMGateway[GLM/Zhipu
https://api.z.ai/api/anthropic]
end
ENV_API_KEY --> ApplyEnv
ENV_BASE_URL --> ApplyEnv
ENV_MODEL --> ApplyEnv
ApplyEnv --> AnthropicBlock
AnthropicBlock --> Engine
AnthropicBlock --> Server
Engine --> AnthropicClient
Server --> AnthropicClient
AnthropicClient -->|"BaseURL empty"| AnthropicAPI
AnthropicClient -->|"BaseURL set"| GLMGateway
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThis PR adds support for customizing the Anthropic API endpoint via a ChangesAnthropic API Endpoint Configuration
🎯 2 (Simple) | ⏱️ ~10 minutes
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The env override handling for Anthropic settings is now split between
pkg/config.applyEnvOverridesandinternal/config.applyEnvOverrides; consider centralizing this logic (or using a shared helper) so Anthropic env vars stay consistent across binaries over time. - In
internal/config.applyEnvOverrides, you support AnthropicBASE_URLandMODELbut notAPI_KEY(unlikepkg/config.applyEnvOverrides); if that’s not intentional, consider adding the API key override for symmetry. - Since
BaseURLuses an empty string as a sentinel for the default Anthropic endpoint, consider enforcing that default in a single place (e.g., the Anthropic client config constructor) so callers don’t have to rely on this convention implicitly.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The env override handling for Anthropic settings is now split between `pkg/config.applyEnvOverrides` and `internal/config.applyEnvOverrides`; consider centralizing this logic (or using a shared helper) so Anthropic env vars stay consistent across binaries over time.
- In `internal/config.applyEnvOverrides`, you support Anthropic `BASE_URL` and `MODEL` but not `API_KEY` (unlike `pkg/config.applyEnvOverrides`); if that’s not intentional, consider adding the API key override for symmetry.
- Since `BaseURL` uses an empty string as a sentinel for the default Anthropic endpoint, consider enforcing that default in a single place (e.g., the Anthropic client config constructor) so callers don’t have to rely on this convention implicitly.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Pull request overview
Adds a BaseURL override to the engine's Anthropic LLM config so the anthropic driver can target any Anthropic-compatible gateway (immediate use case: GLM/Zhipu at https://api.z.ai/api/anthropic), and threads it through both the engine and server binaries' buildLLM. Also introduces new VLE_*/VLS_* env overrides for the Anthropic API key, base URL, and model.
Changes:
- Add
BaseURL(yaml:base_url) field toAnthropicBlockand pass it intoanthropic.Configin both binaries. - Add env overrides
VLE_LLM_ANTHROPIC_API_KEY/_BASE_URL/_MODELto engine config. - Forward
VLS_LLM_ANTHROPIC_BASE_URL/_MODEL(withVLE_*fallbacks) through the server config.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/config/config.go | Adds BaseURL field on AnthropicBlock and three new VLE_LLM_ANTHROPIC_* env overrides. |
| internal/config/config.go | Forwards VLS_/VLE_LLM_ANTHROPIC_BASE_URL and _MODEL into the embedded engine config. |
| cmd/engine/main.go | Passes c.Anthropic.BaseURL into anthropic.Config when building the LLM client. |
| cmd/server/main.go | Same BaseURL plumbing for the server binary's buildLLM. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // anthropic driver at an Anthropic-compatible gateway (e.g. GLM via | ||
| // https://api.z.ai/api/anthropic) without baking the values into the | ||
| // config file or secret. | ||
| if v := os.Getenv("VLE_LLM_ANTHROPIC_API_KEY"); v != "" { |
| if v := firstEnv("VLS_LLM_ANTHROPIC_BASE_URL", "VLE_LLM_ANTHROPIC_BASE_URL"); v != "" { | ||
| c.Engine.LLM.Anthropic.BaseURL = v | ||
| } | ||
| if v := firstEnv("VLS_LLM_ANTHROPIC_MODEL", "VLE_LLM_ANTHROPIC_MODEL"); v != "" { | ||
| c.Engine.LLM.Anthropic.Model = v | ||
| } |
Adds
AnthropicBlock.BaseURLthreaded into both binaries'buildLLMvia llmgate'santhropic.Config.BaseURL. Lets theanthropicdriver target any Anthropic-compatible gateway — immediate use is GLM/Zhipu (https://api.z.ai/api/anthropic, glm-4.6), which sidesteps the Gemini free-tier daily quota that was 429-ing every ingest. Env overrides (VLE_LLM_ANTHROPIC_BASE_URL/_MODEL/_API_KEY, forwarded through the server config) let the deployed binary flip to GLM without a secret edit. Verified the key+endpoint+model live (glm-4.6 returns 200). go build/vet/test green.Summary by Sourcery
Allow the Anthropic LLM driver to target alternative Anthropic-compatible gateways via configurable base URL and environment overrides.
New Features:
Enhancements:
Chores:
Summary by CodeRabbit