Skip to content

feat: allow overriding ANTHROPIC_BASE_URL via env var - #256

Open
Samyak2406 wants to merge 2 commits into
griffinmartin:mainfrom
Samyak2406:feat/anthropic-base-url-override
Open

feat: allow overriding ANTHROPIC_BASE_URL via env var#256
Samyak2406 wants to merge 2 commits into
griffinmartin:mainfrom
Samyak2406:feat/anthropic-base-url-override

Conversation

@Samyak2406

@Samyak2406 Samyak2406 commented Jul 27, 2026

Copy link
Copy Markdown

Summary

  • Lets the plugin route Anthropic API requests through a local proxy like Headroom by reading ANTHROPIC_BASE_URL from environment
  • Defaults to https://api.anthropic.com/v1 unchanged when unset
  • OAuth headers still attached as before

Test plan

  • pnpm test passes except 1 pre-existing unrelated failure
  • npx tsc --noEmit clean
  • pnpm run lint clean

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-apps

greptile-apps Bot commented Jul 27, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds ANTHROPIC_BASE_URL environment variable support so requests can be routed through a local proxy (e.g. Headroom) while OAuth headers continue to be attached by the plugin. The default remains https://api.anthropic.com/v1 when the variable is unset.

  • getAnthropicBaseUrl() is a single-line helper using ?? (nullish coalescing), consistent with every other env-var override in the file; it is exported so tests can reach it via the dynamic-import helpers pattern already established in the test suite.
  • baseURL: getAnthropicBaseUrl() replaces the hardcoded string in the plugin's returned config object; because this object is built once at plugin init, the env var is read at startup — the expected behavior for a connection-level config value.
  • Two new tests cover the default path and the custom-URL path, each with correct save/restore of process.env.ANTHROPIC_BASE_URL.

Confidence Score: 5/5

Safe 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. ?? is used correctly, OAuth header attachment is unaffected, and the env var is read at the same startup point as all other overrides in this file. No existing behaviour changes when the variable is unset.

Files Needing Attention: No files require special attention.

Important Files Changed

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
Loading

Reviews (2): Last reviewed commit: "fix: use nullish coalescing for ANTHROPI..." | Re-trigger Greptile

Comment thread src/index.ts
Matches the pattern used by getCliVersion/getUserAgent so an
explicitly empty ANTHROPIC_BASE_URL doesn't silently fall back
to the default.
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.

1 participant