jcode icon indicating copy to clipboard operation
jcode copied to clipboard

Support Anthropic-compatible base URLs for direct Anthropic provider

Open 2233admin opened this issue 5 months ago • 1 comments

Problem

The direct Anthropic provider currently builds direct Messages and model-catalog requests against the official Anthropic API endpoints. That works for ANTHROPIC_API_KEY, but it prevents Anthropic-compatible gateways/proxies from being used even when a user provides Anthropic-style environment variables such as ANTHROPIC_BASE_URL and a bearer-style ANTHROPIC_AUTH_TOKEN.

This is separate from the Claude OAuth/subscription path: OAuth should keep using the official Anthropic OAuth endpoints because the preflight/bootstrap flow depends on them.

Reproduction

Configure a local or enterprise Anthropic-compatible gateway:

$env:JCODE_RUNTIME_PROVIDER = "anthropic-api"
$env:ANTHROPIC_BASE_URL = "http://127.0.0.1:15721/anthropic/v1"
$env:ANTHROPIC_AUTH_TOKEN = "<redacted>"

Then run a direct Anthropic request, for example:

jcode --provider anthropic-api run --tool-profile none "Reply exactly OK"

Expected behavior:

  • Messages requests go to http://127.0.0.1:15721/anthropic/v1/messages.
  • Bearer-style gateway tokens are sent as Authorization: Bearer <token>.
  • Official ANTHROPIC_API_KEY usage continues to send x-api-key to the default Anthropic API.
  • Claude OAuth continues to use the official OAuth URL and headers.

Actual behavior:

  • The direct Anthropic transport is tied to official Anthropic endpoints/auth behavior, so the gateway cannot be selected through the usual Anthropic-compatible env vars.

Notes

A focused fix should keep OAuth unchanged, preserve the existing direct API-key path, and only apply custom base URL/bearer-token handling to non-OAuth direct Anthropic requests.

2233admin avatar Jun 04 '26 21:06 2233admin

This needs a provider-contract decision because direct Anthropic API keys, bearer-token gateways, and Claude OAuth have different endpoint and header rules. Recommendation: scope custom base URL and bearer auth strictly to non-OAuth direct Anthropic requests, with tests proving official API-key and OAuth behavior remain unchanged.

--- — Jcode agent (automated triage), on behalf of @1jehuang

1jehuang avatar Jul 20 '26 21:07 1jehuang