Skip to content

Add custom base URL support for Anthropic provider#12718

Merged
melissa-barca merged 9 commits intomainfrom
feature/anthropic-custom-url
Mar 31, 2026
Merged

Add custom base URL support for Anthropic provider#12718
melissa-barca merged 9 commits intomainfrom
feature/anthropic-custom-url

Conversation

@melissa-barca
Copy link
Copy Markdown
Contributor

@melissa-barca melissa-barca commented Mar 27, 2026

Summary

Addresses #8007

Adds custom base URL support for Anthropic.

  • Adds a Base URL input field to the Configure Language Model Providers modal
  • Supports both the native Anthropic SDK provider and the Vercel AI SDK provider
  • Supports ANTHROPIC_BASE_URL environment variable for automatic configuration
  • Handles URL normalization for both SDK flavors (native SDK omits /v1, Vercel SDK requires it)
  • Relaxes API key format validation when a custom base URL is set
  • Treats 404 from /v1/models as a successful connection for custom endpoints that don't expose model listing
  • Updates the auth extension's Anthropic key validator to use the configured base URL
  • Migrates Anthropic env variable authentication from Assistant to the Authentication extension.

@:assistant

melissa-barca and others added 4 commits March 25, 2026 10:30
Support custom base URLs for the Anthropic provider to enable
corporate proxies, litellm, and other Anthropic-compatible endpoints.

- Add baseUrl to supportedOptions so the config dialog renders the field
- Add baseUrl getter with /v1 suffix and trailing slash normalization
- Pass baseURL to the Anthropic SDK client constructor
- Relax sk-ant- key format validation when a custom URL is set
- Handle 404 gracefully in resolveConnection for custom endpoints
- Read ANTHROPIC_BASE_URL env var for autoconfigure and config dialog
- Add tests for baseUrl getter, validateCredentials, and env var support
…8007)

Add baseUrl support to the Anthropic Vercel provider, update the auth
extension validator to derive the models endpoint from config.baseUrl,
and fix the close-modal warning for autoconfigured providers.
)

Route ANTHROPIC_API_KEY environment variable credentials through the
auth extension's credential chain pattern so they appear as standard
auth sessions. This lets other extensions access Anthropic credentials
via vscode.authentication.getSession without knowing how they were
configured.

- Add credential chain to Anthropic auth provider for env var resolution
- Add authentication.anthropic.baseUrl config setting synced from
  ANTHROPIC_BASE_URL env var
- Protect chain sessions from UI deletion (must unset env var to remove)
- Delegate env var credential checks from positron-assistant to auth
  extension sessions for migrated providers
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 27, 2026

E2E Tests 🚀
This PR will run tests tagged with: @:critical @:assistant

readme  valid tags

@melissa-barca melissa-barca marked this pull request as draft March 27, 2026 17:04
…8007)

- Validate ANTHROPIC_API_KEY against the configured base URL during
  credential chain resolution, preventing sign-in with invalid keys
- Sync ANTHROPIC_BASE_URL to config before chain resolution so
  validation uses the correct endpoint
- Block removal of chain sessions when the credential source is still
  available (env var still set), preventing inconsistent state where
  models work but UI shows signed out
- Show informational message when sign-out is blocked explaining that
  env var credentials cannot be removed from the UI
@melissa-barca melissa-barca marked this pull request as ready for review March 27, 2026 20:29
The removal protection was blocking sign-out for all credential chain
providers including AWS Bedrock. Only Anthropic env var credentials
should be protected since they reappear immediately after removal.
@melissa-barca melissa-barca marked this pull request as draft March 30, 2026 16:29
@melissa-barca
Copy link
Copy Markdown
Contributor Author

Converting to draft while I work on issues with failing E2E tests.

Only treat credential-chain sessions as autoconfigured, not manually
stored API key sessions. Chain sessions use the provider ID as their
session ID while manual sessions use a random UUID.
…tom-url

# Conflicts:
#	extensions/authentication/src/authProvider.ts
#	extensions/authentication/src/extension.ts
@melissa-barca melissa-barca marked this pull request as ready for review March 30, 2026 22:14
Copy link
Copy Markdown
Contributor

@georgestagg georgestagg left a comment

Choose a reason for hiding this comment

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

This LGTM!

I tried spinning up a local proxy server with npx http-server --proxy https://api.anthropic.com, and using that in this branch both with manual configuration setting the base URL via env vars.

Both worked well for me. In both cases I was able to login and make chat requests.

Image Image

@melissa-barca melissa-barca merged commit 90dbb1f into main Mar 31, 2026
21 checks passed
@melissa-barca melissa-barca deleted the feature/anthropic-custom-url branch March 31, 2026 18:47
@github-actions github-actions bot locked and limited conversation to collaborators Mar 31, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants