Client
NAME
OpenRouter::API::Client - HTTP client for OpenRouter's non-inference API
SYNOPSIS
use OpenRouter::API::Client;
# Reads OPENROUTER_API_KEY from env by default.
my $or = OpenRouter::API::Client.new;
# Explicit key + attribution ā shown on OR's rankings page / logs.
my $attr = OpenRouter::API::Client.new(
:api-key(%*ENV<OPENROUTER_API_KEY>),
:http-referer<https://example.com/my-tool>,
:x-title<My Tool>,
);
# No-auth endpoints work without a key.
my $anon = OpenRouter::API::Client.new;
my @all = $anon.get-models; # /models is public
DESCRIPTION
Owns all HTTP I/O to https://openrouter.ai/api/v1. Public methods
are the per-endpoint wrappers (get-models, get-credits,
get-activity, get-generation, ...). The
OpenRouter::API-level module simply re-exports this class along
with the OpenRouter::API::Filter helper and each
Result::* type.
Internals:
Private
!requestbuilds the URL (base-url + path + query), adds auth + attribution headers, callsCro::HTTP::Client.get, parses JSON, and normalises any failure into adiewith anOpenRouter::API:prefix.Per-call
Cro::HTTP::Client.newā no connection pool, matches the established monorepo wrapper convention.Models catalogue cached in-process with a 5-minute TTL via
%!cached-models. Disabled by:cache(False); invalidate with.clear-cache. Other endpoints never touch the cache.
ATTRIBUTES
$.api-keyā OpenRouter Bearer token. Defaults to%*ENV<OPENROUTER_API_KEY>via theTWEAKsubmethod. May stay undefined for public endpoints; methods that need a key die with a helpful message.$.base-urlā overrideable for regional endpoints or mock servers. Defaults tohttps://openrouter.ai/api/v1.$.http-refererā optionalHTTP-Refererattribution.$.x-titleā optionalX-Titleattribution.$.cacheā whethersearch-modelscaches the models catalogue. Default True.$.cache-ttlā cache lifetime. Default 5 minutes.