[PR #13803] fix(bedrock): route Kimi/Moonshot models via bedrock-mantle OpenAI-compatible endpoint #14817

Open
opened 2026-02-16 18:19:34 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/13803

State: open
Merged: No


Fixes #13807

Summary

  • Route Moonshot AI models (Kimi K2.5, Kimi K2 Thinking) through Bedrock's OpenAI-compatible endpoint (bedrock-mantle.<region>.api.aws) instead of the Converse API
  • Fixes tool call parsing failures that cause premature end_turn in multi-step agentic workflows

Problem

Kimi K2.5 on Bedrock via the Converse API exhibits premature stopping behavior — the model 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 chains 14+ tool calls autonomously.

Root cause: Bedrock's Converse API has a known tool call parsing bug for Kimi/Moonshot models (vercel/ai#11409) where internal model tokens leak into text output instead of being parsed as tool calls. Additionally, Moonshot models are not listed in AWS's official Converse API tool calling support table.

Solution

When a Bedrock model ID contains "kimi" or "moonshot", route through bedrock-mantle.<region>.api.aws/v1 using @ai-sdk/openai-compatible instead of the Converse API. This:

  • Bypasses the lossy Converse API translation layer
  • Sends requests in OpenAI format (which Kimi was trained on)
  • Keeps authentication and billing on Bedrock infrastructure
  • Uses the existing bearer token authentication

Validation

Multi-turn tool calling tests with 5 tools and a 4-step task:

Route Steps completed Tool calls Premature end_turn?
Converse API 2-3 then stops 2-3 per session Yes
bedrock-mantle (this PR) All steps 8+ in one session No

Tested with both curl (15 rounds, never stopped) and AI SDK generateText (6 steps, 8 tool calls, task fully completed).

Test plan

  • Run existing Bedrock provider tests
  • Test amazon-bedrock/moonshotai.kimi-k2.5 with multi-step tool calling task
  • Verify non-Moonshot Bedrock models (Claude, Nova) still use Converse API
  • Test with both bearer token and IAM credential authentication
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/13803 **State:** open **Merged:** No --- Fixes #13807 ## Summary - Route Moonshot AI models (Kimi K2.5, Kimi K2 Thinking) through Bedrock's OpenAI-compatible endpoint (`bedrock-mantle.<region>.api.aws`) instead of the Converse API - Fixes tool call parsing failures that cause premature `end_turn` in multi-step agentic workflows ## Problem Kimi K2.5 on Bedrock via the Converse API exhibits premature stopping behavior — the model 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 chains 14+ tool calls autonomously. Root cause: Bedrock's Converse API has a known tool call parsing bug for Kimi/Moonshot models ([vercel/ai#11409](https://github.com/vercel/ai/issues/11409)) where internal model tokens leak into text output instead of being parsed as tool calls. Additionally, Moonshot models are not listed in AWS's official Converse API tool calling support table. ## Solution When a Bedrock model ID contains "kimi" or "moonshot", route through `bedrock-mantle.<region>.api.aws/v1` using `@ai-sdk/openai-compatible` instead of the Converse API. This: - Bypasses the lossy Converse API translation layer - Sends requests in OpenAI format (which Kimi was trained on) - Keeps authentication and billing on Bedrock infrastructure - Uses the existing bearer token authentication ## Validation Multi-turn tool calling tests with 5 tools and a 4-step task: | Route | Steps completed | Tool calls | Premature end_turn? | |---|---|---|---| | Converse API | 2-3 then stops | 2-3 per session | Yes | | bedrock-mantle (this PR) | All steps | 8+ in one session | No | Tested with both curl (15 rounds, never stopped) and AI SDK generateText (6 steps, 8 tool calls, task fully completed). ## Test plan - [ ] Run existing Bedrock provider tests - [ ] Test `amazon-bedrock/moonshotai.kimi-k2.5` with multi-step tool calling task - [ ] Verify non-Moonshot Bedrock models (Claude, Nova) still use Converse API - [ ] Test with both bearer token and IAM credential authentication
yindo added the pull-request label 2026-02-16 18:19:34 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14817