Skip to content

applyFilter

find() and recommend() both accept filters in their options. applyFilter() exposes the same filtering logic as a standalone function, useful when you want to filter a model array outside of those pipelines.

function applyFilter<T extends Model>(
models: T[],
filter?: ModelFilter | ((model: Model) => boolean),
): T[]
ParameterTypeDescription
modelsT[]The model array to filter.
filterModelFilter | functionDeclarative filter object or predicate function.

T[]: a new array containing only models that pass the filter. Does not mutate the input. When filter is undefined, returns the input array unchanged.

Deprecated models are excluded by default (excludeDeprecated defaults to true in ModelFilter).

import { fromModelsDev, applyFilter } from "pickai";
const models = await fromModelsDev();
const reasoning = applyFilter(models, { reasoning: true });
const cheap = applyFilter(models, (m) => (m.cost?.input ?? Infinity) < 1);

See Filtering for the full guide on declarative filters and predicates.