Hmbown/CodeWhale · error · anyhow::Error

model uses , but this client is bound to ; resolve a new…

Error message

{} model {:?} uses {:?}, but this client is bound to {:?}; resolve a new model route before sending

What it means

Each running client instance is bound to one wire protocol format captured at construction. When a request names a model whose resolved protocol differs from the client's bound wire_format, the client refuses to send rather than silently serializing the request with the wrong envelope; the caller must re-resolve the model route (getting a new client) first.

Solutions

  1. Re-resolve the model route so a client bound to the new model's protocol is constructed, then retry the send.
  2. Switch back to a model whose protocol matches the currently bound client.
  3. If a route change happened mid-session, restart the session or reload config so the client rebuilds with the new wire format.
Defensive patterns

Strategy: type-guard

Validate before calling

fn model_matches_client(client: &Client, request_model: &str, registry: &ModelRegistry) -> bool {
    registry.resolve(request_model).map(|m| m.protocol == client.wire_format).unwrap_or(false)
}

Type guard

fn is_bound_to(client: &Client, wire: WireFormat) -> bool { client.wire_format == wire }

Try / catch

match send_result {
    Err(e) if e.to_string().contains("resolve a new model route") => {
        let client = route_registry.client_for_model(request.model)?;
        client.send(request).await?;
    }
    r => r?,
}

Prevention

When it happens

Trigger: Sending a request whose `request.model` resolves to a model with a different protocol than the client was constructed with, e.g. switching a session from an Anthropic-protocol model to an OpenAI-protocol model without rebuilding the client.

Common situations: Changing models mid-session via a slash command or /model switch while the old client is still bound; a config route change repointing a model to a different provider protocol; session resume where the default model changed.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/4c4b0cb18a2f8b78. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/client.rs:1860

        {
            return Ok((request, self.route_limits));
        }

        let candidate = match self.resolve_model_route(&request.model) {
            Ok(candidate) => candidate,
            Err(error) if model_aware || self.api_provider == ApiProvider::OpencodeGo => {
                return Err(error);
            }
            Err(_) => {
                // A fixed-protocol gateway may legitimately accept an id that
                // is newer than our offline catalog. Preserve the caller's
                // model, but fail closed on limits instead of reusing the
                // bound default model's envelope.
                return Ok((request, None));
            }
        };
        if candidate.protocol() != self.wire_format {
            bail!(
                "{} model {:?} uses {:?}, but this client is bound to {:?}; resolve a new model route before sending",
                self.api_provider.display_name(),
                request.model,
                candidate.protocol(),
                self.wire_format
            );
        }
        request.model = candidate.wire_model_id().as_str().to_string();
        let route_limits = crate::route_budget::known_route_limits(candidate.limits());
        Ok((request, route_limits))
    }

    #[cfg(test)]
    fn build_http_client(
        api_key: &str,
        extra_headers: &HashMap<String, String>,
        api_provider: ApiProvider,
        base_url: &str,

View on GitHub (pinned to 73e0f67d83)