BigPizzaV3/CodexPlusPlus · error

chat response choice missing message

Error message

chat response choice missing message

What it means

The converter expects each choice to contain a message object carrying the assistant reply. If the selected choice lacks `message`, this error is thrown. This usually indicates a non-standard or truncated chat-completion body (e.g. a delta-style chunk rather than a complete message).

Solutions

  1. Confirm the body is a complete (non-streaming) chat completion; route delta chunks to the streaming converter instead.
  2. Log the offending choice to see which fields are actually present (delta? function_call?).
  3. Pin/verify the provider API version so the response schema matches what the converter expects.
  4. Handle tool-call-only responses in the converter before requiring `message`.

Example fix

// before
let message = choice.get("message").ok_or_else(|| anyhow::anyhow!("chat response choice missing message"))?;
// after: accept delta chunks too
let message = choice.get("message")
    .or_else(|| choice.get("delta"))
    .ok_or_else(|| anyhow::anyhow!("choice has neither message nor delta: {}", choice))?;
Defensive patterns

Strategy: type-guard

Validate before calling

let ok = body["choices"][0].get("message").is_some()
    || body["choices"][0].get("delta").is_some();
if !ok {
    anyhow::bail!("choice lacks message/delta; is this a complete completion?");
}

Type guard

fn has_assistant_message(choice: &serde_json::Value) -> bool {
    choice.get("message").map_or(false, |m| m.is_object())
}

Try / catch

match chat_completion_to_response(&body) {
    Ok(v) => v,
    Err(e) if e.to_string().contains("missing message") => {
        log::error!("non-standard choice shape: {}", body["choices"][0]);
        Err(e)
    }
    Err(e) => Err(e),
}

Prevention

When it happens

Trigger: choices[0] exists but has no `message` key — e.g. a streaming delta chunk {"delta": {...}} was fed into the non-streaming converter, or the provider emitted function_call/tool_calls without a message wrapper.

Common situations: Mixing streaming and non-streaming endpoints in the relay; provider API version change removing/renaming message; intermediary proxy stripping fields; passing tool-call chunks through chat conversion.

Related errors


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

Appendix: source

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

    let context = build_codex_tool_context(original_request.get("tools"));
    chat_completion_to_response_with_context(body, &context, Some(original_request))
}

fn chat_completion_to_response_with_context(
    body: Value,
    tool_context: &CodexToolContext,
    original_request: Option<&Value>,
) -> anyhow::Result<Value> {
    let choices = body
        .get("choices")
        .and_then(Value::as_array)
        .ok_or_else(|| anyhow::anyhow!("chat response missing choices"))?;
    let choice = choices
        .first()
        .ok_or_else(|| anyhow::anyhow!("chat response choices is empty"))?;
    let message = choice
        .get("message")
        .ok_or_else(|| anyhow::anyhow!("chat response choice missing message"))?;

    let response_id = response_id_from_chat_id(body.get("id").and_then(Value::as_str));
    let mut output = Vec::new();
    if let Some(reasoning) = chat_reasoning_to_response_output_item(message, &response_id) {
        output.push(reasoning);
    }
    if let Some(message) = chat_message_to_response_output_item(message, &response_id) {
        output.push(message);
    }
    output.extend(chat_tool_calls_to_response_output_items(
        message,
        tool_context,
    ));

    let mut response = json!({
        "id": response_id,
        "object": "response",
        "created_at": body.get("created").and_then(Value::as_u64).unwrap_or(0),

View on GitHub (pinned to b1ed92e5e4)