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's id, name, and description. A single keyword today; splitting on whitespace + requiring all tokens to hit can come later without breaking callers.

  • :$author — exact match on the author/ prefix of the model id. E.g. :author<anthropic> matches every anthropic/* 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); }

OpenRouter::API v0.1.1

Raku client for OpenRouter's non-inference REST API

Authors

  • Matt Doughty

License

Artistic-2.0

Dependencies

Cro::HTTP:ver<0.8.11>:auth<zef:cro>JSON::Fast:ver<0.19>:auth<cpan:TIMOTIMO>

Test Dependencies

Provides

  • OpenRouter::API
  • OpenRouter::API::Client
  • OpenRouter::API::Filter
  • OpenRouter::API::Result::ActivityRow
  • OpenRouter::API::Result::Credits
  • OpenRouter::API::Result::Endpoint
  • OpenRouter::API::Result::Generation
  • OpenRouter::API::Result::Model
  • OpenRouter::API::Result::Provider

The Camelia image is copyright 2009 by Larry Wall. "Raku" is a trademark of the Yet Another Society. All rights reserved.

Built with Podlite — the markup and publishing tools behind this site.