MCPcopy Create free account
hub / github.com/pollinations/pollinations / readProviderRequestCost

Function readProviderRequestCost

shared/registry/perplexity-billing.ts:24–34  ·  view source on GitHub ↗
(event: unknown)

Source from the content-addressed store, hash-verified

22
23// Read `usage.cost.request_cost` from a single response or stream event.
24function readProviderRequestCost(event: unknown): ProviderRequestCostRead {
25 const cost = (event as PerplexityCostOutput | undefined)?.usage?.cost;
26 if (cost == null) return { status: "absent" };
27 if (typeof cost !== "object") return { status: "malformed", raw: cost };
28 if (!("request_cost" in cost)) return { status: "absent" };
29 const value = cost.request_cost;
30 if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
31 return { status: "malformed", raw: value };
32 }
33 return { status: "ok", value };
34}
35
36function getPerplexityReportedRequestCost(
37 output: unknown,

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected