OpenRouter

NAME

LLM::Chat::Backend::Response::OpenRouter - OpenRouter-flavoured Response with cost + routing metadata

SYNOPSIS


use LLM::Chat::Backend::Response::OpenRouter;
use UUID::V4;

# Built by L<LLM::Chat::Backend::OpenRouter>'s C<chat-completion> path
# — you rarely construct one directly. The shape below shows what's
# available once the backend has lifted the response body.
my $resp = LLM::Chat::Backend::Response::OpenRouter.new(id => uuid-v4());

# Inherited from base Response (OAI-spec):
#   $resp.prompt-tokens / completion-tokens / total-tokens / model-used
#
# Added by Augment (OpenRouter-specific):
#   $resp.cost            — USD spent (Num) when usage.cost is in the body
#   $resp.generation-id   — OR's "gen-XXXX" id for /generation lookups
#   $resp.provider-name   — provider OR routed to (e.g. "Anthropic")
#   $resp.is-byok         — True when call used user's BYOK keys

DESCRIPTION

Subclass of LLM::Chat::Backend::Response that adds OpenRouter-only usage and routing fields via the LLM::Chat::Backend::Response::OpenRouter::Augment role. Use it (or its streaming sibling LLM::Chat::Backend::Response::OpenRouter::Stream) when you need to read costs, look up generation metadata via OpenRouter's /generation endpoint, or branch on which underlying provider served a request.

The split lets a generic OpenAI-compatible client (any OpenAICommon-derived backend) keep its Response surface clean — fields that don't exist on the wire for OpenAI proper don't leak into the base type.

Why a role + two classes?

Response and Response::Stream are sibling classes (Stream extends Response). Adding the OR-specific attrs + setter via a role that both classes consume avoids diamond inheritance and keeps the extra fields in one place.

The role declares only attrs and a fresh setter — no callsame / nextsame dispatch from inside the role, so it sidesteps the known-broken role-redispatch case.

LLM::Chat v0.10.0

Simple framework for LLM inferencing

Authors

  • Matt Doughty

License

Artistic-2.0

Dependencies

Cro::HTTP::Client:ver<0.8.11+>:auth<zef:cro>Digest::SHA256::Native:ver<1.0.0+>:auth<zef:bduggan>JSON::Fast:ver<0.19+>:auth<cpan:TIMOTIMO>Template::Jinja2:ver<0.3.0+>:auth<zef:apogee>Tokenizers:ver<0.3.0+>:auth<zef:apogee>UUID::V4:ver<1.0.0+>:auth<zef:masukomi>

Provides

  • LLM::Chat
  • LLM::Chat::Backend
  • LLM::Chat::Backend::KoboldCpp
  • LLM::Chat::Backend::Mock
  • LLM::Chat::Backend::OpenAICommon
  • LLM::Chat::Backend::OpenRouter
  • LLM::Chat::Backend::Response
  • LLM::Chat::Backend::Response::OpenRouter
  • LLM::Chat::Backend::Response::OpenRouter::Augment
  • LLM::Chat::Backend::Response::OpenRouter::Stream
  • LLM::Chat::Backend::Response::Stream
  • LLM::Chat::Backend::Settings
  • LLM::Chat::Conversation
  • LLM::Chat::Conversation::Message
  • LLM::Chat::Debug
  • LLM::Chat::Retry
  • LLM::Chat::Retry::Exceptions
  • LLM::Chat::Template
  • LLM::Chat::Template::ChatML
  • LLM::Chat::Template::DeepSeekV4
  • LLM::Chat::Template::Gemma2
  • LLM::Chat::Template::Jinja2
  • LLM::Chat::Template::Llama3
  • LLM::Chat::Template::Llama4
  • LLM::Chat::Template::MistralV7
  • LLM::Chat::TokenCounter
  • LLM::Chat::ToolLoop

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.