continuedev/continue · warning

Failed to fetch Anthropic models: ${response.status}

Error message

Failed to fetch Anthropic models: ${response.status}

What it means

Thrown by fetchAnthropicModels when the Anthropic models API responds with a non-OK status. Unlike the OpenRouter/Ollama cases, this request includes an x-api-key header, so 401/403 auth failures are a common cause alongside network issues.

Source

Thrown at core/llm/fetchModels.ts:163

      }));
  } catch (error) {
    console.error("Error fetching OpenRouter models:", error);
    return [];
  }
}

async function fetchAnthropicModels(apiKey?: string): Promise<FetchedModel[]> {
  const response = await fetch(
    "https://api.anthropic.com/v1/models?limit=100",
    {
      headers: {
        "x-api-key": apiKey ?? "",
        "anthropic-version": "2023-06-01",
      },
    },
  );
  if (!response.ok) {
    throw new Error(`Failed to fetch Anthropic models: ${response.status}`);
  }
  const data = await response.json();
  return (data.data ?? []).map((m: any) => ({
    name: m.display_name ?? m.id,
    modelId: m.id,
    icon: "anthropic.png",
    contextLength: m.max_input_tokens,
    maxTokens: m.max_tokens,
    supportsTools: true,
  }));
}

async function fetchGeminiModels(
  apiKey?: string,
  apiBase?: string,
): Promise<FetchedModel[]> {
  const base = apiBase || "https://generativelanguage.googleapis.com/v1beta/";
  const url = new URL("models", base);

View on GitHub (pinned to 5522c6f44c)

Solutions

  1. Verify your Anthropic API key is set and valid (test with a minimal curl to the models endpoint)
  2. Check for typos/whitespace in the key and that it's loaded from the right env var/config
  3. Retry on 5xx/429 with backoff; check status.anthropic.com for outages
  4. Confirm the API base URL if overridden (proxy/gateway must forward x-api-key and anthropic-version headers)

Example fix

# before
export ANTHROPIC_API_KEY=sk-ant-wrong
# after
export ANTHROPIC_API_KEY=sk-ant-... # valid key; verify:
curl -s -o /dev/null -w '%{http_code}' https://api.anthropic.com/v1/models -H "x-api-key: $ANTHROPIC_API_KEY" -H "anthropic-version: 2023-06-01"
Defensive patterns

Strategy: try-catch

Validate before calling

const r = await fetch(url, { headers: { 'x-api-key': apiKey } }); if (r.status === 401 || r.status === 403) throw new Error('invalid Anthropic key');

Try / catch

catch (e) { if (e.message.includes('Failed to fetch Anthropic models')) { validateKeyOrPromptUser(); } else throw e; }

Prevention

When it happens

Trigger: Invalid or missing Anthropic API key, revoked key, or API/network errors (5xx, timeouts) hitting the models endpoint.

Common situations: Wrong or expired ANTHROPIC_API_KEY; key lacking access; region-locked API; proxy stripping headers.

Related errors


AI-assisted analysis of continuedev/continue@5522c6f44c (2026-08-27). Data as JSON: /api/errors/eea711d7c7c277af. Report an issue: GitHub.