Skip to content

feat: add custom_headers for providers + built-in Kimi Coding provider#2576

Merged
tusharmath merged 4 commits intotailcallhq:mainfrom
david-strejc:feat/custom-headers-and-kimi-provider
Mar 16, 2026
Merged

feat: add custom_headers for providers + built-in Kimi Coding provider#2576
tusharmath merged 4 commits intotailcallhq:mainfrom
david-strejc:feat/custom-headers-and-kimi-provider

Conversation

@david-strejc
Copy link
Copy Markdown
Contributor

Summary

  • Adds a custom_headers field to ProviderConfig (in provider.json) and Provider<T> struct, allowing providers to specify custom HTTP headers that are included in all API requests
  • Custom headers are appended in the OpenAI backend's get_headers() and respected by the HTTP layer — User-Agent is no longer forcefully overwritten if the provider already sets it
  • Adds a new built-in kimi_coding provider for Moonshot's Kimi Coding API (Kimi K2.5), which requires a whitelisted User-Agent header to accept requests

Motivation

Some API providers (notably Kimi Coding) whitelist requests by User-Agent header, only accepting known coding agents. Previously, Forge hardcoded User-Agent: Forge on all requests with no way to override it. This made it impossible to use providers that enforce User-Agent checks.

The custom_headers field in provider.json is the minimal, configurable solution — any provider definition can now ship arbitrary headers without code changes.

Usage

export KIMI_API_KEY=sk-kimi-...
forge config set provider kimi_coding
forge config set model kimi-for-coding

Test plan

  • Verified cargo check and cargo test --no-run compile cleanly
  • Tested Kimi Coding API responds successfully through Forge with the new provider (forge -p "Say hello" returns a valid response)
  • Verified existing providers are unaffected (custom_headers defaults to None)
  • Maintainers: verify CI passes

🤖 Generated with Claude Code

…ng provider

Add a `custom_headers` field to `ProviderConfig` and `Provider<T>` that allows
providers to specify custom HTTP headers for API requests. Headers from
`custom_headers` are appended in the OpenAI backend's `get_headers()` method
and respected by the HTTP layer (User-Agent is no longer overwritten if
already set by the provider).

This enables providers that require specific headers (e.g. User-Agent
whitelisting) to work out of the box. As a first use case, adds a built-in
`kimi_coding` provider for Moonshot's Kimi Coding API, which requires a
`User-Agent: KimiCLI/1.0.0` header.

Usage:
  export KIMI_API_KEY=sk-kimi-...
  forge config set provider kimi_coding
  forge config set model kimi-for-coding

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 16, 2026

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions Bot added the type: feature Brand new functionality, features, pages, workflows, endpoints, etc. label Mar 16, 2026
for (k, v) in custom_headers {
headers.push((k.clone(), v.clone()));
}
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can u add some unit tests for this change.

@tusharmath
Copy link
Copy Markdown
Collaborator

Thanks @david-strejc PR looks good to me, minor comment.

@tusharmath
Copy link
Copy Markdown
Collaborator

Did u try using this build to see if it solves the problem?

Adds two tests:
- test_get_headers_includes_custom_headers: verifies custom headers from
  provider config are appended to the request headers
- test_get_headers_no_custom_headers: verifies no extra headers when
  custom_headers is None

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@david-strejc
Copy link
Copy Markdown
Contributor Author

Added unit tests for the custom_headers change in get_headers():

  • test_get_headers_includes_custom_headers — verifies custom headers from provider config are appended to request headers
  • test_get_headers_no_custom_headers — verifies no extra headers when custom_headers is None

Both pass. And yes, tested the build end-to-end with Kimi Coding API — confirmed working.

@tusharmath tusharmath enabled auto-merge (squash) March 16, 2026 12:38
@tusharmath tusharmath merged commit fe68905 into tailcallhq:main Mar 16, 2026
9 checks passed
ameno- added a commit to ameno-/forge that referenced this pull request Mar 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: feature Brand new functionality, features, pages, workflows, endpoints, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants