Skip to content

Bedrock: configured output limit never sent, long reasoning turns truncate at 4096 tokens #46595

Closed

Description

@clopca

Description

V2 sends Bedrock Converse requests without inferenceConfig.maxTokens, even when the model config sets limit.output: 128000. The prepared model request only carries generation values set by hooks/context, so the resolved limit never reaches the provider and Bedrock applies a much lower implicit budget.

With adaptive thinking (reasoningConfig: adaptive, effort xhigh), reasoning and text share that budget. Long-thinking turns finish as max_tokens at exactly 4096 output tokens, often reasoning-only with no visible text.

Captured request (via a session.hook("http.request") plugin, sanitized): additionalModelRequestFields.thinking is present, inferenceConfig is absent:

{
  "url": "https://bedrock-runtime.us-east-1.amazonaws.com/model/global.anthropic.claude-fable-5/converse-stream",
  "modelId": "global.anthropic.claude-fable-5",
  "inferenceConfig": null,
  "additionalModelRequestFields": { "thinking": { "type": "adaptive", "display": "summarized" }, "output_config": { "effort": "xhigh" } }
}

Auditing ~1,500 sessions across two workspaces: 1,098 assistant turns finished max_tokens at exactly 4,096 output tokens; 552 of them contained reasoning only.

The Bedrock protocol already serializes generation.maxTokens as inferenceConfig.maxTokens; it just never receives a value. I have a fix ready (projects resolved.limit.output into the request with hook/model/route defaults taking precedence) and will open a PR.

Plugins

opencode-bedrock-rotate (bearer token rotation; not related, reproduced with it failing to load)

OpenCode version

0.0.0-beta-18743, also reproduced on 0.0.0-dev-18806

Steps to reproduce

  1. Configure a Bedrock Claude model with limit.output: 128000 and an adaptive reasoning variant.
  2. Log outgoing requests with a plugin hooked on session.hook("http.request").
  3. The request has no inferenceConfig; turns with long reasoning truncate at 4096 output tokens.

Activity

  1. github-actions commented on Sep 1, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of an existing issue. Please check:

    If #29363 covers the same root fix, it may be worth coordinating the PR there. If the Bedrock inferenceConfig path is a distinct code site, this can remain a separate issue.

  2. bbartels commented on Sep 2, 2026

    @bbartels
    Contributor

    Running into the same issue!

  3. TheFerragamo commented on Sep 4, 2026

    @TheFerragamo

    Same root cause reproduces on @ai-sdk/openai-compatible models with @opencode-ai/cli 0.0.0-beta-19086 (opencode2): the outbound /chat/completions body has no max_tokens at all, while opencode 1.18.20 sends max_tokens: 32000 for the same config (limit.output: 131072).

    The code site looks shared, not Bedrock-specific: packages/core/src/session/runner/llm.ts builds LLM.request(...) without a generation block, so openai-chat.ts fromRequest ends up with max_tokens: generation?.maxTokens === undefined. runner/model.ts does copy limit.output into route.defaults.limits, but nothing turns it into generation.maxTokens.

    Effect on my side: DeepSeek V4 with thinking enabled gets the provider's default budget, spends it all on reasoning, and the turn ends at exactly 4096 output tokens with empty content, the same "reasoning only" pattern you describe.

    Filed the openai-compatible details separately in #47398 so the fix can cover both routes.

  4. added a commit that references this issue on Sep 18, 2026
    5de9656
  5. opencode-agent commented on Sep 27, 2026

    @opencode-agent
    Contributor

    Fix merged into v2 in #51271. It landed after v2.0.18 and will be included in the next V2 release, v2.0.19. Primary requests now supply the output-token limit that Bedrock Converse sends as inferenceConfig.maxTokens, instead of falling back to Bedrock's implicit limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions