zed-industries/zed · error · LanguageModelCompletionError

completion request failed, code: {code}, message: {message}

Error message

completion request failed, code: {code}, message: {message}

What it means

Error variant carrying a failed completion request from the cloud gateway: `from_cloud_failure` (with parse_upstream_error_json as its JSON-decoding helper) wraps the gateway's error code and message when a request to the model provider fails upstream. The code classifies the failure (prompt too large, upstream HTTP error, rate limit, etc.) so callers can decide on retry behavior; the message is what the upstream provider returned.

Source

Thrown at crates/language_model_core/src/language_model_core.rs:252

        host: String,
        #[source]
        error: anyhow::Error,
    },
    #[error("error deserializing {provider} API response")]
    DeserializeResponse {
        provider: LanguageModelProviderName,
        #[source]
        error: serde_json::Error,
    },
    #[error("stream from {provider} ended unexpectedly")]
    StreamEndedUnexpectedly { provider: LanguageModelProviderName },
    #[error(transparent)]
    Other(#[from] anyhow::Error),
}

impl LanguageModelCompletionError {
    fn parse_upstream_error_json(message: &str) -> Option<(StatusCode, String)> {
        let error_json = serde_json::from_str::<serde_json::Value>(message).ok()?;
        let upstream_status = error_json
            .get("upstream_status")
            .and_then(|v| v.as_u64())
            .and_then(|status| u16::try_from(status).ok())
            .and_then(|status| StatusCode::from_u16(status).ok())?;
        let inner_message = error_json
            .get("message")
            .and_then(|v| v.as_str())
            .unwrap_or(message)
            .to_string();
        Some((upstream_status, inner_message))
    }

    pub fn from_cloud_failure(
        upstream_provider: LanguageModelProviderName,
        code: String,
        message: String,
        retry_after: Option<Duration>,

View on GitHub (pinned to 5a9b9558db)

Solutions

  1. Read `code` to classify: prompt-too-long means shrink the context, upstream_http_error means the underlying provider failed
  2. Respect any retry_after duration before retrying
  3. Retry transient upstream errors (5xx) with backoff; do not retry 4xx request errors unchanged
  4. If the gateway consistently fails, check provider status and the configured API endpoint
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at crates/language_model_core/src/language_model_core.rs:243 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@5a9b9558db (2026-08-20). Data as JSON: /api/errors/7a70635f11d19538. Report an issue: GitHub.