xonecas.io
64875
Mc

mini-coder / commit 93373a3

fix: use Bearer auth for Anthropic OAuth model listing

When logged in via OAuth, fetchAnthropicModels() was sending the OAuth
token as x-api-key instead of Authorization: Bearer, and was missing
the required anthropic-beta: oauth-2025-04-20 header. This caused the
/v1/models endpoint to reject the request, resulting in an empty model
list for new OAuth-only users.

xonecas2026-03-17 93373a30f809ef69395f5afe991f3cdb0159ca43 parent 519a3cc

1 file changed

src/llm-api/model-info-fetch.ts+22−11
@@ -148,27 +148,38 @@ async function fetchOpenAIModels(): Promise<ProviderModelCandidate[] | null> {
148148 );
149149 }
150150
151-async function getAnthropicApiKey(): Promise<string | null> {
151+async function getAnthropicAuth(): Promise<{
152+ key: string;
153+ oauth: boolean;
154+} | null> {
152155 const envKey = process.env.ANTHROPIC_API_KEY;
153- if (envKey) return envKey;
154- if (isLoggedIn("anthropic")) return getAccessToken("anthropic");
156+ if (envKey) return { key: envKey, oauth: false };
157+ if (isLoggedIn("anthropic")) {
158+ const token = await getAccessToken("anthropic");
159+ if (token) return { key: token, oauth: true };
160+ }
155161 return null;
156162 }
157163
158164 async function fetchAnthropicModels(): Promise<
159165 ProviderModelCandidate[] | null
160166 > {
161- const key = await getAnthropicApiKey();
162- if (!key) return null;
167+ const auth = await getAnthropicAuth();
168+ if (!auth) return null;
169+
170+ const headers: Record<string, string> = {
171+ "anthropic-version": "2023-06-01",
172+ };
173+ if (auth.oauth) {
174+ headers.Authorization = `Bearer ${auth.key}`;
175+ headers["anthropic-beta"] = "oauth-2025-04-20";
176+ } else {
177+ headers["x-api-key"] = auth.key;
178+ }
163179
164180 const payload = await fetchJson(
165181 `${ANTHROPIC_BASE}/v1/models`,
166- {
167- headers: {
168- "x-api-key": key,
169- "anthropic-version": "2023-06-01",
170- },
171- },
182+ { headers },
172183 6_000,
173184 );
174185 return processModelsList(payload, "data", "id", (item, modelId) => {