Fix: AIMLAPI silently truncates tool call output at 512 tokens#2
Open
uniuuu wants to merge 2 commits intoaimlapi:feature/add-aimlapi-models-providerfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem:
When using claude-opus-4-6, tool calls would silently fail - write calls arrived with no content, exec calls arrived with empty {} arguments. The session JSONL showed "output": 512 and "stopReason": "stop" on every failed call.
Root cause:
AIMLAPI defaults max_tokens to 512 when the parameter is not explicitly set in the request. The model hits this cap mid-generation while serializing tool call JSON, truncates the output, and returns finish_reason: stop as if it completed
normally - no error, no warning.
This is an AIMLAPI-side behaviour documented in their own support article help.aimlapi.com/article/140 .
Fix:
In
applyExtraParamsToAgent (extra-params.ts), inject{ maxTokens: 32768 }as a provider-level default for aimlapi before merging user config and streamParams overrides. This means:maxTokensin the agent model config orstreamParamsstill wins32768 was chosen to match an effective default cap for Opus 4.6, and is well within the model's actual 128K output
token limit.
Logs:
Every write call arrives with truncated arguments - content never generated:
This repeats 15+ consecutive times. The model keeps retrying, context grows by ~145 tokens each turn, and output stays locked at exactly 512 every time. Same for exec: