feat: add ANTHROPIC_BASE_URL environment variable support
This commit is contained in:
parent
5c35b62a5c
commit
84f2a25218
@ -67,7 +67,9 @@ const pickAnthropicTokens = (store: {
|
||||
};
|
||||
|
||||
const fetchAnthropicOAuthUsage = async (token: string) => {
|
||||
const res = await fetch("https://api.anthropic.com/api/oauth/usage", {
|
||||
const baseUrl = process.env.ANTHROPIC_BASE_URL?.trim() || "https://api.anthropic.com";
|
||||
const url = `${baseUrl}/api/oauth/usage`;
|
||||
const res = await fetch(url, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
Accept: "application/json",
|
||||
|
||||
@ -235,6 +235,15 @@ export function normalizeProviders(params: {
|
||||
normalizedProvider = googleNormalized;
|
||||
}
|
||||
|
||||
// Apply ANTHROPIC_BASE_URL environment variable override
|
||||
if (normalizedKey === "anthropic") {
|
||||
const baseUrl = process.env.ANTHROPIC_BASE_URL?.trim();
|
||||
if (baseUrl && normalizedProvider.baseUrl !== baseUrl) {
|
||||
mutated = true;
|
||||
normalizedProvider = { ...normalizedProvider, baseUrl };
|
||||
}
|
||||
}
|
||||
|
||||
next[key] = normalizedProvider;
|
||||
}
|
||||
|
||||
@ -367,6 +376,15 @@ export async function resolveImplicitProviders(params: {
|
||||
allowKeychainPrompt: false,
|
||||
});
|
||||
|
||||
// Add Anthropic provider if ANTHROPIC_BASE_URL is set
|
||||
const anthropicBaseUrl = process.env.ANTHROPIC_BASE_URL?.trim();
|
||||
if (anthropicBaseUrl) {
|
||||
providers.anthropic = {
|
||||
baseUrl: anthropicBaseUrl,
|
||||
models: [],
|
||||
};
|
||||
}
|
||||
|
||||
const minimaxKey =
|
||||
resolveEnvApiKeyVarName("minimax") ??
|
||||
resolveApiKeyFromProfiles({ provider: "minimax", store: authStore });
|
||||
|
||||
@ -99,8 +99,10 @@ export async function fetchClaudeUsage(
|
||||
timeoutMs: number,
|
||||
fetchFn: typeof fetch,
|
||||
): Promise<ProviderUsageSnapshot> {
|
||||
const baseUrl = process.env.ANTHROPIC_BASE_URL?.trim() || "https://api.anthropic.com";
|
||||
const url = `${baseUrl}/api/oauth/usage`;
|
||||
const res = await fetchJson(
|
||||
"https://api.anthropic.com/api/oauth/usage",
|
||||
url,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user