xonecas.io
64875
Mc

mini-coder / commit d2f5365

fix: show Anthropic models in /models for OAuth users

- Pass OAuth access token as x-api-key to the /v1/models endpoint
  instead of Bearer auth (which the endpoint doesn't accept)
- Include OAuth-authenticated providers in the visible providers set
  so they appear in the model list and trigger cache refresh
- Block on model fetch when a visible provider has no cached models
  (e.g. right after /login) instead of returning empty results

xonecas2026-03-16 d2f5365983b78dae4a41636040eaa2757de11ab8 parent d2fa578

2 files changed

src/llm-api/model-info-fetch.ts+13−14
@@ -148,28 +148,27 @@ async function fetchOpenAIModels(): Promise<ProviderModelCandidate[] | null> {
148148 );
149149 }
150150
151-async function getAnthropicOAuthToken(): Promise<string | null> {
152- if (!isLoggedIn("anthropic")) return null;
153- return getAccessToken("anthropic");
151+async function getAnthropicApiKey(): Promise<string | null> {
152+ const envKey = process.env.ANTHROPIC_API_KEY;
153+ if (envKey) return envKey;
154+ if (isLoggedIn("anthropic")) return getAccessToken("anthropic");
155+ return null;
154156 }
155157
156158 async function fetchAnthropicModels(): Promise<
157159 ProviderModelCandidate[] | null
158160 > {
159- const envKey = process.env.ANTHROPIC_API_KEY;
160- const oauthToken = !envKey ? await getAnthropicOAuthToken() : null;
161- if (!envKey && !oauthToken) return null;
162-
163- const headers: Record<string, string> = {
164- "anthropic-version": "2023-06-01",
165- ...(oauthToken
166- ? { Authorization: `Bearer ${oauthToken}` }
167- : { "x-api-key": envKey as string }),
168- };
161+ const key = await getAnthropicApiKey();
162+ if (!key) return null;
169163
170164 const payload = await fetchJson(
171165 `${ANTHROPIC_BASE}/v1/models`,
172- { headers },
166+ {
167+ headers: {
168+ "x-api-key": key,
169+ "anthropic-version": "2023-06-01",
170+ },
171+ },
173172 6_000,
174173 );
175174 return processModelsList(payload, "data", "id", (item, modelId) => {
src/llm-api/model-info.ts+30−2
@@ -1,3 +1,4 @@
1+import { isLoggedIn } from "../oauth/auth-storage.ts";
12 import {
23 listModelCapabilities,
34 listModelInfoState,
@@ -111,9 +112,16 @@ function hasAnyEnvKey(
111112 export function getRemoteProvidersFromEnv(
112113 env: Record<string, string | undefined>,
113114 ): string[] {
114- return REMOTE_PROVIDER_ENV_KEYS.filter((entry) =>
115+ const providers = REMOTE_PROVIDER_ENV_KEYS.filter((entry) =>
115116 hasAnyEnvKey(env, entry.envKeys),
116117 ).map((entry) => entry.provider);
118+
119+ // Include providers with OAuth login even without env keys
120+ if (!providers.includes("anthropic") && isLoggedIn("anthropic")) {
121+ providers.push("anthropic");
122+ }
123+
124+ return providers;
117125 }
118126
119127 export function getProvidersToRefreshFromEnv(
@@ -260,10 +268,30 @@ export function supportsThinking(modelString: string): boolean {
260268 return resolveModelInfo(modelString)?.reasoning ?? false;
261269 }
262270
271+function hasCachedModelsForAllVisibleProviders(): boolean {
272+ const visible = getVisibleProvidersForSnapshotFromEnv(process.env);
273+ for (const provider of visible) {
274+ let found = false;
275+ for (const row of runtimeCache.providerModelsByKey.values()) {
276+ if (row.provider === provider) {
277+ found = true;
278+ break;
279+ }
280+ }
281+ if (!found) return false;
282+ }
283+ return true;
284+}
285+
263286 export async function fetchAvailableModelsSnapshot(): Promise<AvailableModelsSnapshot> {
264287 ensureLoaded();
265288 if (isModelInfoStale() && !isModelInfoRefreshing()) {
266- if (runtimeCache.providerModelsByKey.size === 0) {
289+ // Block when the cache is empty or a visible provider has no cached models
290+ // (e.g. user just logged in via OAuth). Otherwise refresh in background.
291+ if (
292+ runtimeCache.providerModelsByKey.size === 0 ||
293+ !hasCachedModelsForAllVisibleProviders()
294+ ) {
267295 await refreshModelInfoInBackground({ force: true });
268296 } else {
269297 void refreshModelInfoInBackground();