Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/app/api/openrouter/[...path]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,8 @@ export async function POST(request: NextRequest): Promise<NextResponseType<unkno
request: requestBodyParsed,
response,
isUserByok: !!userByok,
feature,
balance: (await balanceAndSettingsPromise).balance,
});
if (errorResponse) {
return errorResponse;
Expand Down
14 changes: 14 additions & 0 deletions src/lib/llm-proxy-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,15 @@ export async function makeErrorReadable({
request,
response,
isUserByok,
feature,
balance,
}: {
requestedModel: string;
request: GatewayRequest;
response: Response;
isUserByok: boolean;
feature: FeatureValue | null;
balance: number;
}) {
if (response.status < 400) {
return undefined;
Expand All @@ -163,6 +167,16 @@ export async function makeErrorReadable({
}
}

if (response.status === 404) {
const recommendedModel = balance <= 0 ? KILO_AUTO_FREE_MODEL : KILO_AUTO_BALANCED_MODEL;
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 ${recommendedModel.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
// (such as "Internal Server Error" or "No allowed providers are available for the selected model")
const model = kiloFreeModels.find(m => m.public_id === requestedModel);
Expand Down
Loading