feat: add custom_headers for providers + built-in Kimi Coding provider#2576
Merged
tusharmath merged 4 commits intotailcallhq:mainfrom Mar 16, 2026
Merged
Conversation
…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>
tusharmath
reviewed
Mar 16, 2026
| for (k, v) in custom_headers { | ||
| headers.push((k.clone(), v.clone())); | ||
| } | ||
| } |
Collaborator
There was a problem hiding this comment.
can u add some unit tests for this change.
Collaborator
|
Thanks @david-strejc PR looks good to me, minor comment. |
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>
Contributor
Author
|
Added unit tests for the custom_headers change in
Both pass. And yes, tested the build end-to-end with Kimi Coding API — confirmed working. |
ameno-
added a commit
to ameno-/forge
that referenced
this pull request
Mar 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
custom_headersfield toProviderConfig(inprovider.json) andProvider<T>struct, allowing providers to specify custom HTTP headers that are included in all API requestsget_headers()and respected by the HTTP layer —User-Agentis no longer forcefully overwritten if the provider already sets itkimi_codingprovider for Moonshot's Kimi Coding API (Kimi K2.5), which requires a whitelistedUser-Agentheader to accept requestsMotivation
Some API providers (notably Kimi Coding) whitelist requests by
User-Agentheader, only accepting known coding agents. Previously, Forge hardcodedUser-Agent: Forgeon all requests with no way to override it. This made it impossible to use providers that enforce User-Agent checks.The
custom_headersfield inprovider.jsonis the minimal, configurable solution — any provider definition can now ship arbitrary headers without code changes.Usage
Test plan
cargo checkandcargo test --no-runcompile cleanlyforge -p "Say hello"returns a valid response)🤖 Generated with Claude Code