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: 1 addition & 1 deletion apps/web/src/app/api/fim/completions/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import z from 'zod';
import { captureException, setTag, startInactiveSpan } from '@sentry/nextjs';
import type { MicrodollarUsageContext } from '@/lib/ai-gateway/processUsage.types';
import { validateFeatureHeader, FEATURE_HEADER } from '@/lib/feature-detection';
import { isFreeModel } from '@/lib/ai-gateway/models';
import { isFreeModel } from '@/lib/ai-gateway/is-free-model';
import { sentryRootSpan } from '@/lib/getRootSpan';
import { getUserFromAuth } from '@/lib/user.server';
import {
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/api/openrouter/[...path]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ import { setTag, startInactiveSpan } from '@sentry/nextjs';
import { getUserFromAuth } from '@/lib/user.server';
import { sentryRootSpan } from '@/lib/getRootSpan';
import {
isFreeModel,
isDeadFreeModel,
isExcludedForFeature,
isKiloExclusiveFreeModel,
isKiloStealthModel,
} from '@/lib/ai-gateway/models';
import { isFreeModel } from '@/lib/ai-gateway/is-free-model';
import {
accountForMicrodollarUsage,
captureProxyError,
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/api/openrouter/embeddings/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { debugSaveProxyRequest } from '@/lib/debugUtils';
import { captureException, setTag, startInactiveSpan } from '@sentry/nextjs';
import { getUserFromAuth } from '@/lib/user.server';
import { sentryRootSpan } from '@/lib/getRootSpan';
import { isFreeModel } from '@/lib/ai-gateway/models';
import { isFreeModel } from '@/lib/ai-gateway/is-free-model';
import {
captureProxyError,
checkOrganizationModelRestrictions,
Expand Down
23 changes: 23 additions & 0 deletions apps/web/src/lib/ai-gateway/is-free-model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { KILO_AUTO_FREE_MODEL } from '@/lib/ai-gateway/auto-model';
import { isKiloExclusiveFreeModel, isOpenRouterStealthModel } from '@/lib/ai-gateway/models';

/**
* Returns true if `model` should be treated as free for the requesting user
* this request.
*
* Server-only: future implementations will consult external state (e.g. a
* Redis-backed membership set for partner-funded preview model ids) to
* answer for models that are conditionally free. Lives outside `models.ts`
* so client bundles importing the model-id constants
* (`PRIMARY_DEFAULT_MODEL`, `preferredModels`, …) from `models.ts` don't
* transitively pull in those server-only dependencies.
*/
export async function isFreeModel(model: string): Promise<boolean> {
return (
isKiloExclusiveFreeModel(model) ||
model === KILO_AUTO_FREE_MODEL.id ||
(model ?? '').endsWith(':free') ||
model === 'openrouter/free' ||
isOpenRouterStealthModel(model ?? '')
);
}
3 changes: 2 additions & 1 deletion apps/web/src/lib/ai-gateway/models.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, test, expect } from '@jest/globals';
import { autoFreeModels, isFreeModel, kiloExclusiveModels } from './models';
import { autoFreeModels, kiloExclusiveModels } from './models';
import { isFreeModel } from './is-free-model';
import { getInferenceProvider } from './providers/kilo-exclusive-model';

describe('isFreeModel', () => {
Expand Down
12 changes: 1 addition & 11 deletions apps/web/src/lib/ai-gateway/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,6 @@ export const preferredModels = [
GLM_CURRENT_MODEL_ID,
];

export async function isFreeModel(model: string): Promise<boolean> {
return (
isKiloExclusiveFreeModel(model) ||
model === KILO_AUTO_FREE_MODEL.id ||
(model ?? '').endsWith(':free') ||
model === 'openrouter/free' ||
isOpenRouterStealthModel(model ?? '')
);
}

export function isPdfSupportingModel(model: string): boolean {
return isClaudeModel(model) || isOpenAiModel(model) || isGrok4Model(model);
}
Expand Down Expand Up @@ -97,7 +87,7 @@ export function isKiloStealthModel(model: string): boolean {
return kiloExclusiveModels.some(m => m.public_id === model && m.flags.includes('stealth'));
}

function isOpenRouterStealthModel(model: string): boolean {
export function isOpenRouterStealthModel(model: string): boolean {
return model.startsWith('openrouter/') && (model.endsWith('-alpha') || model.endsWith('-beta'));
}

Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/lib/ai-gateway/processUsage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import { eq, sql } from 'drizzle-orm';
import { sentryRootSpan } from '../getRootSpan';
import { ingestOrganizationTokenUsage } from '@/lib/organizations/organization-usage';
import type { ProviderId } from '@/lib/ai-gateway/providers/types';
import { findKiloExclusiveModel, isFreeModel, isKiloStealthModel } from '@/lib/ai-gateway/models';
import { findKiloExclusiveModel, isKiloStealthModel } from '@/lib/ai-gateway/models';
import { isFreeModel } from '@/lib/ai-gateway/is-free-model';
import { sentryLogger } from '@/lib/utils.server';
import { maybeIssueKiloPassBonusFromUsageThreshold } from '@/lib/kilo-pass/usage-triggered-bonus';
import { getEffectiveKiloPassThreshold } from '@/lib/kilo-pass/threshold';
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/lib/ai-gateway/providers/openrouter/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
isFreeModel,
isPdfSupportingModel,
kiloExclusiveModels,
preferredModels,
} from '@/lib/ai-gateway/models';
import { isFreeModel } from '@/lib/ai-gateway/is-free-model';
import PROVIDERS from '@/lib/ai-gateway/providers/provider-definitions';
import type { OpenRouterModel } from '@/lib/organizations/organization-types';
import {
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/lib/bot/agent-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
formatGitLabRepositoriesForPrompt,
getGitLabRepositoryContext,
} from '@/lib/slack-bot/gitlab-repository-context';
import { isFreeModel } from '@/lib/ai-gateway/models';
import { isFreeModel } from '@/lib/ai-gateway/is-free-model';
import { generateApiToken } from '@/lib/tokens';
import { captureException } from '@sentry/nextjs';
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
Expand Down