charmbracelet/crush · error
failed to update preferred model: status code %d
Error message
failed to update preferred model: status code %d
What it means
UpdatePreferredModel's server-rejection path: the server responded with a non-200 status. The status code is embedded in the error message.
Source
Thrown at internal/client/config.go:59
if rsp.StatusCode != http.StatusOK {
return fmt.Errorf("failed to remove config field: status code %d", rsp.StatusCode)
}
return nil
}
// UpdatePreferredModel updates the preferred model on the server.
func (c *Client) UpdatePreferredModel(ctx context.Context, id string, scope config.Scope, modelType config.SelectedModelType, model config.SelectedModel) error {
rsp, err := c.post(ctx, fmt.Sprintf("/workspaces/%s/config/model", id), nil, jsonBody(struct {
Scope config.Scope `json:"scope"`
ModelType config.SelectedModelType `json:"model_type"`
Model config.SelectedModel `json:"model"`
}{Scope: scope, ModelType: modelType, Model: model}), http.Header{"Content-Type": []string{"application/json"}})
if err != nil {
return fmt.Errorf("failed to update preferred model: %w", err)
}
defer rsp.Body.Close()
if rsp.StatusCode != http.StatusOK {
return fmt.Errorf("failed to update preferred model: status code %d", rsp.StatusCode)
}
return nil
}
// SetCompactMode sets compact mode on the server.
func (c *Client) SetCompactMode(ctx context.Context, id string, scope config.Scope, enabled bool) error {
rsp, err := c.post(ctx, fmt.Sprintf("/workspaces/%s/config/compact", id), nil, jsonBody(struct {
Scope config.Scope `json:"scope"`
Enabled bool `json:"enabled"`
}{Scope: scope, Enabled: enabled}), http.Header{"Content-Type": []string{"application/json"}})
if err != nil {
return fmt.Errorf("failed to set compact mode: %w", err)
}
defer rsp.Body.Close()
if rsp.StatusCode != http.StatusOK {
return fmt.Errorf("failed to set compact mode: status code %d", rsp.StatusCode)
}
return nilView on GitHub (pinned to 7944b8e522)
Solutions
- Check the status code and server logs to identify the rejected payload
- Validate the model id and model type against the provider catalog before calling
- Update the server binary if it predates the model type being set
Defensive patterns
Strategy: validation
Validate before calling
// Ensure the model exists in the provider catalog first
catalog, err := config.Providers()
if err != nil {
return err
}
if !catalog.HasModel(modelType, model.ID) {
return fmt.Errorf("unknown model %q for type %s", model.ID, modelType)
} Try / catch
if err := c.UpdatePreferredModel(ctx, id, scope, modelType, model); err != nil {
if strings.Contains(err.Error(), "status code 400") {
return fmt.Errorf("server rejected model payload: %w", err)
}
return err
} Prevention
- Validate model ids/types against the catalog before updating
- Keep client and server model catalogs in sync
- Surface the embedded status code to users for diagnosis
When it happens
Trigger: POST /workspaces/{id}/config/model returns non-200, e.g. 400 when the SelectedModel payload is invalid or the model type is unknown to the server.
Common situations: Client sends a model the server/provider catalog does not know; stale server not recognizing newer model types; workspace gone.
Related errors
- failed to set config field: status code %d
- failed to remove config field: status code %d
- failed to update preferred model: %w
- failed to set large model: %w
- failed to set small model: %w
AI-assisted analysis of charmbracelet/crush@7944b8e522 (2026-08-29).
Data as JSON: /api/errors/8345e8c103da5f4e.
Report an issue: GitHub.