Skip to content

feat: support custom baseURL via opencode.json and ANTHROPIC_BASE_URL…#229

Open
anxjok wants to merge 1 commit into
griffinmartin:mainfrom
anxjok:feat/proxy-baseurl-support
Open

feat: support custom baseURL via opencode.json and ANTHROPIC_BASE_URL…#229
anxjok wants to merge 1 commit into
griffinmartin:mainfrom
anxjok:feat/proxy-baseurl-support

Conversation

@anxjok

@anxjok anxjok commented May 22, 2026

Copy link
Copy Markdown

Summary

Add support for configuring a custom Anthropic API base URL via opencode.json or the ANTHROPIC_BASE_URL environment variable. This enables routing Anthropic API requests through proxies, API gateways, and custom endpoints while maintaining OAuth authentication through Claude Code credentials.
Key features:

  • Configure custom base URL in opencode.json via provider.anthropic.options.baseURL
  • Fallback support via ANTHROPIC_BASE_URL environment variable
  • Priority chain: config file > environment variable > default Anthropic endpoint
  • Custom headers from provider.anthropic.options.headers are automatically forwarded (useful for authentication headers like X-Gateway-Key)
  • Fully backward compatible — existing setups continue to work without changes

Related issue

Closes #160 (FR: Anthropic API mode for e.g. CLIProxyAPI)

Testing

  • Manually tested with live proxy endpoint:
    • Requests correctly routed to proxy URL (not default API)
    • 200 OK responses received
    • Custom headers (e.g., X-Gateway-Key) forwarded correctly
    • Fallback to default endpoint when no config/env var is set
  • Priority chain validated: config > env var > default
  • All 225 tests pass (220 existing + 5 new baseURL tests):
    • Lint: 0 warnings, 0 errors
    • Build: TypeScript compilation successful
    • Test suites: 39 suites, 0 failures
  • No regression in existing functionality
    Test coverage includes:
  • Uses default baseURL when no config or env var is set
  • Uses provider.anthropic.options.baseURL from opencode.json when provided
  • Uses ANTHROPIC_BASE_URL environment variable when set (no config)
  • Prioritizes config over environment variable (correct precedence)
  • Does not double /v1 path segment (correct URL merging)

Checklist

  • PR title follows Conventional Commits (feat:)
  • make all passes locally (runs lint, build, and test)
  • Tests added or updated where applicable (5 new baseURL tests in src/index.test.ts)
  • README or docs updated where applicable (added "Custom base URL / Proxy support" section and ANTHROPIC_BASE_URL env var documentation)

… env var

- Add support for configuring custom base URL in opencode.json via provider.anthropic.options.baseURL
- Add fallback to ANTHROPIC_BASE_URL environment variable
- Maintain backward compatibility with default Anthropic API endpoint
- Priority: config > env var > default

This enables routing Anthropic API requests through proxies, API gateways, and custom endpoints while maintaining OAuth authentication through Claude Code credentials.

Features:
- Custom headers from provider.anthropic.options.headers are automatically forwarded
- Useful for authentication headers (e.g., X-Gateway-Key)
- Verified to work with proxies and load balancers

Closes: Support for proxy/gateway setups requested by users
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.

FR: Anthropic API mode for e.g. CLIProxyAPI

1 participant