zed-industries/zed · error

Model must be specified

Error message

Model must be specified

What it means

validate_generate_content_request rejects a GenerateContentRequest whose 'model' field is an empty string. The Generative Language API needs a model id (e.g. gemini-2.0-flash) to route the request; an empty model means the caller built the struct without ever populating it. This is a client-side validation error, raised before any network I/O.

Source

Thrown at crates/google_ai/src/google_ai.rs:81

                    }
                    Err(error) => Some(Err(anyhow!(error))),
                }
            })
            .boxed())
    } else {
        let mut text = String::new();
        response.body_mut().read_to_string(&mut text).await?;
        Err(anyhow!(
            "error during streamGenerateContent, status code: {:?}, body: {}",
            response.status(),
            text
        ))
    }
}

pub fn validate_generate_content_request(request: &GenerateContentRequest) -> Result<()> {
    if request.model.is_empty() {
        bail!("Model must be specified");
    }

    if request.contents.is_empty() {
        bail!("Request must contain at least one content item");
    }

    if let Some(user_content) = request
        .contents
        .iter()
        .find(|content| content.role == Role::User)
        && user_content.parts.is_empty()
    {
        bail!("User content must contain at least one part");
    }

    Ok(())
}

View on GitHub (pinned to 5a9b9558db)

Solutions

  1. Set request.model to a valid model id before sending
  2. Populate the model from configuration and assert non-empty at startup so the misconfiguration surfaces immediately
  3. Centralize request construction in one builder or function that requires the model as an argument

Example fix

// before
let request = GenerateContentRequest { model: String::new(), contents, ..Default::default() };

// after
let request = GenerateContentRequest { model: "gemini-2.0-flash".into(), contents, ..Default::default() };
Defensive patterns

Strategy: validation

Validate before calling

// before calling the API
anyhow::ensure!(!request.model.trim().is_empty(), "model id is required");

Type guard

fn has_model(request: &GenerateContentRequest) -> bool {
    !request.model.trim().is_empty()
}

Prevention

When it happens

Trigger: Constructing GenerateContentRequest with the default empty model string and passing it to generate/stream; copying or templating a request and dropping the model field; loading the model id from an unset setting or environment variable.

Common situations: New integration code that forgets the model id; model selection wired to an unset config key; refactors that move the model into a different field and leave the struct default.

Related errors


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