feat: allow overriding ANTHROPIC_BASE_URL via env var - #256
Conversation
Lets the plugin route Anthropic API requests through a local proxy like Headroom by reading ANTHROPIC_BASE_URL from the environment. OAuth headers are still attached as before; only the destination host changes. Defaults to https://api.anthropic.com/v1 when the variable is unset.
Greptile SummaryThis PR adds
Confidence Score: 5/5Safe to merge — a three-line logic change with matching tests and docs, no impact on auth or request signing. The change is minimal: one new exported helper, one replaced hardcoded string, two tests. Files Needing Attention: No files require special attention.
|
| Filename | Overview |
|---|---|
| src/index.ts | Adds exported getAnthropicBaseUrl() using ?? consistent with other env-var helpers; wires it into the plugin's one-time baseURL config field. |
| src/index.test.ts | Adds two tests for getAnthropicBaseUrl covering unset and set env-var cases; save/restore pattern is correct in both test branches. |
| README.md | Documents ANTHROPIC_BASE_URL in the env-var override table with accurate default and description. |
Sequence Diagram
sequenceDiagram
participant OC as OpenCode
participant P as Plugin (index.ts)
participant E as process.env
participant Proxy as Proxy / Anthropic API
OC->>P: plugin() called at startup
P->>E: read ANTHROPIC_BASE_URL
E-->>P: value or undefined
P-->>OC: "{ baseURL, fetch() }"
note over OC,P: baseURL fixed for lifetime of plugin
OC->>P: fetch(input, init) per request
P->>P: getCachedCredentials()
P->>P: buildRequestHeaders() - attach OAuth token
P->>Proxy: fetch(input, headers)
Proxy-->>P: Response
P-->>OC: Response
Reviews (2): Last reviewed commit: "fix: use nullish coalescing for ANTHROPI..." | Re-trigger Greptile
Matches the pattern used by getCliVersion/getUserAgent so an explicitly empty ANTHROPIC_BASE_URL doesn't silently fall back to the default.
Summary
ANTHROPIC_BASE_URLfrom environmenthttps://api.anthropic.com/v1unchanged when unsetTest plan
pnpm testpasses except 1 pre-existing unrelated failurenpx tsc --noEmitcleanpnpm run lintclean