Receive llm_usage_recorded events from arcadia-llm-gateway
POST /api/v1/integrations/llm-usage stores priced LLM usage events (idempotent on gateway_request_id) in llm_usage_events. The gateway is the LLM-pricing authority — arcadia-cloud trusts the charge it sends rather than re-pricing. The monthly invoice rollup now appends an llm_usage line per deployment alongside the infra quote lines; the exact decimal charges are summed and rounded to cents once. Closes the gateway→cloud billing loop. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -77,7 +77,12 @@ defmodule ArcadiaCloud.Invoicing do
|
||||
})
|
||||
|> Repo.insert()
|
||||
|
||||
lines = Enum.flat_map(subscriptions, &subscription_lines(&1, period_start, period_end))
|
||||
# Infra lines from the quote engine + LLM-token lines from metered
|
||||
# gateway usage (arcadia-llm-gateway pushes priced usage events).
|
||||
lines =
|
||||
Enum.flat_map(subscriptions, &subscription_lines(&1, period_start, period_end)) ++
|
||||
ArcadiaCloud.LlmUsage.period_lines(tenant_id, period_start, period_end)
|
||||
|
||||
Enum.each(lines, &insert_line(invoice.id, &1))
|
||||
|
||||
subtotal = Enum.reduce(lines, 0, &(&1.amount_cents + &2))
|
||||
|
||||
Reference in New Issue
Block a user