Skip to content

feat(managed-kimi-code): route anthropic protocol via beta api#1182

Open
sailist wants to merge 1 commit into
MoonshotAI:mainfrom
sailist:feat/anthropic
Open

feat(managed-kimi-code): route anthropic protocol via beta api#1182
sailist wants to merge 1 commit into
MoonshotAI:mainfrom
sailist:feat/anthropic

Conversation

@sailist

@sailist sailist commented Jun 28, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

N/A — no prior issue; the problem is described below.

Problem

Managed Kimi Code models that declare the Anthropic-compatible protocol (protocol: 'anthropic') are currently served through the standard Messages API (POST /v1/messages). Kimi's anthropic-compatible endpoint is actually backed by the beta Messages API (POST /v1/messages?beta=true), so these models need to be routed through the beta endpoint to behave correctly.

What changed

  • kosong: AnthropicChatProvider gains a betaApi option. When enabled, requests go through client.beta.messages.create (POST /v1/messages?beta=true) instead of the standard client.messages.create.
  • agent-core: ModelAlias gains a betaApi flag, threaded through to the anthropic provider config alongside the existing adaptiveThinking override.
  • oauth: managed Kimi Code now sets betaApi: true on every model that declares protocol: 'anthropic'.

Non-managed Anthropic providers (official api.anthropic.com, OpenRouter, etc.) are unaffected: betaApi defaults to off and the existing standard-endpoint behavior is unchanged.

Tests added/updated in kosong, agent-core, and oauth; all three packages pass tests and tsc --noEmit.

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.

@changeset-bot

changeset-bot Bot commented Jun 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6fd0ebb

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

This PR includes changesets to release 1 package
Name Type
@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

@pkg-pr-new

pkg-pr-new Bot commented Jun 28, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@6fd0ebb
npx https://pkg.pr.new/@moonshot-ai/kimi-code@6fd0ebb

commit: 6fd0ebb

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 177823d8fa

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

let newBetas = [...(this._generationKwargs.betaFeatures ?? [])];

if (adaptive) {
if (adaptive && !this._explicitBetaFeatures) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve adaptive thinking with explicit betas

When config comes from managed Kimi Code, packages/oauth/src/managed-kimi-code.ts now sets both betaFeatures and adaptiveThinking: true for thinking-capable Anthropic-protocol models. This condition makes withThinking('high') skip the adaptive branch whenever beta features are explicit, so requests fall through to thinking: { type: 'enabled', budget_tokens: ... } (and max can throw in budgetTokensForEffort) instead of the type: 'adaptive' payload that Kimi's Anthropic-compatible endpoint requires. Keep beta-list preservation separate from selecting the adaptive thinking payload.

Useful? React with 👍 / 👎.

- kosong: add betaApi option to use client.beta.messages.create
- agent-core: thread alias betaApi into the anthropic provider config
- oauth: route managed models on the anthropic protocol through the beta Messages API
@sailist

sailist commented Jun 28, 2026

Copy link
Copy Markdown
Collaborator Author

@codex

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6fd0ebb979

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +115 to +117
// remove before commit
const adaptiveThinkingOverride = this.options.adaptiveThinkingOverride?.();
const effectiveAdaptiveThinking = adaptiveThinkingOverride ?? alias.adaptiveThinking;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 Badge Remove the leftover adaptive-thinking override hook

When a ProviderManager is constructed with this new option, it replaces alias.adaptiveThinking for every resolved model, so a test/debug hook left enabled in any runtime path silently ignores the per-model config this code is trying to thread through. The inline remove before commit marker suggests this was not intended; please drop the option and pass alias.adaptiveThinking directly.

Useful? React with 👍 / 👎.

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