BigPizzaV3/CodexPlusPlus · error

Grok 模型 的 API 协议无效

Error message

Grok 模型 {alias} 的 API 协议无效

What it means

validate_request only accepts three API protocol values for Grok models: "responses", "chat_completions", or "messages" (after trimming). Any other string — typos, camelCase variants, empty values — is rejected because the generated config would reference an unsupported backend protocol.

Solutions

  1. Set api_backend to exactly "responses", "chat_completions", or "messages"
  2. Trim surrounding whitespace and convert to the snake_case literal
  3. Check existing valid config entries and copy one of the accepted values

Example fix

// before
api_backend: "chat-completions"
// after
api_backend: "chat_completions"
Defensive patterns

Strategy: validation

Validate before calling

const BACKENDS: [&str;3] = ["responses","chat_completions","messages"]; assert!(BACKENDS.contains(&req.api_backend.trim()));

Type guard

fn is_valid_backend(s: &str) -> bool { matches!(s.trim(), "responses" | "chat_completions" | "messages") }

Prevention

When it happens

Trigger: save_grok_config_at called with input.api_backend set to anything other than the three exact snake_case literals, e.g. "chatCompletions", "chat-completions", "responses_api", or "".

Common situations: Typing the protocol by hand in a config UI; porting settings from another tool that uses different casing/hyphenation; old saved configs using a protocol name that was renamed to snake_case.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at crates/codex-plus-core/src/grok_config.rs:293

        let alias = input.alias.trim();
        if alias.is_empty() {
            bail!("Grok 模型别名不能为空");
        }
        if alias.chars().any(char::is_control) {
            bail!("Grok 模型别名不能包含控制字符");
        }
        if !aliases.insert(alias.to_string()) {
            bail!("Grok 模型别名重复:{alias}");
        }
        let source = input.source_alias.trim();
        if !source.is_empty() && !sources.insert(source.to_string()) {
            bail!("Grok 模型来源别名重复:{source}");
        }
        if !matches!(
            input.api_backend.trim(),
            "responses" | "chat_completions" | "messages"
        ) {
            bail!("Grok 模型 {alias} 的 API 协议无效");
        }
        if input.context_window == Some(0) {
            bail!("Grok 模型 {alias} 的上下文窗口必须大于 0");
        }
        if input
            .context_window
            .is_some_and(|value| value > i64::MAX as u64)
        {
            bail!("Grok 模型 {alias} 的上下文窗口过大");
        }
        if input.remove_api_key && !input.api_key_update.is_empty() {
            bail!("Grok 模型 {alias} 不能同时替换并移除 API Key");
        }
    }
    Ok(())
}

fn table_string(doc: &DocumentMut, table: &str, key: &str) -> String {

View on GitHub (pinned to b1ed92e5e4)