fix(anthropic-compatible): send Bearer auth for third-party gateways

Third-party Anthropic-compatible gateways that require Authorization: Bearer
(in addition to x-api-key) returned 401 missing_api_key on the forward path.
For non-official upstreams, also send Bearer <apiKey> alongside x-api-key.
Official api.anthropic.com behavior is unchanged.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
hodtien
2026-06-13 09:45:59 +07:00
committed by decolua
parent b309261166
commit b977bf7414

View File

@@ -157,6 +157,12 @@ export class DefaultExecutor extends BaseExecutor {
const baseUrl = credentials?.providerSpecificData?.baseUrl || "";
const isOfficialAnthropic = baseUrl === "" || baseUrl.includes("api.anthropic.com");
if (!isOfficialAnthropic) {
// Some third-party Anthropic-compatible gateways require Bearer auth in
// addition to x-api-key. Send both (x-api-key already set above) so
// gateways that read either header succeed.
if (credentials.apiKey && !headers["Authorization"]) {
headers["Authorization"] = `Bearer ${credentials.apiKey}`;
}
delete headers["anthropic-dangerous-direct-browser-access"];
delete headers["Anthropic-Dangerous-Direct-Browser-Access"];
delete headers["x-app"];