diff --git a/.changeset/anthropic-max-tokens-fallback.md b/.changeset/anthropic-max-tokens-fallback.md new file mode 100644 index 0000000000..71c9e64db6 --- /dev/null +++ b/.changeset/anthropic-max-tokens-fallback.md @@ -0,0 +1,5 @@ +--- +"@moonshot-ai/kimi-code": patch +--- + +Fix 400 rejections from Anthropic-compatible providers that enforce a lower max_tokens output limit than the default 128000 fallback. Custom endpoints now use a conservative 32768 default, and a rejected request is automatically retried with the provider's declared limit. diff --git a/packages/agent-core-v2/src/agent/llmRequester/llmRequesterService.ts b/packages/agent-core-v2/src/agent/llmRequester/llmRequesterService.ts index e8589fdd74..07c2d0e8c0 100644 --- a/packages/agent-core-v2/src/agent/llmRequester/llmRequesterService.ts +++ b/packages/agent-core-v2/src/agent/llmRequester/llmRequesterService.ts @@ -8,8 +8,10 @@ * params, then drives a bounded request chain through the `ModelRequester` * resolved from `IModelCatalog`: one primary `requester.request(input, signal, * params)` attempt plus projection rebuilds for request structure or media - * compatibility; general retry policy remains in the loop's `stepRetry` - * plugin. Before each request the projected messages pass through `media`'s + * compatibility and a one-shot completion-budget clamp when the provider + * rejects `max_tokens` (the server-declared ceiling is remembered per model, + * so each model pays for at most one rejected-and-resent request); general + * retry policy remains in the loop's `stepRetry` plugin. Before each request the projected messages pass through `media`'s * video resolver, which rewrites every `kimi-file://` prompt-video reference * to a provider-acceptable part (uploaded `ms://`, inline base64, or a * `