Skip to content

feat(llm): Anthropic driver base_url override (GLM/Zhipu support)#28

Merged
hallelx2 merged 1 commit into
mainfrom
feat/anthropic-base-url-glm
May 28, 2026
Merged

feat(llm): Anthropic driver base_url override (GLM/Zhipu support)#28
hallelx2 merged 1 commit into
mainfrom
feat/anthropic-base-url-glm

Conversation

@hallelx2
Copy link
Copy Markdown
Owner

@hallelx2 hallelx2 commented May 28, 2026

Adds AnthropicBlock.BaseURL threaded into both binaries' buildLLM via llmgate's anthropic.Config.BaseURL. Lets the anthropic driver 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:

  • Add a configurable base URL to the Anthropic LLM configuration to support Anthropic-compatible gateways such as GLM/Zhipu.

Enhancements:

  • Thread the Anthropic base URL through engine and server binaries so deployments can switch Anthropic endpoints without code changes.

Chores:

  • Introduce environment variable overrides for Anthropic API key, base URL, and model in both external and internal configs to simplify operational configuration.

Summary by CodeRabbit

  • New Features
    • Added support for configuring custom Anthropic API endpoints, enabling compatibility with alternative gateways and private deployments. Configuration available through YAML settings and environment variables.

Review Change Stack

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.
Copilot AI review requested due to automatic review settings May 28, 2026 15:35
@hallelx2 hallelx2 merged commit 678bcf0 into main May 28, 2026
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 28, 2026

Reviewer's Guide

Adds 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 selection

flowchart 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
Loading

File-Level Changes

Change Details Files
Add BaseURL field to Anthropic config and plumb it through to llmgate Anthropic client construction.
  • Extend AnthropicBlock in external config with a BaseURL field and documentation of its semantics.
  • Thread Anthropic.BaseURL into buildLLM in the engine binary when constructing the llmgate anthropic.Config.
  • Thread Anthropic.BaseURL into buildLLM in the server binary when constructing the llmgate anthropic.Config.
pkg/config/config.go
cmd/engine/main.go
cmd/server/main.go
Introduce environment variable overrides for Anthropic driver API key, base URL, and model for both server and engine configs.
  • Add VLE_LLM_ANTHROPIC_API_KEY, VLE_LLM_ANTHROPIC_BASE_URL, and VLE_LLM_ANTHROPIC_MODEL env overrides into external config applyEnvOverrides.
  • Add VLS_LLM_ANTHROPIC_BASE_URL and VLS_LLM_ANTHROPIC_MODEL env overrides (with VLE fallbacks) into internal engine config applyEnvOverrides.
pkg/config/config.go
internal/config/config.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@hallelx2 hallelx2 deleted the feat/anthropic-base-url-glm branch May 28, 2026 15:35
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1511388d-e98c-4211-af68-3341f2515ab1

📥 Commits

Reviewing files that changed from the base of the PR and between 94fc6a3 and 55e6da7.

📒 Files selected for processing (4)
  • cmd/engine/main.go
  • cmd/server/main.go
  • internal/config/config.go
  • pkg/config/config.go

📝 Walkthrough

Walkthrough

This PR adds support for customizing the Anthropic API endpoint via a BaseURL field in the configuration schema. The field is exposed through YAML and environment variable overrides at both the shared package and engine-specific config layers, then wired into the Anthropic client initialization in the engine and server commands.

Changes

Anthropic API Endpoint Configuration

Layer / File(s) Summary
Configuration schema and base environment overrides
pkg/config/config.go
AnthropicBlock struct gains BaseURL field with YAML key base_url. Environment override handler extended to support VLE_LLM_ANTHROPIC_BASE_URL to set c.LLM.Anthropic.BaseURL.
Engine LLM environment configuration
internal/config/config.go
Engine-specific config environment overrides extended to read VLS_LLM_ANTHROPIC_BASE_URL (with fallback to VLE_LLM_ANTHROPIC_BASE_URL) and VLS_LLM_ANTHROPIC_MODEL to set c.Engine.LLM.Anthropic.BaseURL and c.Engine.LLM.Anthropic.Model.
LLM client initialization
cmd/engine/main.go, cmd/server/main.go
Anthropic client configuration updated to set BaseURL from c.Anthropic.BaseURL in both buildLLM functions.

🎯 2 (Simple) | ⏱️ ~10 minutes

A rabbit hops through config with glee,
BaseURL now found in the trees,
Environment vars dance and sway,
Anthropic endpoint comes out to play! 🐰✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/anthropic-base-url-glm

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • 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.
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.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 to AnthropicBlock and pass it into anthropic.Config in both binaries.
  • Add env overrides VLE_LLM_ANTHROPIC_API_KEY / _BASE_URL / _MODEL to engine config.
  • Forward VLS_LLM_ANTHROPIC_BASE_URL / _MODEL (with VLE_* 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.

Comment thread pkg/config/config.go
// 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 != "" {
Comment thread internal/config/config.go
Comment on lines +327 to +332
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
}
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