sigoden/aichat · error
Invalid response data
Error message
Invalid response data: {data} (smithy_type: {smithy_type}) What it means
During Bedrock's smithy EventStream decoding, a message of type 'exception' arrives over the stream. The library base64-decodes the payload and bails with 'Invalid response data' including the payload text and its smithy_type. This is Bedrock signaling a mid-stream exception (e.g. ModelStreamErrorException, ThrottlingException) that the client surfaces verbatim.
Solutions
- Read smithy_type and the decoded payload in the message to identify the exact Bedrock exception
- Implement retry with exponential backoff for throttling-type exceptions
- Reduce request size (shorter prompt / smaller max_tokens) to avoid stream timeouts
- Check service health and quota limits in the AWS console
- Ensure SDK/region config is correct if the exception indicates validation failure
Example fix
// before
match result { Err(e) if e.to_string().contains("Throttling") => bail!(e), ... }
// after: retry throttled stream errors
let out = loop {
match client.chat_completions_streaming(req).await {
Err(e) if e.to_string().contains("ThrottlingException") => { tokio::time::sleep(backoff).await; backoff *= 2; }
other => break other,
}
}; Defensive patterns
Strategy: try-catch
Try / catch
match result {
Err(e) if e.to_string().contains("smithy_type: ThrottlingException") => retry_with_backoff(),
Err(e) if e.to_string().contains("Invalid response data") => log::error!("bedrock stream exception: {e}"),
other => other?,
} Prevention
- Parse smithy_type from the error string to branch on the exact Bedrock exception
- Add retries for throttling/timeout stream exceptions
- Keep request sizes moderate to avoid mid-stream timeouts
- Monitor AWS service health and account quotas
When it happens
Trigger: chat_completions_streaming receives an event-stream message with message_type == "exception"; the decoded payload text and smithy_type are included in the error message.
Common situations: Bedrock throttles the stream mid-generation (ThrottlingException), the model stream fails internally (ModelStreamErrorException/ModelTimeoutException), or a long-running generation exceeds service limits.
Related errors
- Unrecognized message, message_type
- Invalid response data
- The model does not support network images
- {err}
- Failed to read json stream
AI-assisted analysis of sigoden/aichat@82976d349a (2026-09-09).
Data as JSON: /api/errors/c697fc5068c7fa1f.
Report an issue: GitHub.
Appendix: source
Thrown at src/client/bedrock.rs:291
}
let arguments: Value = function_arguments.parse().with_context(|| {
format!("Tool call '{function_name}' have non-JSON arguments '{function_arguments}'")
})?;
handler.tool_call(ToolCall::new(
function_name.clone(),
arguments,
Some(function_id.clone()),
))?;
}
}
_ => {}
}
}
("exception", _) => {
let payload = base64_decode(message.payload())?;
let data = String::from_utf8_lossy(&payload);
bail!("Invalid response data: {data} (smithy_type: {smithy_type})")
}
_ => {
bail!("Unrecognized message, message_type: {message_type}, smithy_type: {smithy_type}",);
}
}
}
}
Ok(())
}
async fn embeddings(builder: RequestBuilder) -> Result<EmbeddingsOutput> {
let res = builder.send().await?;
let status = res.status();
let data: Value = res.json().await?;
if !status.is_success() {
catch_error(&data, status.as_u16())?;
}View on GitHub (pinned to 82976d349a)