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
- Confirm the body is a complete (non-streaming) chat completion; route delta chunks to the streaming converter instead.
- Log the offending choice to see which fields are actually present (delta? function_call?).
- Pin/verify the provider API version so the response schema matches what the converter expects.
- 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
- Never feed streaming delta chunks into the non-streaming converter
- Pin provider API versions and re-test converters after upgrades
- Handle tool-call-only choices explicitly before requiring `message`
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
- chat response missing choices
- chat response choices is empty
- API 未返回有效的 choices[0].message.content,请确认兼容 Chat Completions
- 当前中转未启用 Chat Completions 协议代理
- Chat Completions 协议暂不支持 Responses compact 请求
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)