{"record":{"id":"baf15eefcf70a096","repo":"sigoden/aichat","slug":"invalid-response-data-data","errorCode":null,"errorMessage":"Invalid response data: {data}","messagePattern":"Invalid response data: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/client/bedrock.rs","lineNumber":201,"sourceCode":"\n    if !status.is_success() {\n        catch_error(&data, status.as_u16())?;\n    }\n\n    debug!(\"non-stream-data: {data}\");\n    extract_chat_completions(&data)\n}\n\nasync fn chat_completions_streaming(\n    builder: RequestBuilder,\n    handler: &mut SseHandler,\n) -> Result<()> {\n    let res = builder.send().await?;\n    let status = res.status();\n    if !status.is_success() {\n        let data: Value = res.json().await?;\n        catch_error(&data, status.as_u16())?;\n        bail!(\"Invalid response data: {data}\");\n    }\n\n    let mut function_name = String::new();\n    let mut function_arguments = String::new();\n    let mut function_id = String::new();\n    let mut reasoning_state = 0;\n\n    let mut stream = res.bytes_stream();\n    let mut buffer = BytesMut::new();\n    let mut decoder = MessageFrameDecoder::new();\n    while let Some(chunk) = stream.next().await {\n        let chunk = chunk?;\n        buffer.extend_from_slice(&chunk);\n        while let DecodedFrame::Complete(message) = decoder.decode_frame(&mut buffer)? {\n            let response_headers = parse_response_headers(&message)?;\n            let message_type = response_headers.message_type.as_str();\n            let smithy_type = response_headers.smithy_type.as_str();\n            match (message_type, smithy_type) {","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/sigoden/aichat/blob/82976d349ad97ac9aae0655ad631dace5e2a6385/src/client/bedrock.rs#L183-L219","documentation":"In the Bedrock client's streaming chat-completions path, a non-success HTTP response is returned by the EventStream request. The library parses the JSON error body, runs catch_error() for known error shapes, and if the body is not a recognized error shape it bails with 'Invalid response data' embedding the raw response data. This means Bedrock returned an HTTP failure whose body did not match any known error schema.","triggerScenarios":"chat_completions_streaming on Bedrock receives status.is_success() == false AND the parsed JSON body is not recognized by catch_error() (e.g. throttling/quota errors, model access errors, or HTML/agent error pages with unexpected JSON shapes).","commonSituations":"Model not enabled in the AWS account/region, missing IAM permissions (bedrock:InvokeModelWithResponseStream), throttling due to rate limits, invalid model ID, or a proxy returning a non-standard error body.","solutions":["Print the {data} in the message — it contains Bedrock's actual error payload explaining the root cause","Verify the model ID is correct and enabled for your account in the target region","Check IAM permissions for bedrock:InvokeModelWithResponseStream","Retry with backoff if the payload indicates throttling/TooManyRequests","Check AWS region configuration matches a region where the model is available"],"exampleFix":"// before\nlet client = Client::default().with_model(\"claude-3-sonnet\");\n// after (use full inference profile / correct model id)\nlet client = Client::default().with_model(\"anthropic.claude-3-sonnet-20240229-v1:0\");","handlingStrategy":"try-catch","validationCode":"// Before the call: ensure model id and creds are set\nif client.model().is_empty() { return Err(\"model id required\".into()); }","typeGuard":"fn is_success_status(res: &reqwest::Response) -> bool { res.status().is_success() }","tryCatchPattern":"match client.chat_completions_streaming(req).await {\n    Err(e) if e.to_string().starts_with(\"Invalid response data\") => {\n        // surface the embedded payload; check model access/IAM before retrying\n        log::error!(\"bedrock error: {e}\");\n    }\n    r => r?,\n}","preventionTips":["Log the full error message — it embeds the raw Bedrock payload","Verify model access/enabled models in the AWS region beforehand","Test IAM permissions with a minimal bedrock:InvokeModelWithResponseStream policy","Retry throttling errors with exponential backoff"],"tags":["aws","bedrock","http-error","streaming","api-response"],"backgroundTag":"http-error-response","analyzedSha":"82976d349ad97ac9aae0655ad631dace5e2a6385","analyzedAt":"2026-09-09T18:33:06.139Z","contentChangedAt":"2026-09-09T18:33:06.139Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}