BigPizzaV3/CodexPlusPlus · error

Base URL 格式无效

Error message

Base URL 格式无效

What it means

validate_llm_proxy_url parses a user-supplied LLM proxy Base URL with reqwest::Url::parse before the app uses it. If the string cannot be parsed as an absolute URL (relative path, missing scheme, illegal characters), the parse error is replaced with this Chinese-language message. This is an input-validation error from the llm_proxy_value handler.

Solutions

  1. Prepend the scheme: change "api.example.com/v1" to "https://api.example.com/v1".
  2. Trim whitespace and remove illegal characters from the URL before saving.
  3. Use a full absolute URL including host (e.g. https://host[:port]/path).
  4. Validate the URL in the frontend input before submitting to the route.

Example fix

// before
let base = "api.deepseek.com/v1";
// after
let base = "https://api.deepseek.com/v1";
Defensive patterns

Strategy: validation

Validate before calling

function isValidProxyBase(raw: string): boolean {
  try {
    const u = new URL(raw.trim());
    return u.protocol === 'https:' && u.hostname.length > 0;
  } catch { return false; }
}

Try / catch

try {
  await api.setLlmProxy({ baseUrl });
} catch (e) {
  if (String(e).includes('Base URL 格式无效')) {
    showFieldError('base_url', '请输入以 https:// 开头的完整 URL');
  } else { throw e; }
}

Prevention

When it happens

Trigger: Entering a Base URL like "api.example.com/v1" (no scheme), "http://" with an empty host, a URL with spaces or unsupported characters, or an empty string into the proxy config.

Common situations: Typing a host without https:// in the relay profile form; pasting a URL with trailing whitespace or invisible characters; missing scheme after a config migration.

Understand the failure class

Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.

Related errors


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

Appendix: source

Thrown at crates/codex-plus-core/src/routes.rs:785

        .map(str::trim)
        .is_some_and(|value| value.eq_ignore_ascii_case("application/json"))
    {
        serde_json::from_slice::<Value>(&bytes).ok()
    } else {
        None
    };

    Ok(json!({
        "status": "ok",
        "http_status": http_status,
        "ok": ok,
        "body_text": body_text,
        "body_json": body_json,
    }))
}

fn validate_llm_proxy_url(raw: &str) -> anyhow::Result<reqwest::Url> {
    let url = reqwest::Url::parse(raw.trim()).map_err(|_| anyhow::anyhow!("Base URL 格式无效"))?;
    if url.scheme() != "https" {
        anyhow::bail!("Base URL 必须使用 HTTPS");
    }
    if !url.username().is_empty() || url.password().is_some() {
        anyhow::bail!("Base URL 不得包含用户名或密码");
    }
    let host = url
        .host_str()
        .ok_or_else(|| anyhow::anyhow!("Base URL 缺少主机名"))?;
    if is_blocked_llm_proxy_host(host) {
        anyhow::bail!("Base URL 不得指向本机或私有网络");
    }
    Ok(url)
}

fn is_blocked_llm_proxy_host(host: &str) -> bool {
    let host = host
        .trim()

View on GitHub (pinned to b1ed92e5e4)