This commit is contained in:
Gabriel 2026-01-30 20:02:07 +08:00 committed by GitHub
commit 1830f0d113
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 2 deletions

View File

@ -69,7 +69,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",

View File

@ -246,6 +246,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;
}
@ -396,6 +405,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 });

View File

@ -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}`,