Skip to content

feat(provider): add custom body overrides#1789

Open
ayu-exorcist wants to merge 1 commit into
MoonshotAI:mainfrom
ayu-exorcist:feat/custom-body
Open

feat(provider): add custom body overrides#1789
ayu-exorcist wants to merge 1 commit into
MoonshotAI:mainfrom
ayu-exorcist:feat/custom-body

Conversation

@ayu-exorcist

@ayu-exorcist ayu-exorcist commented Jul 16, 2026

Copy link
Copy Markdown

Related issue

Related to #1674. This PR delivers the provider-scoped part of that request; model-scoped overrides remain a follow-up design decision.

Problem / 背景

English

Provider APIs and compatible gateways expose request fields that Kimi Code does not generate itself. For example, OpenAI Priority processing uses service_tier: "priority". Without a supported configuration surface, users need a reverse proxy or a local source patch to use those capabilities.

中文

供应商 API 与兼容网关提供了 Kimi Code 不会自行生成的请求字段。例如,OpenAI Priority 处理需要 service_tier: "priority"。缺少受支持的配置入口时,用户只能借助反向代理或修改本地源码来使用这些能力。

What changed / 改动内容

English

  • Add the provider-level custom_body TOML field alongside custom_headers.
  • Validate it as a recursive JSON object, preserve nested values through TOML and configuration PATCH round-trips, and keep user-native keys such as service_tier and cache_control unchanged.
  • Apply the patch immediately before transport dispatch for Kimi, Anthropic, OpenAI Chat Completions, OpenAI Responses, Google GenAI, and Vertex AI. Object values merge recursively; arrays and scalar values replace generated values, including false, 0, empty strings, and SDK/RPC null.
  • Treat a boolean custom_body.stream as a transport-control override. It selects matching request serialization and response decoding for the OpenAI-compatible and Anthropic providers; for Google GenAI and Vertex AI, it selects generateContent or generateContentStream and is not forwarded to the SDK request object.
  • Reject __proto__, prototype, and constructor at every nesting level, and use safe own-property writes while merging to prevent prototype pollution.
  • Add the klient provider contract and conformance coverage so customBody round-trips through supported client transports.
  • Update English and Chinese configuration documentation.

中文

  • 新增 Provider 级 custom_body TOML 字段,并与 custom_headers 配套使用。
  • 将其校验为递归 JSON 对象,在 TOML 与配置 PATCH 往返中保留嵌套值,并保持 service_tiercache_control 等供应商原生键不变。
  • 在 Kimi、Anthropic、OpenAI Chat Completions、OpenAI Responses、Google GenAI 和 Vertex AI 的传输请求发出前应用补丁。对象递归合并;数组和标量值覆盖生成值,包含 false0、空字符串以及 SDK/RPC 中的 null
  • 将布尔值 custom_body.stream 视为传输控制覆盖。它会让 OpenAI 兼容供应商与 Anthropic 选择匹配的请求序列化和响应解码;对 Google GenAI 与 Vertex AI,则选择 generateContentgenerateContentStream,且不会透传到 SDK 请求对象。
  • 在所有嵌套层级拒绝 __proto__prototypeconstructor,并在合并时安全写入自有属性,防止原型污染。
  • 新增 klient provider contract 与 conformance 覆盖,使 customBody 可以在受支持的客户端传输中往返。
  • 更新中英文配置文档。

Scope / 范围

English

This implementation intentionally uses provider scope: fields apply to every request sent through the configured provider. It does not add model-level custom_body configuration. That work needs an explicit precedence model between provider defaults, model overrides, and generated request fields, and remains tracked by #1674.

中文

本实现有意采用 Provider 级范围:字段会作用于该 Provider 发出的所有请求。它不新增模型级 custom_body 配置。模型级能力需要先明确 Provider 默认值、模型覆盖和生成请求字段之间的优先级,因此仍由 #1674 跟踪。

Validation / 验证

  • pnpm exec vitest run …: 120 focused tests passed after rebasing onto the latest upstream/main.
  • @moonshot-ai/kosong, @moonshot-ai/agent-core-v2, and @moonshot-ai/klient typecheck passed.
  • @moonshot-ai/agent-core-v2 lint:domain, documentation build, and git diff --check passed.
  • The shared klient conformance addition passes locally for memory and HTTP. IPC conformance still needs a Unix-socket-enabled runner because the local Windows environment rejects socket binding.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue.
  • I have added tests that prove the feature works.
  • I added a minor changeset for @moonshot-ai/kimi-code.
  • I updated the English and Chinese user-facing configuration documentation.

@changeset-bot

changeset-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 393972d

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 Minor

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

@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: 356aadf4b5

ℹ️ 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 thread packages/kosong/src/providers/kimi.ts
Comment thread packages/agent-core-v2/src/app/provider/provider.ts
Comment thread packages/agent-core/src/config/schema.ts
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