Kimi K2.5 on Bedrock: premature end_turn due to Converse API tool call parsing bugs #9446

Open
opened 2026-02-16 18:12:28 -05:00 by yindo · 1 comment
Owner

Originally created by @gopinaath on GitHub (Feb 16, 2026).

Originally assigned to: @rekram1-node on GitHub.

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:

  1. 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.

  2. 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.

  3. 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
Originally created by @gopinaath on GitHub (Feb 16, 2026). Originally assigned to: @rekram1-node on GitHub. ## 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: 1. **Confirmed upstream bug ([vercel/ai#11409](https://github.com/vercel/ai/issues/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. 2. **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. 3. **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 ```json { "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
Author
Owner

@gopinaath commented on GitHub (Feb 16, 2026):

Please merge this at the earliest. AWS customers would like to use OpenCode with Kimi 2.5 on Amazon Bedrock.

@gopinaath commented on GitHub (Feb 16, 2026): Please merge this at the earliest. AWS customers would like to use OpenCode with Kimi 2.5 on Amazon Bedrock.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#9446