Filter
NAME
OpenRouter::API::Filter - Client-side predicates for model filtering
SYNOPSIS
use OpenRouter::API::Filter;
# Usually reached via Client.search-models, but the predicate is
# exposed directly so callers can build richer queries.
my @matches = $models.grep({
OpenRouter::API::Filter::matches(
$_,
:keyword<claude>,
:supports-tool-use,
:min-context-length(200_000),
)
});
DESCRIPTION
Pure-Raku predicates over OpenRouter::API::Result::Model. Every
parameter is optional and conjunctive ā omit a parameter to leave
that dimension unfiltered. OpenRouter itself has no server-side
keyword search on /models; this module provides the equivalent
client-side.
Population is stubbed here for now; the full predicate lands with
Client.search-models (task 20).
:$keywordā case-insensitive substring match against the model'sid,name, anddescription. A single keyword today; splitting on whitespace + requiring all tokens to hit can come later without breaking callers.:$authorā exact match on theauthor/prefix of the model id. E.g.:author<anthropic>matches everyanthropic/*model.:$max-input-cost/:$max-output-costā USD per token at the catalogue-level advertised price. A model with either price undefined (rare, but happens for free / preview models) counts as matching when the limit is zero and excluded otherwise, since "unknown price" is safer to omit than to silently include when the caller set a ceiling.:$min-context-lengthācontext-length= N>.:$supports-*ā strict Boolean compare against the derived capability check.:supports-tool-use(True)keeps only models that pass;:supports-tool-use(False)keeps only models that don't. Omit to ignore the dimension. ) our sub matches( OpenRouter::API::Result::Model:D $model, Str :$keyword, Str :$author, Rat :$max-input-cost, Rat :$max-output-cost, Int :$min-context-length, Bool :$supports-tool-use, Bool :$supports-vision, Bool :$supports-reasoning, Bool :$supports-structured-outputs, --> Bool:D ) is export { if $keyword.defined && $keyword.chars { my $needle = $keyword.lc; my $haystack = ($model.id // '').lc ~ ' ' ~ ($model.name // '').lc ~ ' ' ~ ($model.description // '').lc; return False unless $haystack.contains($needle); }