BigPizzaV3/CodexPlusPlus · error · anyhow::Error

图片上游 Base URL 不能指向本地协议代理

Error message

图片上游 Base URL 不能指向本地协议代理

What it means

open_image_proxy_request validates the upstream base URL before forwarding an image API (generations/edits) request. If the effective base URL (relay.upstream_base_url, falling back to relay_profile_base_url) resolves to a local protocol-proxy address (loopback/private scheme handled by this proxy itself), it refuses to proceed to prevent a proxy loop. The throw is a pre-flight safety guard in crates/codex-plus-core/src/protocol_proxy.rs.

Solutions

  1. Set the image upstream base URL in the relay profile to a real remote endpoint (e.g. https://api.openai.com), not a localhost address
  2. If upstream_base_url was intentionally blank, set relay_profile_base_url's source profile to a non-local URL
  3. Restart/re-apply the profile so the generated config no longer points image requests at the local proxy

Example fix

// before
upstream_base_url = "http://127.0.0.1:8317"
// after
upstream_base_url = "https://api.openai.com"
Defensive patterns

Strategy: validation

Validate before calling

let base = if relay.upstream_base_url.trim().is_empty() { crate::relay_config::relay_profile_base_url(&relay) } else { relay.upstream_base_url.trim().to_string() };
if base.trim().is_empty() || is_local_protocol_proxy_base_url(&base) { return Err("fix upstream base url first"); }

Try / catch

match open_image_generations_proxy_request(...) {
    Err(e) if e.to_string().contains("不能指向本地协议代理") => eprintln!("配置了本地代理地址,请改为远程上游 URL: {e}"),
    other => other?,
}

Prevention

When it happens

Trigger: Calling open_image_generations_proxy_request or open_image_edits_proxy_request while the active relay profile's upstream_base_url (or the profile-derived base URL) points at localhost/127.0.0.1 or another local protocol proxy endpoint.

Common situations: User pasted a local relay address (e.g. http://127.0.0.1:port) into the '图片上游 Base URL' field of a relay profile, or relay_profile_base_url fallback resolved to the local proxy because the explicit upstream URL was blank.

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/1603c7ff69c87e59. Report an issue: GitHub.

Appendix: source

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

        }
    }
}

async fn open_image_proxy_request(
    body: &[u8],
    content_type: &str,
    original_user_agent: Option<&str>,
    endpoint_kind: ImageProxyEndpoint,
) -> anyhow::Result<UpstreamProxyResponse> {
    let settings = SettingsStore::default().load().unwrap_or_default();
    let relay = crate::relay_rotation::select_relay_for_probe(&settings)?;
    let base_url = if relay.upstream_base_url.trim().is_empty() {
        crate::relay_config::relay_profile_base_url(&relay)
    } else {
        relay.upstream_base_url.trim().to_string()
    };
    if is_local_protocol_proxy_base_url(&base_url) {
        anyhow::bail!("图片上游 Base URL 不能指向本地协议代理");
    }
    if base_url.trim().is_empty() {
        anyhow::bail!("图片上游 Base URL 不能为空");
    }
    if relay.api_key.trim().is_empty() && !relay.uses_no_auth() {
        anyhow::bail!("图片上游 Key 不能为空");
    }
    let content_type = content_type.trim();
    let content_type = if content_type.is_empty() {
        match endpoint_kind {
            ImageProxyEndpoint::Generations => "application/json",
            ImageProxyEndpoint::Edits => {
                anyhow::bail!("图片 edits 请求缺少 Content-Type");
            }
        }
    } else {
        content_type
    };

View on GitHub (pinned to b1ed92e5e4)