Skip to content

Fix: AIMLAPI silently truncates tool call output at 512 tokens#2

Open
uniuuu wants to merge 2 commits intoaimlapi:feature/add-aimlapi-models-providerfrom
uniuuu:feature/add-aimlapi-models-provider-fix-512-cap
Open

Fix: AIMLAPI silently truncates tool call output at 512 tokens#2
uniuuu wants to merge 2 commits intoaimlapi:feature/add-aimlapi-models-providerfrom
uniuuu:feature/add-aimlapi-models-provider-fix-512-cap

Conversation

@uniuuu
Copy link

@uniuuu uniuuu commented Feb 21, 2026

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:

  • Any explicit maxTokens in the agent model config or streamParams still wins
  • The AIMLAPI 512-token default is never hit unless the user explicitly sets it

32768 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:

"name": "write",
"arguments": { "file_path": "/home/ubuntu/.openclaw/workspace/TEST.md" }
"usage": { "output": 512 }
"stopReason": "stop"

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:

"name": "exec",
"arguments": {}
"usage": { "output": 512 }
"stopReason": "stop"

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant