sigoden/aichat · error
Unrecognized message, message_type
Error message
Unrecognized message, message_type: {message_type}, smithy_type: {smithy_type} What it means
The Bedrock EventStream decoder received a message whose (message_type, smithy_type) pair matches none of the known branches (event/exception variants). The library bails with 'Unrecognized message' echoing both identifiers. This guards against new or unknown smithy event shapes being silently dropped.
Solutions
- Log the message_type and smithy_type values reported and compare against Bedrock's EventStream API docs
- Update the library (and aws-smithy event-stream handling) to a version that knows the new event type
- File/track an issue upstream to add a handler for the reported smithy_type
- Bypass intermediaries/proxies that might rewrite the event stream
- Pin to a Bedrock API version/model whose stream events are supported
Example fix
// before rig = "0.x" # old client without new event handler // after rig = "latest" # or patch the match in src/client/bedrock.rs to handle the new smithy_type
Defensive patterns
Strategy: fallback
Try / catch
match client.chat_completions_streaming(req).await {
Err(e) if e.to_string().starts_with("Unrecognized message") => {
log::warn!("unknown bedrock event: {e}; falling back to non-streaming");
client.chat_completions(req).await
}
r => r,
} Prevention
- Keep the library updated so new smithy event types are handled
- Capture message_type/smithy_type from the message and report upstream
- Avoid proxies that may alter event-stream framing
- Pin supported model/API versions
When it happens
Trigger: chat_completions_streaming decodes an event-stream message whose message_type/smithy_type combination falls into the catch-all '_' arm of the match in the streaming loop.
Common situations: AWS introduced a new event type not yet handled by this library version, a protocol/SDK version mismatch between reqwest eventsource handling and Bedrock's stream, or corrupted/unexpected framing from a proxy.
Understand the failure class
Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.
Related errors
- Invalid response data
- 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/9f338676466ba0b9.
Report an issue: GitHub.
Appendix: source
Thrown at src/client/bedrock.rs:294
})?;
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())?;
}
let res_body: EmbeddingsResBody =
serde_json::from_value(data).context("Invalid embeddings data")?;View on GitHub (pinned to 82976d349a)