Skip to content

fix(proxy): handle 404 with model-not-found guidance#1748

Open
kilo-code-bot[bot] wants to merge 6 commits intomainfrom
fix/byok-404-model-not-found
Open

fix(proxy): handle 404 with model-not-found guidance#1748
kilo-code-bot[bot] wants to merge 6 commits intomainfrom
fix/byok-404-model-not-found

Conversation

@kilo-code-bot
Copy link
Copy Markdown
Contributor

@kilo-code-bot kilo-code-bot bot commented Mar 30, 2026

Summary

When an upstream provider returns a 404 for a BYOK request, users previously received an opaque error. This change adds a dedicated handler in makeErrorReadable that tells the user the model does not exist or is no longer available, and recommends switching to kilo-auto/balanced. For KiloClaw/OpenClaw users, the message includes explicit /model switch instructions.

Changes:

  • Added feature parameter to makeErrorReadable to detect kiloclaw/openclaw clients
  • Added 404 handling inside the BYOK block in makeErrorReadable (src/lib/llm-proxy-helpers.ts)
  • Updated the call site in src/app/api/openrouter/[...path]/route.ts to pass feature

Verification

  • Reviewed existing BYOK error handling patterns and followed the same style
  • Confirmed FeatureValue and KILO_AUTO_BALANCED_MODEL are already imported
  • Typecheck could not run in CI-less environment (missing node_modules), but types are consistent with existing patterns

Visual Changes

N/A

Reviewer Notes

  • The 404 handler is placed after the existing byokErrorMessages lookup (401/402/403/429), so it only fires when no other BYOK-specific message matches first.
  • The kiloclaw/openclaw branch mirrors the pattern used in forbiddenFreeModelResponse for consistency.

After user BYOK error handling, return a helpful message when the
upstream provider responds with 404, indicating the model does not
exist or is no longer available. Recommends switching to
kilo-auto/balanced, with explicit /model instructions for
kiloclaw/openclaw users.
The 404 handler should apply to all users, not just BYOK users.
@kilo-code-bot
Copy link
Copy Markdown
Contributor Author

kilo-code-bot bot commented Mar 30, 2026

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
src/lib/llm-proxy-helpers.ts 172 The new 404 fallback chooses kilo-auto/free when balance <= 0, but BYOK requests do not depend on Kilo credits and should not change guidance based on local balance.

Fix these issues in Kilo Cloud

Other Observations (not in diff)

N/A

Files Reviewed (1 file)
  • src/lib/llm-proxy-helpers.ts - 1 issue

Reviewed by gpt-5.4-20260305 · 380,617 tokens

@chrarnoldus chrarnoldus changed the title fix(proxy): handle BYOK 404 with model-not-found guidance fix(proxy): handle 404 with model-not-found guidance Mar 30, 2026
When the user has no credits, recommend kilo-auto/free instead of
kilo-auto/balanced in the 404 model-not-found message.
kilo-code-bot bot added 2 commits March 30, 2026 21:01
BYOK users get a plain message pointing them to check the model name
and their API provider, while non-BYOK users still get the auto model
recommendation.
}

if (response.status === 404) {
const recommendedModel = balance <= 0 ? KILO_AUTO_FREE_MODEL : KILO_AUTO_BALANCED_MODEL;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

WARNING: BYOK fallback depends on the user's Kilo balance

BYOK requests can still reach this branch, but balance is the user's Kilo credit balance, not the upstream provider balance behind their API key. Accounts with zero Kilo credits will now be told to switch to kilo-auto/free, which contradicts the new BYOK guidance and makes the recommendation depend on unrelated state.

Suggested change
const recommendedModel = balance <= 0 ? KILO_AUTO_FREE_MODEL : KILO_AUTO_BALANCED_MODEL;
const recommendedModel = isUserByok || balance > 0 ? KILO_AUTO_BALANCED_MODEL : KILO_AUTO_FREE_MODEL;

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