Repository navigation
feat(gateway): add per-request Kilo headers, body sanitization, and error contract - #15067
Merged
Merged
Conversation
Contributor
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Reviewed the Gateway PR 3 changes: per-request attribution headers, request body/auth sanitization, the Gateway error contract, and SSE routing metadata. All 11 files are Kilo-owned paths; no shared upstream files changed. Notable checks performed:
Files Reviewed (11 files)
Reviewed by deepseek-v4.1-flash · Input: 93.9K · Output: 30.1K · Cached: 1.5M |
chrarnoldus
approved these changes
Oct 15, 2026
WebReflection
approved these changes
Oct 15, 2026
This was referenced Oct 16, 2026
This was referenced Oct 17, 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.
Stacked on #15065.
Part of #14991 (and #13750), PR 3 of the Gateway series. Plan units
U-E1-03(error contract) andU-E1-04(request attribution, body sanitization, and routed model metadata).What Problem This Solves
In PR 2 (#15065), Kilo Gateway requests still lacked per-request attribution headers (
X-KILOCODE-TASKID,X-KILOCODE-PARENT-TASKID,X-KILOCODE-PROJECTID,X-KILOCODE-MACHINEID,x-kilocode-mode,X-KILOCODE-TESTER,User-Agent), request body sanitization (credential metadata stripping, stateless/responsesitem_reference/idstripping,provider.data_collection, and Anthropic/messagesx-api-key->Bearerpromotion),routedModelIDandx-vercel-idextraction from SSE streams, and structured handling of the Gateway error contract (PAID_MODEL_AUTH_REQUIRED,PROMOTION_MODEL_LIMIT_REACHED, 402usage_limit_exceededwith balance andbuyCreditsUrl,top_up_in_progress,model_not_allowed,provider_not_allowed,data_collection_required,upgrade_required).Why This Change Was Made
Following the architecture in #14991 and #15060:
packages/kilo-gateway-core(src/headers.ts,src/project.ts,src/machine.ts):KiloHeaders.request: buildsUser-Agent: opencode-kilo-provider/<version>,X-KILOCODE-TASKID,X-KILOCODE-PARENT-TASKID,X-KILOCODE-PROJECTID,X-KILOCODE-MACHINEID,x-kilocode-mode(lowercased), andX-KILOCODE-TESTER: SUPPRESS(when configured), alongside the provider headers.KiloProject: resolves project ID from.kilo/config.json,.kilocode/config.json, orgit config --get remote.origin.url, normalized to the repository name and truncated to 100 chars (ported from v1project-id.ts).KiloMachine: resolvesKILO_MACHINE_IDor persiststelemetry-idin the data directory (ported from v1identity.ts).src/requests.ts):x-api-keytoAuthorization: Bearer <key>on Gateway requests (fixing Anthropic/messageskey auth).server,organizationID,email, etc.) from top-level JSON request bodies while preserving the originalRequestoptions andAbortSignal.item_referenceitems and itemidfields on stateless/responsesrequests (store !== true), and injectsprovider.data_collectionwhen configured (ported from v1responses.ts).src/errors.ts,src/stream.ts):{ error: { code, message, title, balance, buyCreditsUrl }, error_type }and{ error, error_type, message }) plus mid-stream SSE error frames (response.failed, envelope-less{ error }, bare{ code, message }).PAID_MODEL_AUTH_REQUIRED,PROMOTION_MODEL_LIMIT_REACHED, 402usage_limit_exceeded(with current balance andbuyCreditsUrl),top_up_in_progress(retryable),model_not_allowed,provider_not_allowed,data_collection_required, andupgrade_required.routedModelID(fromprovider_metadata.gateway.routing.modelAttempts,routing.canonicalSlug, or responsemodel) andx-vercel-idon 200 SSE streams, stampsroutedModelIDonto SSEusage, and exposes{ routedModelID, vercelID }viakilocode.gatewaysession.metadataRPC.Shared upstream files changed
None in this PR (all changes are in Kilo-owned paths
packages/kilo-gateway-core/**andpackages/core/**/kilocode/**).User Impact
X-KILOCODE-TASKID,X-KILOCODE-PARENT-TASKID,X-KILOCODE-PROJECTID,X-KILOCODE-MACHINEID,x-kilocode-mode,User-Agent) so the Gateway backend attributes usage, rate limits, and billing accurately.kilo-auto/*) record the backend-selectedroutedModelIDandx-vercel-id.Evidence
Automated checks
bun script/check-opencode-annotations.ts:ok (39 shared files against 4d9678a79d6)bun script/check-shared-patches.ts:ok(0 new shared upstream files touched)bun run --cwd packages/kilo-gateway-core typecheck && bun run --cwd packages/kilo-gateway-core build: passbun run --cwd packages/core typecheck: passbun run --cwd packages/tui typecheck: passbun test --cwd packages/kilo-gateway-core: 33 pass, 0 fail (107 assertions)bun test --cwd packages/core test/kilocode/gateway.test.ts test/plugin/provider-kilo.test.ts: 13 pass, 0 fail (60 assertions)CLI & TUI Self-Test
/api/gateway/chat/completions:http-referer: https://kilocode.ai,x-title: Kilo Code,user-agent: opencode-kilo-provider/...,x-kilocode-editorname,x-kilocode-feature,x-kilocode-machineid,x-kilocode-mode,x-kilocode-projectid: kilocode,x-kilocode-taskid: ses_....usage_limit_exceededand 401PAID_MODEL_AUTH_REQUIRED):