Description
Kimi K2.5 on Amazon Bedrock (amazon-bedrock/moonshotai.kimi-k2.5) makes 2-3 tool calls then issues end_turn, requiring multiple opencode run invocations for tasks that should complete in one session. The same model via OpenAI-compatible endpoints (e.g., opencode/kimi-k2.5-free) chains 14+ tool calls autonomously in a single session.
Root Cause
Bedrock's Converse API has known tool call parsing bugs for Moonshot AI models:
-
Confirmed upstream bug (vercel/ai#11409): Internal model tokens (<|tool_call_begin|>, <|tool_call_end|>, <|tool_call_argument_begin|>) intermittently leak into text output instead of being parsed as tool calls. When this happens, the AI SDK sees a text response + end_turn instead of tool_use, so the agentic loop exits prematurely.
-
Unsupported configuration: Kimi/Moonshot models are not listed in AWS's official Converse API tool calling support table, meaning the translation layer may not be properly maintained.
-
Lossy format translation: Bedrock must translate between Converse API format (tool results as toolResult blocks in user messages) and Kimi's native OpenAI format (role: "tool" messages). This translation is opaque and demonstrably buggy.
Reproduction
{
"model": "amazon-bedrock/moonshotai.kimi-k2.5",
"provider": {
"amazon-bedrock": {
"options": { "region": "us-east-1" }
}
}
}
opencode run "Build a REST API bookmark manager using Flask and SQLite with CRUD endpoints, tag filtering, test script, run tests, and show results."
Expected: Single opencode run completes the full task (8+ tool calls).
Actual: Model stops after 2-3 tool calls. Requires 4 separate opencode run invocations.
Validated Fix
Routing Kimi/Moonshot models through Bedrock's OpenAI-compatible endpoint (bedrock-mantle.<region>.api.aws/v1) instead of the Converse API completely eliminates the premature stopping:
| Route |
Tool calls per session |
Task completed in one run? |
| Converse API |
2-3 (then end_turn) |
No (4 invocations needed) |
| bedrock-mantle (OpenAI-compatible) |
8+ |
Yes |
| opencode/kimi-k2.5-free (OpenAI-compatible) |
14 |
Yes |
Environment
- OpenCode v1.1.65
- AI SDK: @ai-sdk/amazon-bedrock 3.0.79, ai 5.0.133
- Region: us-east-1
- Auth: AWS_BEARER_TOKEN_BEDROCK
Description
Kimi K2.5 on Amazon Bedrock (
amazon-bedrock/moonshotai.kimi-k2.5) makes 2-3 tool calls then issuesend_turn, requiring multipleopencode runinvocations for tasks that should complete in one session. The same model via OpenAI-compatible endpoints (e.g.,opencode/kimi-k2.5-free) chains 14+ tool calls autonomously in a single session.Root Cause
Bedrock's Converse API has known tool call parsing bugs for Moonshot AI models:
Confirmed upstream bug (vercel/ai#11409): Internal model tokens (
<|tool_call_begin|>,<|tool_call_end|>,<|tool_call_argument_begin|>) intermittently leak into text output instead of being parsed as tool calls. When this happens, the AI SDK sees a text response +end_turninstead oftool_use, so the agentic loop exits prematurely.Unsupported configuration: Kimi/Moonshot models are not listed in AWS's official Converse API tool calling support table, meaning the translation layer may not be properly maintained.
Lossy format translation: Bedrock must translate between Converse API format (tool results as
toolResultblocks in user messages) and Kimi's native OpenAI format (role: "tool"messages). This translation is opaque and demonstrably buggy.Reproduction
{ "model": "amazon-bedrock/moonshotai.kimi-k2.5", "provider": { "amazon-bedrock": { "options": { "region": "us-east-1" } } } }Expected: Single
opencode runcompletes the full task (8+ tool calls).Actual: Model stops after 2-3 tool calls. Requires 4 separate
opencode runinvocations.Validated Fix
Routing Kimi/Moonshot models through Bedrock's OpenAI-compatible endpoint (
bedrock-mantle.<region>.api.aws/v1) instead of the Converse API completely eliminates the premature stopping:end_turn)Environment