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
- Set request.model to a valid model id before sending
- Populate the model from configuration and assert non-empty at startup so the misconfiguration surfaces immediately
- 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
- Make the model a required constructor argument instead of a settable defaulted field
- Validate the request once in a shared send wrapper
- Fail fast at startup if the model comes from configuration
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
- Request must contain at least one content item
- User content must contain at least one part
- Google AI does not support custom tool calls
- Failed to connect to Ollama API: {} {}
AI-assisted analysis of zed-industries/zed@5a9b9558db (2026-08-20).
Data as JSON: /api/errors/c2a8b647716e001b.
Report an issue: GitHub.