fix: handle anthropic-compatible providers in BaseExecutor (#428)
The BaseExecutor's buildUrl() and buildHeaders() methods only handled openai-compatible-* providers but not anthropic-compatible-* providers. This caused Anthropic-compatible synthetic providers to fail API testing by hitting the wrong endpoint (returning documentation instead of valid API responses) and using incorrect auth headers. Changes: - Added buildUrl() handling for anthropic-compatible-* providers to append /messages path - Added buildHeaders() handling for x-api-key header and anthropic-version for anthropic-compatible providers Fixes #XXX Co-authored-by: Bitgineer <bitgineer@bitgineer.shop>
This commit is contained in:
@@ -29,6 +29,11 @@ export class BaseExecutor {
|
|||||||
const path = this.provider.includes("responses") ? "/responses" : "/chat/completions";
|
const path = this.provider.includes("responses") ? "/responses" : "/chat/completions";
|
||||||
return `${normalized}${path}`;
|
return `${normalized}${path}`;
|
||||||
}
|
}
|
||||||
|
if (this.provider?.startsWith?.("anthropic-compatible-")) {
|
||||||
|
const baseUrl = credentials?.providerSpecificData?.baseUrl || "https://api.anthropic.com/v1";
|
||||||
|
const normalized = baseUrl.replace(/\/$/, "");
|
||||||
|
return `${normalized}/messages`;
|
||||||
|
}
|
||||||
const baseUrls = this.getBaseUrls();
|
const baseUrls = this.getBaseUrls();
|
||||||
return baseUrls[urlIndex] || baseUrls[0] || this.config.baseUrl;
|
return baseUrls[urlIndex] || baseUrls[0] || this.config.baseUrl;
|
||||||
}
|
}
|
||||||
@@ -39,10 +44,23 @@ export class BaseExecutor {
|
|||||||
...this.config.headers
|
...this.config.headers
|
||||||
};
|
};
|
||||||
|
|
||||||
if (credentials.accessToken) {
|
if (this.provider?.startsWith?.("anthropic-compatible-")) {
|
||||||
headers["Authorization"] = `Bearer ${credentials.accessToken}`;
|
// Anthropic-compatible providers use x-api-key header
|
||||||
} else if (credentials.apiKey) {
|
if (credentials.apiKey) {
|
||||||
headers["Authorization"] = `Bearer ${credentials.apiKey}`;
|
headers["x-api-key"] = credentials.apiKey;
|
||||||
|
} else if (credentials.accessToken) {
|
||||||
|
headers["Authorization"] = `Bearer ${credentials.accessToken}`;
|
||||||
|
}
|
||||||
|
if (!headers["anthropic-version"]) {
|
||||||
|
headers["anthropic-version"] = "2023-06-01";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Standard Bearer token auth for other providers
|
||||||
|
if (credentials.accessToken) {
|
||||||
|
headers["Authorization"] = `Bearer ${credentials.accessToken}`;
|
||||||
|
} else if (credentials.apiKey) {
|
||||||
|
headers["Authorization"] = `Bearer ${credentials.apiKey}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stream) {
|
if (stream) {
|
||||||
|
|||||||
Reference in New Issue
Block a user