BigPizzaV3/CodexPlusPlus · error

当前中转未启用 Chat Completions 协议代理

Error message

当前中转未启用 Chat Completions 协议代理

What it means

The Chat Completions passthrough proxy requires the active relay profile to use RelayProtocol::ChatCompletions. It loads the active relay profile and bails immediately if the profile's protocol is not ChatCompletions. This guard prevents translating/sending Chat Completions traffic through a profile configured for a different protocol (e.g. Responses).

Solutions

  1. Switch the active relay profile's protocol to ChatCompletions in the manager/settings
  2. Or point the client at an endpoint/profile that is configured for Chat Completions
  3. Re-apply the profile so the runtime settings reflect the new protocol

Example fix

// before
protocol = "responses"
// after
protocol = "chat_completions"
Defensive patterns

Strategy: validation

Validate before calling

let relay = SettingsStore::default().load().unwrap_or_default().active_relay_profile();
if relay.protocol != RelayProtocol::ChatCompletions { return Err("profile protocol is not chat_completions"); }

Try / catch

match proxy_chat_completions(...) {
    Err(e) if e.to_string().contains("未启用 Chat Completions 协议代理") => eprintln!("请将当前中转协议切换为 Chat Completions: {e}"),
    other => other?,
}

Prevention

When it happens

Trigger: Invoking the Chat Completions proxy entry (the function whose SOURCE is shown, validating before parsing the body) while settings.active_relay_profile().protocol != ChatCompletions.

Common situations: User switched the relay profile protocol to Responses (or another protocol) but a client still sends Chat Completions traffic through the local proxy; settings file edited manually changing the protocol field.

Related errors


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

Appendix: source

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

    })
}

fn response_header_timeout(is_stream: bool) -> Duration {
    if is_stream {
        UPSTREAM_STREAM_HEADER_TIMEOUT
    } else {
        UPSTREAM_HEADER_TIMEOUT
    }
}

pub async fn open_chat_completions_proxy_request(
    body: &str,
    original_user_agent: Option<&str>,
) -> anyhow::Result<UpstreamProxyResponse> {
    let settings = SettingsStore::default().load().unwrap_or_default();
    let relay = settings.active_relay_profile();
    if relay.protocol != RelayProtocol::ChatCompletions {
        anyhow::bail!("当前中转未启用 Chat Completions 协议代理");
    }
    if relay.base_url.trim().is_empty() {
        anyhow::bail!("Chat Completions 上游 Base URL 不能为空");
    }
    if relay.api_key.trim().is_empty() && !relay.uses_no_auth() {
        anyhow::bail!("Chat Completions 上游 Key 不能为空");
    }

    let request_json: Value = serde_json::from_str(body)?;
    let is_stream = request_json
        .get("stream")
        .and_then(Value::as_bool)
        .unwrap_or(false);
    let request = crate::http_client::proxied_client(&effective_user_agent(
        &relay.user_agent,
        original_user_agent,
    ))?
    .post(chat_completions_url(&relay.base_url))

View on GitHub (pinned to b1ed92e5e4)