From 45670ac7e959826eb99d53c19809c65195a14821 Mon Sep 17 00:00:00 2001 From: "kiloconnect[bot]" <240665456+kiloconnect[bot]@users.noreply.github.com> Date: Mon, 30 Mar 2026 20:24:45 +0000 Subject: [PATCH 1/7] fix(proxy): handle BYOK 404 with model-not-found guidance 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. --- src/app/api/openrouter/[...path]/route.ts | 1 + src/lib/llm-proxy-helpers.ts | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/app/api/openrouter/[...path]/route.ts b/src/app/api/openrouter/[...path]/route.ts index 1994fbb1d..e370aa6ed 100644 --- a/src/app/api/openrouter/[...path]/route.ts +++ b/src/app/api/openrouter/[...path]/route.ts @@ -592,6 +592,7 @@ export async function POST(request: NextRequest): Promise Date: Mon, 30 Mar 2026 20:27:39 +0000 Subject: [PATCH 2/7] fix: move 404 model-not-found handler outside BYOK block The 404 handler should apply to all users, not just BYOK users. --- src/lib/llm-proxy-helpers.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/lib/llm-proxy-helpers.ts b/src/lib/llm-proxy-helpers.ts index 81e74c1af..42fcf4b15 100644 --- a/src/lib/llm-proxy-helpers.ts +++ b/src/lib/llm-proxy-helpers.ts @@ -164,14 +164,15 @@ export async function makeErrorReadable({ ); } - if (response.status === 404) { - const recommendation = - feature === 'kiloclaw' || feature === 'openclaw' - ? `[BYOK] The model "${requestedModel}" does not exist or is no longer available. We recommend switching to kilo-auto/balanced: /model kilocode/${KILO_AUTO_BALANCED_MODEL.id}` - : `[BYOK] The model "${requestedModel}" does not exist or is no longer available. We recommend switching to kilocode/${KILO_AUTO_BALANCED_MODEL.id}.`; - warnExceptInTest(`Responding with 404 ${recommendation}`); - return NextResponse.json({ error: recommendation, message: recommendation }, { status: 404 }); - } + } + + if (response.status === 404) { + const recommendation = + feature === 'kiloclaw' || feature === 'openclaw' + ? `The model "${requestedModel}" does not exist or is no longer available. We recommend switching to kilo-auto/balanced: /model kilocode/${KILO_AUTO_BALANCED_MODEL.id}` + : `The model "${requestedModel}" does not exist or is no longer available. We recommend switching to kilocode/${KILO_AUTO_BALANCED_MODEL.id}.`; + warnExceptInTest(`Responding with 404 ${recommendation}`); + return NextResponse.json({ error: recommendation, message: recommendation }, { status: 404 }); } // Sometimes we get generic or nonsensical errors when the context length is exceeded From 387addc77d32f369a15a1a049cb6dc1bedeb578c Mon Sep 17 00:00:00 2001 From: "kiloconnect[bot]" <240665456+kiloconnect[bot]@users.noreply.github.com> Date: Mon, 30 Mar 2026 20:56:51 +0000 Subject: [PATCH 3/7] fix: recommend kilo-auto/free when user balance is zero When the user has no credits, recommend kilo-auto/free instead of kilo-auto/balanced in the 404 model-not-found message. --- src/app/api/openrouter/[...path]/route.ts | 1 + src/lib/llm-proxy-helpers.ts | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/app/api/openrouter/[...path]/route.ts b/src/app/api/openrouter/[...path]/route.ts index e370aa6ed..7f17008e2 100644 --- a/src/app/api/openrouter/[...path]/route.ts +++ b/src/app/api/openrouter/[...path]/route.ts @@ -593,6 +593,7 @@ export async function POST(request: NextRequest): Promise Date: Mon, 30 Mar 2026 21:01:20 +0000 Subject: [PATCH 4/7] fix: add BYOK-specific 404 message without auto model recommendation 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. --- src/lib/llm-proxy-helpers.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/llm-proxy-helpers.ts b/src/lib/llm-proxy-helpers.ts index 5c38f7d12..46ac34066 100644 --- a/src/lib/llm-proxy-helpers.ts +++ b/src/lib/llm-proxy-helpers.ts @@ -126,6 +126,7 @@ const byokErrorMessages: Record = { 401: '[BYOK] Your API key is invalid or has been revoked. Please check your API key configuration.', 402: '[BYOK] Your API account has insufficient funds. Please check your billing details with your API provider.', 403: '[BYOK] Your API key does not have permission to access this resource. Please check your API key permissions.', + 404: '[BYOK] The requested model does not exist or is no longer available. Please check the model name and your API provider.', 429: '[BYOK] Your API key has hit its rate limit. Please try again later or check your rate limit settings with your API provider.', }; From 4ec62e96868c79a2e552939b0a244f9a925f56d6 Mon Sep 17 00:00:00 2001 From: "kiloconnect[bot]" <240665456+kiloconnect[bot]@users.noreply.github.com> Date: Mon, 30 Mar 2026 21:02:10 +0000 Subject: [PATCH 5/7] fix: drop kilocode/ prefix from non-claw 404 recommendation --- src/lib/llm-proxy-helpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/llm-proxy-helpers.ts b/src/lib/llm-proxy-helpers.ts index 46ac34066..7a04c7b5c 100644 --- a/src/lib/llm-proxy-helpers.ts +++ b/src/lib/llm-proxy-helpers.ts @@ -174,7 +174,7 @@ export async function makeErrorReadable({ const recommendation = feature === 'kiloclaw' || feature === 'openclaw' ? `The model "${requestedModel}" does not exist or is no longer available. We recommend switching to ${recommendedModel.name}: /model kilocode/${recommendedModel.id}` - : `The model "${requestedModel}" does not exist or is no longer available. We recommend switching to kilocode/${recommendedModel.id}.`; + : `The model "${requestedModel}" does not exist or is no longer available. We recommend switching to ${recommendedModel.id}.`; warnExceptInTest(`Responding with 404 ${recommendation}`); return NextResponse.json({ error: recommendation, message: recommendation }, { status: 404 }); } From 3447f7e39b00ca8f95148d7ca6315e5af5003142 Mon Sep 17 00:00:00 2001 From: "kiloconnect[bot]" <240665456+kiloconnect[bot]@users.noreply.github.com> Date: Mon, 30 Mar 2026 21:05:33 +0000 Subject: [PATCH 6/7] fix: remove BYOK 404 entry from byokErrorMessages --- src/lib/llm-proxy-helpers.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib/llm-proxy-helpers.ts b/src/lib/llm-proxy-helpers.ts index 7a04c7b5c..a3abbb559 100644 --- a/src/lib/llm-proxy-helpers.ts +++ b/src/lib/llm-proxy-helpers.ts @@ -126,7 +126,6 @@ const byokErrorMessages: Record = { 401: '[BYOK] Your API key is invalid or has been revoked. Please check your API key configuration.', 402: '[BYOK] Your API account has insufficient funds. Please check your billing details with your API provider.', 403: '[BYOK] Your API key does not have permission to access this resource. Please check your API key permissions.', - 404: '[BYOK] The requested model does not exist or is no longer available. Please check the model name and your API provider.', 429: '[BYOK] Your API key has hit its rate limit. Please try again later or check your rate limit settings with your API provider.', }; From 3fee8312b67a84c8ab141102f4bbba782904a212 Mon Sep 17 00:00:00 2001 From: Christiaan Arnoldus Date: Tue, 31 Mar 2026 09:50:07 +0200 Subject: [PATCH 7/7] Format --- src/lib/llm-proxy-helpers.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib/llm-proxy-helpers.ts b/src/lib/llm-proxy-helpers.ts index a3abbb559..407cc041b 100644 --- a/src/lib/llm-proxy-helpers.ts +++ b/src/lib/llm-proxy-helpers.ts @@ -165,7 +165,6 @@ export async function makeErrorReadable({ { status: response.status } ); } - } if (response.status === 404) {