BigPizzaV3/CodexPlusPlus · error

API Key 为空

Error message

API Key 为空

What it means

Thrown by normalize_request in crates/codex-plus-core/src/provider_import.rs when the import request's api_key is empty after trimming. The key is written into the generated auth.json (build_auth_json) and config.toml, so a blank key aborts the import. For URL imports this maps to the apiKey query parameter.

Source

Thrown at crates/codex-plus-core/src/provider_import.rs:229

        sub2api_multiplier: String::new(),
        model_routes: Vec::new(),
    }
}

fn normalize_request(mut request: ProviderImportRequest) -> anyhow::Result<ProviderImportRequest> {
    request.name = request.name.trim().to_string();
    request.base_url = request.base_url.trim().trim_end_matches('/').to_string();
    request.api_key = request.api_key.trim().to_string();
    request.wire_api = request.wire_api.trim().to_ascii_lowercase();
    request.relay_mode = request.relay_mode.trim().to_ascii_lowercase();
    if request.name.is_empty() {
        anyhow::bail!("供应商名称为空");
    }
    if request.base_url.is_empty() {
        anyhow::bail!("Base URL 为空");
    }
    if request.api_key.is_empty() {
        anyhow::bail!("API Key 为空");
    }
    request.config_contents = build_config_toml(
        &request.base_url,
        &request.api_key,
        relay_protocol(&request.wire_api),
    );
    request.auth_contents = build_auth_json(&request.api_key);
    Ok(request)
}

fn relay_protocol(value: &str) -> RelayProtocol {
    match value.trim().to_ascii_lowercase().as_str() {
        "chat" | "chat_completions" | "chat-completions" => RelayProtocol::ChatCompletions,
        _ => RelayProtocol::Responses,
    }
}

fn relay_mode(value: &str) -> RelayMode {

View on GitHub (pinned to 1f431ae49b)

Solutions

  1. Include a non-empty API key in the import request / apiKey query parameter
  2. If the upstream truly needs no auth, enter any non-empty placeholder and keep in mind the proxy will send it as a bearer token
  3. Regenerate the share link after the key is set

Example fix

# before
https://app/import?name=VendorAI&baseUrl=https%3A%2F%2Fapi.vendor.com&apiKey=

# after
https://app/import?name=VendorAI&baseUrl=https%3A%2F%2Fapi.vendor.com&apiKey=sk-xxxx
Defensive patterns

Strategy: validation

Validate before calling

fn api_key_valid(key: &str) -> bool {
    !key.trim().is_empty()
}

Prevention

When it happens

Trigger: Import request with apiKey omitted or whitespace; share link whose apiKey= parameter is empty; user deliberately omitting the key for a keyless gateway — still rejected, since the import path requires one.

Common situations: Share links generated before the key was chosen; frontend forms not enforcing the key field; users assuming local gateways need no key.

Related errors


AI-assisted analysis of BigPizzaV3/CodexPlusPlus@1f431ae49b (2026-08-16). Data as JSON: /api/errors/0798c387965f1d20. Report an issue: GitHub.