Skip to content

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

Merged
sailist merged 4 commits into
mainfrom
feat/anthropic
Jun 29, 2026
Merged

feat(managed-kimi-code): route anthropic protocol via beta api#1186
sailist merged 4 commits into
mainfrom
feat/anthropic

Conversation

@RealKai42

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue. Opened from the in-repo feat/anthropic branch (supersedes the fork-based #1182).

Problem

Managed Kimi Code models that declare the Anthropic-compatible protocol must be served through the Anthropic beta Messages API. Operators also need a way to inject custom outbound LLM headers, and to attribute turn and error telemetry by provider wire protocol so issues on this path can be isolated after rollout.

What changed

  • Route managed Kimi Code models on the Anthropic-compatible protocol through the beta Messages API (client.beta.messages.create); beta features are sent via the request betas field instead of the anthropic-beta header to avoid duplication. Thinking-capable Anthropic models are opted into adaptive thinking.
  • Add KIMI_CODE_CUSTOM_HEADERS (newline-separated Name: Value lines) for custom outbound LLM request headers, send the CLI User-Agent to non-Kimi providers, forward Kimi identity headers to model catalog fetches, and support defaultHeaders in the Google GenAI provider.
  • Add type/protocol (and alias) to api_error and turn_interrupted, and introduce a turn_ended telemetry event, so turn volume, completion rate, and errors can be segmented by provider wire protocol.

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.

Note: the new KIMI_CODE_CUSTOM_HEADERS env var may need a user-facing docs update.

sailist and others added 3 commits June 29, 2026 05:10
- 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
- Add KIMI_CODE_CUSTOM_HEADERS env var for custom outbound LLM headers
- Send User-Agent to non-Kimi providers
- Forward Kimi identity headers to model catalog fetches
- Support defaultHeaders in Google GenAI provider
- Add type/protocol/alias to api_error for per-protocol error attribution

- Add turn_ended event with reason/duration/mode/type/protocol

- Add type/protocol to turn_interrupted
@changeset-bot

changeset-bot Bot commented Jun 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 103d600

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 29, 2026

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

commit: 103d600

@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: 461b0c4e96

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/oauth/src/managed-kimi-code.ts Outdated
@sailist sailist merged commit 821847c into main Jun 29, 2026
8 of 9 checks passed
@sailist sailist deleted the feat/anthropic branch June 29, 2026 06:24
@github-actions github-actions Bot mentioned this pull request Jun 29, 2026
liruifengv added a commit that referenced this pull request Jun 29, 2026
Resolve conflicts with main's #1186 (managed-kimi-code anthropic beta-api routing):

- packages/oauth/src/managed-kimi-code.ts: keep this branch's selective-merge model refresh and effort fields, layer in main's betaApi/adaptiveThinking. Both are assigned directly (cleared when the server stops declaring anthropic) so they never go stale across refreshes, mirroring how protocol is handled.
- packages/oauth/src/open-platform.ts: keep both imports (parseThinkEfforts for effort parsing, parseKimiCodeCustomHeaders for request headers).
- packages/agent-core/src/session/provider-manager.ts: pass through both betaApi (anthropic) and supportEfforts (kimi); use main's effectiveAdaptiveThinking and envCustomHeaders.
- packages/agent-core/src/config/schema.ts: keep both ModelAlias fields (supportEfforts/defaultEffort and betaApi).
Moixia pushed a commit to Moixia/idea that referenced this pull request Jun 29, 2026
…hotAI#1186)

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

- 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

* feat(providers): add KIMI_CODE_CUSTOM_HEADERS support

- Add KIMI_CODE_CUSTOM_HEADERS env var for custom outbound LLM headers
- Send User-Agent to non-Kimi providers
- Forward Kimi identity headers to model catalog fetches
- Support defaultHeaders in Google GenAI provider

* feat(agent-core): add protocol attrs to turn and api error telemetry

- Add type/protocol/alias to api_error for per-protocol error attribution

- Add turn_ended event with reason/duration/mode/type/protocol

- Add type/protocol to turn_interrupted

* chore(oauth): remove hardcoded internal dev endpoint from shared OAuth base URLs

---------

Co-authored-by: haozhe.yang <yanghaozhe@moonshot.ai>
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.

2 participants