Add --anthropic-path-prefix flag and auto-probe for Envoy AI Gateway#5174
Add --anthropic-path-prefix flag and auto-probe for Envoy AI Gateway#5174
Conversation
There was a problem hiding this comment.
Pull request overview
Adds support in thv llm setup for gateways (notably Envoy AI Gateway) that serve Anthropic-native traffic under an /anthropic path prefix, preventing 404 “model not found” errors for direct-mode tools that rely on ANTHROPIC_BASE_URL.
Changes:
- Introduces
--anthropic-path-prefixand propagates an effectiveAnthropicBaseURLinto direct-mode tool config patching. - Adds an auto-probe that HEADs
<gateway>/anthropic/v1/messagesand selects/anthropicwhen a 401 indicates the route exists. - Updates Claude Code integration to write
ANTHROPIC_BASE_URLfromAnthropicBaseURL(with fallback toGatewayURL) and adds unit tests for prefix behavior + probing.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/llmgateway/config.go | Extends ApplyConfig to carry an AnthropicBaseURL alongside the gateway URL. |
| pkg/llm/setup.go | Resolves/passes the Anthropic prefix, applies it only for direct-mode tools, and implements the auto-probe. |
| pkg/llm/setup_test.go | Adds unit tests for direct/proxy prefix behavior and probe outcomes. |
| pkg/llm/manage.go | Extends SetOptions with AnthropicPathPrefix. |
| pkg/client/llm_gateway.go | Adds AnthropicBaseURL value resolution with fallback to GatewayURL. |
| pkg/client/config.go | Switches Claude Code’s ANTHROPIC_BASE_URL mapping to AnthropicBaseURL. |
| cmd/thv/app/llm.go | Adds the --anthropic-path-prefix CLI flag to thv llm setup. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5174 +/- ##
==========================================
- Coverage 67.57% 67.57% -0.01%
==========================================
Files 602 602
Lines 61119 61167 +48
==========================================
+ Hits 41303 41334 +31
- Misses 16693 16704 +11
- Partials 3123 3129 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
cmd/thv/app/llm.go:233
- PR description mentions Codex being affected (“direct-mode tool configs (Claude Code, Codex)”), but Codex doesn’t appear to have LLM gateway support in
supportedClientIntegrations(it has noLLMGatewayMode/LLMGatewayKeys). If Codex is intentionally out of scope, please update the PR description to avoid confusing users; if it should be in scope, it likely needs an LLM gateway config entry similar to other direct-mode tools.
cmd := &cobra.Command{
Use: "setup",
Short: "Configure detected AI tools to use the LLM gateway",
Long: `Detect installed AI coding tools (Claude Code, Gemini CLI, Cursor, VS Code,
Xcode) and patch each tool's configuration to route through the LLM gateway.
Token-helper tools (Claude Code, Gemini CLI) are configured to call
"thv llm token" to obtain a fresh OIDC token on demand.
Proxy-mode tools (Cursor, VS Code, Xcode) are configured to send requests to
the localhost reverse proxy started by "thv llm proxy start".
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Some gateways (e.g. Envoy AI Gateway) serve native-Anthropic traffic at /anthropic/v1/messages rather than /v1/messages, causing Claude Code to receive 404s and report "model not found" errors. - Add --anthropic-path-prefix flag to `thv llm setup` (default empty). When set, the prefix is appended to the gateway URL when writing ANTHROPIC_BASE_URL in direct-mode tool configs (Claude Code, Codex). - Auto-probe: if the flag is omitted, issue a HEAD request to <gateway>/anthropic/v1/messages; a 401 response (auth-reachable path) triggers automatic prefix selection. 404 or any error means no prefix. - Proxy-mode tools (Cursor, VS Code) are unaffected — they route through `thv llm proxy` and don't use ANTHROPIC_BASE_URL. Closes #5158
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| case "AnthropicBaseURL": | ||
| // Use the pre-computed Anthropic base URL when available; fall back to | ||
| // GatewayURL so existing configs continue to work without the prefix. | ||
| if cfg.AnthropicBaseURL != "" { | ||
| return cfg.AnthropicBaseURL, nil | ||
| } | ||
| return cfg.GatewayURL, nil |
Summary
Some gateways (e.g. Envoy AI Gateway) serve native-Anthropic traffic at /anthropic/v1/messages rather than /v1/messages, causing Claude Code to receive 404s and report "model not found" errors.
thv llm setup(default empty). When set, the prefix is appended to the gateway URL when writing ANTHROPIC_BASE_URL in direct-mode tool configs (Claude Code, Codex).thv llm proxyand don't use ANTHROPIC_BASE_URL.Fixes #5158
Type of change
Test plan
task test)task test-e2e)task lint-fix)API Compatibility
v1beta1API, OR theapi-break-allowedlabel is applied and the migration guidance is described above.Changes
Does this introduce a user-facing change?
Implementation plan
Approved implementation plan
Special notes for reviewers