mirror of
https://github.com/FJurmanovic/sugarr.git
synced 2026-11-11 15:51:09 +00:00
Support OpenRouter's real per-request cost reporting
Send usage: { include: true } on every chat completion request (an
OpenRouter-specific extension - requires Usage Accounting enabled on
the OpenRouter account; other OpenAI-compatible providers generally
ignore unknown top-level request fields). When the response includes
OpenRouter's own usage.cost, forward it to Langfuse as
costDetails.total, so cost is the real per-request figure OpenRouter
billed rather than a guess from Langfuse's model price list (which
has no entry for proxied/aggregated OpenRouter model names anyway).
Verified: full suite (84/84) passing, tsc/eslint clean, docker
compose build succeeds. Per Langfuse's OpenRouter integration guide:
https://langfuse.com/integrations/gateways/openrouter
This commit is contained in:
@@ -73,6 +73,7 @@ export class LangfuseTracer extends Tracer {
|
||||
generation.update({
|
||||
output: output.output,
|
||||
usageDetails: toUsageDetails(output.usage) as Record<string, number> | undefined,
|
||||
costDetails: output.usage?.cost !== undefined ? { total: output.usage.cost } : undefined,
|
||||
metadata: output.metadata,
|
||||
});
|
||||
generation.end();
|
||||
|
||||
Reference in New Issue
Block a user