zed-industries/zed · error

cannot fetch Anthropic models without an API key

Error message

cannot fetch Anthropic models without an API key

What it means

Early-return guard in AnthropicLanguageModelProvider::fetch_models: `api_key_state.key(&api_url)` returned None, so there is no Anthropic API key with which to call the models list endpoint. Model listing requires authentication; this fires when fetch_models runs (e.g. via restart_fetch_models_task after authenticate) before the user has provided credentials.

Source

Thrown at crates/language_models/src/provider/anthropic.rs:108

            credentials_provider,
            cx,
        );

        cx.spawn(async move |this, cx| {
            let result = task.await;
            if result.is_ok() {
                this.update(cx, |this, cx| this.restart_fetch_models_task(cx))
                    .ok();
            }
            result
        })
    }

    fn fetch_models(&mut self, cx: &mut Context<Self>) -> Task<Result<()>> {
        let http_client = self.http_client.clone();
        let api_url = AnthropicLanguageModelProvider::api_url(cx);
        let Some(api_key) = self.api_key_state.key(&api_url) else {
            return Task::ready(Err(anyhow::anyhow!(
                "cannot fetch Anthropic models without an API key"
            )));
        };
        let extra_headers = AnthropicLanguageModelProvider::settings(cx)
            .custom_headers
            .clone();

        cx.spawn(async move |this, cx| {
            let models = anthropic::list_models(
                http_client.as_ref(),
                &api_url,
                api_key.as_ref(),
                &extra_headers,
            )
            .await
            .map_err(LanguageModelCompletionError::from)?;

            this.update(cx, |this, cx| {

View on GitHub (pinned to f4178619ac)

Solutions

  1. Sign in / enter an Anthropic API key in the provider settings so authenticate() can store it
  2. Check that the credentials provider has a stored key for the configured api_url
  3. If using a custom base URL, ensure credentials exist for that URL, not just the default
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/language_models/src/provider/anthropic.rs:108 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20). Data as JSON: /api/errors/31cc71b9d9945502. Report an issue: GitHub.