api: include turn/payload/message count in API error messages

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Kent Overstreet 2026-03-22 02:16:51 -04:00
parent be2b499978
commit f70d108193

View file

@ -59,7 +59,13 @@ pub async fn call_api_with_tools(
&ui_tx,
StreamTarget::Autonomous,
&reasoning,
).await.map_err(|e| format!("API error: {}", e))?;
).await.map_err(|e| {
let msg_bytes: usize = messages.iter()
.map(|m| m.content_text().len())
.sum();
format!("API error on turn {} (~{}KB payload, {} messages): {}",
turn, msg_bytes / 1024, messages.len(), e)
})?;
if let Some(u) = &usage {
log(&format!("tokens: {} prompt + {} completion",