BigPizzaV3/CodexPlusPlus · error · anyhow::Error

模型路由不能指向当前供应商自身:

Error message

模型路由不能指向当前供应商自身:{model}

What it means

select_model_route resolves a model-based route for an incoming request. When the matched route's target_relay_id equals the source relay's own id, the request would loop back to the originating provider, so it is rejected with this error to prevent self-routing cycles.

Solutions

  1. Edit the model route in settings so target_relay_id points at a different relay profile
  2. If the profile was cloned, ensure each profile has a unique id and fix stale duplicated ids
  3. Remove the self-referencing route entry if it is unnecessary

Example fix

# before
[[model_routes]]
model = "gpt-5"
target_relay_id = "relay-a"   # same as source relay-a
# after
[[model_routes]]
model = "gpt-5"
target_relay_id = "relay-b"
Defensive patterns

Strategy: validation

Validate before calling

fn route_is_self_source(route: &ModelRoute, source_id: &str) -> bool {
    route.target_relay_id.trim() == source_id
}
// call before saving settings; reject self-referencing routes

Try / catch

match select_model_route(&settings, model) {
    Ok(Some(sel)) => forward(sel),
    Ok(None) => default_forward(),
    Err(e) if e.to_string().contains("不能指向当前供应商自身") => reject_config_and_prompt_user(e),
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: A model route table entry maps model {model} to target_relay_id that is identical to the id of the relay profile handling the request (source.id), typically due to a copy-paste mistake in settings.

Common situations: User created a route entry on an aggregate/member provider pointing to itself; duplicated relay ids in settings after cloning a profile; migration produced a route whose target defaulted to the source.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19). Data as JSON: /api/errors/e4dc0a8db13ccbc1. Report an issue: GitHub.

Appendix: source

Thrown at crates/codex-plus-core/src/protocol_proxy.rs:792

fn select_model_route(
    settings: &crate::settings::BackendSettings,
    model: &str,
) -> anyhow::Result<Option<ModelRouteSelection>> {
    if model.is_empty() || settings.active_aggregate_relay_profile().is_some() {
        return Ok(None);
    }

    let source = settings.active_relay_profile();
    let Some(route) = source
        .model_routes
        .iter()
        .find(|route| route.model.trim() == model)
    else {
        return Ok(None);
    };
    let target_relay_id = route.target_relay_id.trim();
    if target_relay_id == source.id {
        anyhow::bail!("模型路由不能指向当前供应商自身:{model}");
    }
    let target = settings
        .relay_profiles
        .iter()
        .find(|profile| profile.id == target_relay_id)
        .cloned()
        .with_context(|| format!("模型路由目标供应商不存在:{target_relay_id}"))?;
    if target.relay_mode == crate::settings::RelayMode::Aggregate {
        anyhow::bail!("模型路由目标不能是聚合供应商:{}", target.name);
    }
    if target.protocol != RelayProtocol::Responses {
        anyhow::bail!("模型路由目标必须使用 Responses API:{}", target.name);
    }

    let upstream_model = if route.target_model.trim().is_empty() {
        model.to_string()
    } else {
        route.target_model.trim().to_string()

View on GitHub (pinned to b1ed92e5e4)