Skip to content

fix: forward maxOutputSize to OpenAI-compatible providers#438

Closed
RTCartist wants to merge 3 commits into
MoonshotAI:mainfrom
RTCartist:fix/openai-provider-max-output-size
Closed

fix: forward maxOutputSize to OpenAI-compatible providers#438
RTCartist wants to merge 3 commits into
MoonshotAI:mainfrom
RTCartist:fix/openai-provider-max-output-size

Conversation

@RTCartist
Copy link
Copy Markdown

@RTCartist RTCartist commented Jun 4, 2026

Related Issue

Resolve #306

Problem

toKosongProviderConfig forwards maxOutputSize as defaultMaxTokens for the Anthropic provider but omits it for openai and openai_responses. As a result, OpenAI-compatible providers like DeepSeek receive the full max_context_size (1,000,000) as max_tokens via the completion-budget fallback, exceeding the model's actual cap and triggering 400 Invalid max_tokens value.

What changed

Forward maxOutputSize as maxTokens to the openai provider config and as maxOutputTokens to openai_responses, matching the constructor signatures of the respective ChatProvider classes. Added three tests in runtime-provider.test.ts covering both providers (set / unset).

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

Verification

  • pnpm -C packages/agent-core exec vitest run test/harness/runtime-provider.test.ts

Note: PR #318 by @qkunio addresses #306 at the budget-resolution layer; this PR addresses the provider-construction layer. The two fixes are complementary.

RTCartist added 2 commits June 4, 2026 23:51
The `toKosongProviderConfig` function forwarded `maxOutputSize` as
`defaultMaxTokens` for Anthropic providers but omitted it for
`openai` and `openai_responses` providers. This caused
OpenAI-compatible providers like DeepSeek to receive the full
`max_context_size` (e.g. 1,000,000) as `max_tokens`, exceeding the
model's actual limit and triggering a 400 error.

Forward `maxOutputSize` as `maxTokens` for the `openai` provider and
as `maxOutputTokens` for the `openai_responses` provider, matching
the constructor interfaces of their respective chat provider classes.

Closes MoonshotAI#306
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jun 4, 2026

🦋 Changeset detected

Latest commit: 305e962

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@moonshot-ai/agent-core Patch
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Source changes live in `packages/agent-core/src/session/provider-manager.ts`,
so the agent-core package needs to bump alongside `@moonshot-ai/kimi-code`
to match the repo convention used by prior internal-package changes.
@liruifengv
Copy link
Copy Markdown
Collaborator

Sorry, we currently do not accept PRs submitted in batches using AI

@liruifengv liruifengv closed this Jun 5, 2026
@RTCartist
Copy link
Copy Markdown
Author

Sorry, we currently do not accept PRs submitted in batches using AI

I think you at least need to review the pr and make decision. All prs have been checked and reviewed by myself. I have worked for it for hours, no logic

@qkunio
Copy link
Copy Markdown
Contributor

qkunio commented Jun 5, 2026

Sorry, we currently do not accept PRs submitted in batches using AI

I think you at least need to review the pr and make decision. All prs have been checked and reviewed by myself. I have worked for it for hours, no logic

I am using v0.10.1, and the problem do not exist. #365 this pr may has solved this, i think.
they are working hard recently, and dont have enough time to review, most pr by people not in kimi were rejected.

@RTCartist
Copy link
Copy Markdown
Author

Sorry, we currently do not accept PRs submitted in batches using AI

I think you at least need to review the pr and make decision. All prs have been checked and reviewed by myself. I have worked for it for hours, no logic

I am using v0.10.1, and the problem do not exist. #365 this pr may has solved this, i think.
they are working hard recently, and dont have enough time to review, most pr by people not in kimi were rejected.

Thanks for your reply. So nice of you. Much better now.

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.

配置 DeepSeek 模型的 max_output_size 后报错 400 Invalid max_tokens value

3 participants