sigoden/aichat · error
Invalid response data
Error message
Invalid response data: {data} What it means
In claude_extract_chat_completions, a successful Anthropic Messages response parsed to neither text content nor tool calls (reasoning blocks alone don't count). The library considers this an unusable empty completion and bails with the raw response JSON embedded in the message.
Solutions
- Inspect {data} for the actual content array and stop_reason
- Increase max_tokens — thinking tokens consume the budget and can leave zero text tokens
- Check stop_reason (e.g. refusal, max_tokens) in the payload
- If using extended-thinking models, ensure the library version extracts text blocks correctly / update the library
- Capture thinking blocks separately if reasoning-only output is expected
Example fix
// before .with_max_tokens(512) // consumed entirely by thinking -> empty text // after .with_max_tokens(4096) // headroom for thinking + text
Defensive patterns
Strategy: try-catch
Validate before calling
// Give thinking models headroom
if max_tokens <= thinking_budget { return Err("max_tokens must exceed thinking budget".into()); } Try / catch
match client.chat_completions(req).await {
Err(e) if e.to_string().starts_with("Invalid response data") => {
// inspect {data} for content blocks / stop_reason
Err(anyhow!("claude empty completion: {e}"))
}
r => r,
} Prevention
- Increase max_tokens when using extended-thinking models
- Inspect stop_reason (max_tokens, refusal) on empty outputs
- Upgrade the library when Anthropic changes response shapes
- Capture thinking blocks if reasoning-only responses are expected
When it happens
Trigger: claude_chat_completions gets a 2xx response where the content array contains no text/tool_use blocks — e.g. only thinking blocks, an empty content array, or refusal/stop_reason-only responses the extractor doesn't convert.
Common situations: max_tokens exhausted by thinking tokens (extended thinking models) leaving no text output, content filtered by safety, or Anthropic response schema changes.
Understand the failure class
Background: "empty response", "returned no data", "empty embeddings": what HTTP 200-with-empty-body errors mean across libraries — this error's family across 36 libraries.
Related errors
- Invalid response data
- The model does not support network images
- Invalid response data
- Invalid path
- No valid models
AI-assisted analysis of sigoden/aichat@82976d349a (2026-09-09).
Data as JSON: /api/errors/40510f7672e6c302.
Report an issue: GitHub.
Appendix: source
Thrown at src/client/claude.rs:342
item["id"].as_str(),
) {
tool_calls.push(ToolCall::new(
name.to_string(),
input.clone(),
Some(id.to_string()),
));
}
}
_ => {}
}
}
}
if let Some(reasoning) = reasoning {
text = format!("<think>\n{reasoning}\n</think>\n\n{text}")
}
if text.is_empty() && tool_calls.is_empty() {
bail!("Invalid response data: {data}");
}
let output = ChatCompletionsOutput {
text: text.to_string(),
tool_calls,
id: data["id"].as_str().map(|v| v.to_string()),
input_tokens: data["usage"]["input_tokens"].as_u64(),
output_tokens: data["usage"]["output_tokens"].as_u64(),
};
Ok(output)
}
View on GitHub (pinned to 82976d349a)