Skip to content

Commit 9d33aa3

Browse files
authored
Improve discontinued free model error message for KiloClaw (#1725)
1 parent 380feb0 commit 9d33aa3

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

src/app/api/openrouter/[...path]/route.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import {
2929
} from '@/lib/models';
3030
import {
3131
accountForMicrodollarUsage,
32-
alphaPeriodEndedResponse,
3332
captureProxyError,
3433
checkOrganizationModelRestrictions,
3534
dataCollectionRequiredResponse,
@@ -378,11 +377,7 @@ export async function POST(request: NextRequest): Promise<NextResponseType<unkno
378377
(!autoModel && isForbiddenFreeModel(originalModelIdLowerCased))
379378
) {
380379
console.warn(`User requested forbidden free model ${originalModelIdLowerCased}; rejecting.`);
381-
if (isRooCodeBasedClient(fraudHeaders)) {
382-
return alphaPeriodEndedResponse();
383-
} else {
384-
return forbiddenFreeModelResponse();
385-
}
380+
return forbiddenFreeModelResponse(fraudHeaders, feature);
386381
}
387382

388383
// Extract properties for usage context

src/lib/llm-proxy-helpers.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ import type {
1818
OpenRouterProviderConfig,
1919
GatewayRequest,
2020
} from '@/lib/providers/openrouter/types';
21-
import { getFraudDetectionHeaders, toMicrodollars } from '@/lib/utils';
21+
import {
22+
type FraudDetectionHeaders,
23+
getFraudDetectionHeaders,
24+
isRooCodeBasedClient,
25+
toMicrodollars,
26+
} from '@/lib/utils';
2227
import { normalizeProjectId } from '@/lib/normalizeProjectId';
2328
import { getXKiloCodeVersionNumber } from '@/lib/userAgent';
2429
import { normalizeModelId } from '@/lib/providers/openrouter';
@@ -111,12 +116,6 @@ export function apiKindNotSupportedResponse(
111116
return NextResponse.json({ error, message: error }, { status: 400 });
112117
}
113118

114-
export function alphaPeriodEndedResponse() {
115-
// https://github.com/Kilo-Org/kilocode/blob/50d6bd482bec6fae7d1c80b14ffb064de3761507/src/shared/kilocode/errorUtils.ts#L13
116-
const error = `The alpha period for this model has ended.`;
117-
return NextResponse.json({ error: error, message: error }, { status: 404 });
118-
}
119-
120119
async function stealthModelError(response: Response) {
121120
const error = 'Stealth model unable to process request';
122121
warnExceptInTest(`Responding with ${response.status} ${error}`);
@@ -193,9 +192,21 @@ export function modelNotAllowedResponse() {
193192
);
194193
}
195194

196-
export function forbiddenFreeModelResponse() {
197-
const error = `The free period of this model ended. Please use ${KILO_AUTO_BALANCED_MODEL.id} for affordable inference or ${KILO_AUTO_FREE_MODEL.id} for limited free inference.`;
198-
return NextResponse.json({ error, message: error }, { status: 404 });
195+
export function forbiddenFreeModelResponse(
196+
header: FraudDetectionHeaders,
197+
feature: FeatureValue | null
198+
) {
199+
if (feature === 'kiloclaw' || feature === 'openclaw') {
200+
const error = `The free period of this model ended. Please use ${KILO_AUTO_FREE_MODEL.name} to continue, switch using: /model kilocode/${KILO_AUTO_FREE_MODEL.id}`;
201+
return NextResponse.json({ error, message: error }, { status: 404 });
202+
} else if (isRooCodeBasedClient(header)) {
203+
// https://github.com/Kilo-Org/kilocode/blob/50d6bd482bec6fae7d1c80b14ffb064de3761507/src/shared/kilocode/errorUtils.ts#L13
204+
const error = `The alpha period for this model has ended.`;
205+
return NextResponse.json({ error: error, message: error }, { status: 404 });
206+
} else {
207+
const error = `The free period of this model ended. Please use ${KILO_AUTO_BALANCED_MODEL.id} for affordable inference or ${KILO_AUTO_FREE_MODEL.id} for limited free inference.`;
208+
return NextResponse.json({ error, message: error }, { status: 404 });
209+
}
199210
}
200211

201212
export function modelDoesNotExistResponse() {

0 commit comments

Comments
 (0)