Skip to content

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

@gopinaath

Description

@gopinaath

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions