Expand description
The OpenRouter backend: the per-key spend probe against
{base}/v1/key with the account credit pool from {base}/v1/credits
alongside it. The configured base url already ends in
/api (that is what the chat API wants), so only the /v1/...
tails are appended; appending the documented site-relative paths
yields /api/api/..., which 404s.
Re-exportsΒ§
use std::time::SystemTime;πuse async_trait::async_trait;πuse reqwest::header::ACCEPT;πuse reqwest::header::AUTHORIZATION;πuse reqwest::header::HeaderMap;πuse reqwest::header::HeaderValue;πuse serde::de::DeserializeOwned;πuse forge_primitives::usage::oauth::OauthUsageError;πuse forge_primitives::usage::openrouter::CreditsResponse;πuse forge_primitives::usage::openrouter::KeyResponse;πuse forge_primitives::usage::ApiSpend;πuse forge_primitives::usage::UsageSnapshot;πuse forge_primitives::usage::UsageSourceKind;πuse crate::helpers::BaseUrlCredential;πuse crate::helpers::MissingBase;πuse crate::helpers::OAUTH_TIMEOUT;πuse crate::helpers::base_url_credential;πuse crate::helpers::parse_retry_after;πuse crate::helpers::redacted_body;πuse crate::helpers::redacted_message;πuse crate::AccountEnv;πuse crate::BillingModel;πuse crate::ProbeError;πuse crate::Provider;πuse crate::ProviderBackend;πuse crate::ProviderHost;π
StructsΒ§
- Openrouter
- The OpenRouter
[[accounts]] providertoken.
EnumsΒ§
- Mapper π
FunctionsΒ§
- balance_
from_ πcredits - choose_
mapper π - The mapper the accountβs env earns, paired with the credential that earns it: the base-url pair earns the spend mapper, and a missing base url carries its error to the probeβs Unmappable surface. Pure so the routing stays unit-pinned - the probe cannot be driven against the network offline.
- credits_
balance π - The accountβs remaining credit pool, or
Nonewhen the fetch or decode fails for any reason, or the 200 carries nodataenvelope - each logged with its own cause. The balance is auxiliary, and the/v1/keydata the panel also renders must stand even when this endpoint is unavailable. - credits_
url π - OpenRouterβs account-wide credit endpoint, joined by the same rule
as
key_url. - fetch_
json π - One authenticated GET, classified like the window probes: 401 / 403 unauthorized, 429 rate-limited (honouring Retry-After), any other status carrying a truncated body suffix. Returns the decoded body alongside the raw bytes so a caller can name an unexpected 200 shape in its own log.
- key_
probe π - One probe for a pay-per-token account: the per-key spend from
{base}/v1/key, plus the accountβs credit pool from{base}/v1/credits. SharesOauthUsageErrorwith the window probes so the loader and poller classify a 401 / 429 / network failure the same way regardless of billing kind. The key fetch is load-bearing and its error propagates; the credits fetch is auxiliary and its failure only makes the balance absent. - key_url π
- OpenRouterβs per-key endpoint:
{base}/v1/key, trailing slash trimmed so base and base/ behave identically. - snapshot_
from_ πopenrouter_ key - Map an OpenRouter key payload into a snapshot. Window-free: a pay-per-token key has no plan window and, when uncapped, no denominator, so nothing here synthesises a utilization.