Skip to content

fix(ai-gateway): never forward custom LLM upstream errors to users - #7777

Closed
chrarnoldus wants to merge 1 commit into
mainfrom
kilo/redact-custom-llm-errors
Closed

chrarnoldus wants to merge 1 commit into
mainfrom
kilo/redact-custom-llm-errors

Conversation

@chrarnoldus

Copy link
Copy Markdown
Contributor

Summary

A custom LLM upstream is private infrastructure. Until now its error bodies reached the user unchanged, which can expose internal URLs, model names, or account details. This PR stops forwarding them:

  • HTTP errors: makeErrorReadable now answers every non-2xx custom LLM response with the generic upstream_error used for stealth models. A context overflow is still reported so clients can compact, but with a Kilo-authored message instead of the upstream body.
  • Stream errors: rewriteModelResponse replaces error details in stream events with the same generic message: chat completions error, Messages error events, and Responses error / response.failed. This applies whenever shouldRedactErrorResponse is true, which is now custom LLMs plus stealth models.
  • Upstream detail is still kept internally: the unrewritten response is still logged, so operators keep the upstream detail.

This is a prep PR for #7291, where custom LLMs can become public.

Verification

  • No manual testing; covered by unit tests for HTTP errors, context overflow, and each stream API kind.

Visual Changes

N/A

Reviewer Notes

Stealth models already had HTTP errors redacted. Their stream error events are now redacted too, for consistency.

@chrarnoldus chrarnoldus self-assigned this Oct 16, 2026
@kilo-code-bot

kilo-code-bot Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

Reviewed the custom-LLM/stealth stream-error redaction across the AI-gateway helpers and response rewriters; the redaction correctly targets the real HTTP and stream error shapes, no defects found in the changed code.

Files Reviewed (6 files)

  • packages/web-shared/src/lib/ai-gateway/kilo-exclusive-models.ts
  • packages/web-shared/src/lib/ai-gateway/llm-proxy-helpers.ts
  • packages/web-shared/src/lib/ai-gateway/llm-proxy-helpers.test.ts
  • packages/web-shared/src/lib/ai-gateway/models.test.ts
  • packages/web-shared/src/lib/ai-gateway/rewriteModelResponse.ts
  • packages/web-shared/src/lib/ai-gateway/rewriteModelResponse.test.ts

Detail

  • shouldRedactErrorResponse now returns true for provider === 'custom', matching shouldRedactModelNameInMicrodollarUsage; the early providerId === 'custom' branch in makeErrorReadable still routes context overflow through detectContextOverflow and builds a Kilo-authored context_length_exceeded body, and otherwise returns the generic upstream_error. Status is preserved and the upstream detail remains available to internal logging, so no operator signal is lost.
  • Stream redaction in rewriteModelResponse_ChatCompletions (frame error), rewriteModelResponse_Messages (type === 'error'), and rewriteModelResponse_Responses (type: 'error' plus response.failed via response.error) matches the shapes the gateway actually receives (ResponseErrorEvent carries flat code/message/param; ResponseFailedEvent carries response.error). The event.response?.error guard is safe because successful responses send error: null.
  • Tests cover the changed behavior for HTTP errors, context overflow, and each stream API kind, and the pre-existing providerId: 'custom' tests operate on 2xx bodies or logUnrewrittenResponse, so they are unaffected.

Reviewed by deepseek-v4.1-flash · Input: 141.3K · Output: 33.5K · Cached: 2.2M

Review guidance: REVIEW.md from base branch main

@chrarnoldus

Copy link
Copy Markdown
Contributor Author

We don't want this.

@chrarnoldus
chrarnoldus deleted the kilo/redact-custom-llm-errors branch October 19, 2026 12:13
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