Description
When using Mistral models via @ai-sdk/amazon-bedrock, tool calling fails on multi-turn conversations because the tool call IDs generated by the Bedrock Converse API do not meet Mistral's strict format requirements.
Code to reproduce:
import {createAmazonBedrock} from '@ai-sdk/amazon-bedrock';
import {generateText, jsonSchema} from 'ai';
const bedrock = createAmazonBedrock({
region: 'us-east-1',
// ... credentials
});
const model = bedrock('mistral.ministral-3-14b-instruct');
const result = await generateText({
model,
tools: {
searchWeb: {
description: 'Search the web for information',
parameters: jsonSchema({
type: 'object',
properties: {
query: {type: 'string', description: 'Search query'},
},
required: ['query'],
}),
},
},
toolChoice: 'auto',
messages: [
{
role: 'user',
content: 'Search for the projected revenue for Alphabet Inc. in 2026',
},
],
maxRetries: 1,
});
Expected Behavior
Tool calling should work correctly with Mistral models on Bedrock, similar to how it works with Anthropic models on Bedrock.
Actual Behavior
The first tool call succeeds, but when sending the tool result back for the next turn, the request fails with:
ValidationException: The model returned the following errors:
{
"code": "validation_error",
"message": "Tool call id was i-nKGDr5g but must be a-z, A-Z, 0-9, with a length of 9.
Tool call id was i-nKGDr5g but must be a-z, A-Z, 0-9, with a length of 9.",
"param": null,
"type": "invalid_request_error"
}
Root Cause Analysis
- Bedrock generates tool call IDs in its own format:
tooluse_bpe71yCfRu2b5i-nKGDr5g
- Mistral requires tool call IDs to match the regex
^[a-zA-Z0-9]{9}$:
- Exactly 9 characters
- Alphanumeric only (no underscores, hyphens, or prefixes)
- When the tool result is sent back with the Bedrock-format ID, Mistral's validation rejects it
Related Issues
This is a known compatibility issue that has been addressed in other projects:
Suggested Fix
Add Mistral-specific tool call ID normalization in @ai-sdk/amazon-bedrock. The opencode project implemented this via a normalizeMistralToolCallIds() function that:
- Detects Mistral models by provider/model ID
- Transforms tool call IDs to meet Mistral's requirements (first 9 alphanumeric characters)
Example transformation:
tooluse_bpe71yCfRu2b5i-nKGDr5g → bpe71yCfR (9 alphanumeric chars)
Workaround
Currently, there is no workaround other than avoiding tool use with Mistral models on Bedrock, or implementing a custom transformation layer at the application level.
Additional Context
Full error response from Bedrock:
{
"statusCode": 400,
"responseHeaders": {
"x-amzn-errortype": "ValidationException:http://internal.amazon.com/coral/com.amazon.bedrock/",
"x-amzn-requestid": "1db5f47e-7335-4051-bea0-224852765024"
},
"responseBody": {
"message": "The model returned the following errors: {\"code\":\"validation_error\",\"message\":\"Tool call id was i-nKGDr5g but must be a-z, A-Z, 0-9, with a length of 9.\"}"
}
}
AI SDK Version
Environment:
ai: 5.0.27
@ai-sdk/amazon-bedrock: 3.0.19
- Node.js: 20.x
- AWS Region:
us-east-1
Mistral models affected:
mistral.mistral-large-2407-v1:0
mistral.ministral-3-14b-instruct
mistral.ministral-3-8b-instruct
Code of Conduct
Description
When using Mistral models via
@ai-sdk/amazon-bedrock, tool calling fails on multi-turn conversations because the tool call IDs generated by the Bedrock Converse API do not meet Mistral's strict format requirements.Code to reproduce:
Expected Behavior
Tool calling should work correctly with Mistral models on Bedrock, similar to how it works with Anthropic models on Bedrock.
Actual Behavior
The first tool call succeeds, but when sending the tool result back for the next turn, the request fails with:
Root Cause Analysis
tooluse_bpe71yCfRu2b5i-nKGDr5g^[a-zA-Z0-9]{9}$:Related Issues
This is a known compatibility issue that has been addressed in other projects:
Suggested Fix
Add Mistral-specific tool call ID normalization in
@ai-sdk/amazon-bedrock. The opencode project implemented this via anormalizeMistralToolCallIds()function that:Example transformation:
tooluse_bpe71yCfRu2b5i-nKGDr5g→bpe71yCfR(9 alphanumeric chars)Workaround
Currently, there is no workaround other than avoiding tool use with Mistral models on Bedrock, or implementing a custom transformation layer at the application level.
Additional Context
Full error response from Bedrock:
{ "statusCode": 400, "responseHeaders": { "x-amzn-errortype": "ValidationException:http://internal.amazon.com/coral/com.amazon.bedrock/", "x-amzn-requestid": "1db5f47e-7335-4051-bea0-224852765024" }, "responseBody": { "message": "The model returned the following errors: {\"code\":\"validation_error\",\"message\":\"Tool call id was i-nKGDr5g but must be a-z, A-Z, 0-9, with a length of 9.\"}" } }AI SDK Version
Environment:
ai:5.0.27@ai-sdk/amazon-bedrock:3.0.19us-east-1Mistral models affected:
mistral.mistral-large-2407-v1:0mistral.ministral-3-14b-instructmistral.ministral-3-8b-instructCode of Conduct