Ir al contenido

API de consola: admin-margin

Esta página se genera a partir de server/api/openapi.yaml. Su contenido está en inglés; no la edites a mano.

Cost and margin summary, payment fees, margin alerts (V3 B1). Handlers: internal/admin/margin.

Margin over time

operationId adminGetMarginSeries · auth: adminSession

Usage revenue, upstream cost and margin per hour or UTC day, from the materialised summary (see adminGetMarginStatus for how current it is). Hour series span at most 31 days, day series 3 years.

Parameter In Type Required Description
from query string<date-time> yes Inclusive lower bound (rounded down to the bucket).
to query string<date-time> yes Exclusive upper bound (rounded up to the bucket).
granularity query MarginGranularity no (default: “day”)
model_id query string<uuid> no Only this model (the nil uuid selects usage without a model).
channel_id query string<uuid> no Only this channel (the nil uuid selects usage that reached no channel).
org_id query string<uuid> no Only this organisation.
Status Meaning Body
200 OK application/json MarginSeries
default Error envelope. The HTTP status follows the error kind. application/json Error

Response 200 application/json — MarginSeries

  • granularity (MarginGranularity, required, default: “day”)
  • from (string, required)
  • to (string, required)
  • points (array of MarginPoint, required) — Buckets with data, oldest first.
    • bucket (string, required) — Start of the hour or UTC day.
    • totals (MarginTotals, required) — Summed measures. Revenue is what the organisations were charged (usage_records.cost_nano); cost is the upstream cost of every attempt, failed ones included, on the attempt’s channel.
      • records (integer, required) — Usage records delivered by this row’s channel.
      • requests (integer, required)
      • input_tokens (integer, required)
      • output_tokens (integer, required)
      • list_nano (NanoUSD, required, pattern: ”^-?[0-9]+$”) — An amount of money in nano-USD (1 USD = 1,000,000,000) as a decimal integer string. It is a string because an int64 does not survive JavaScript numbers. Never a float.
      • revenue_nano (NanoUSD, required, pattern: ”^-?[0-9]+$”) — An amount of money in nano-USD (1 USD = 1,000,000,000) as a decimal integer string. It is a string because an int64 does not survive JavaScript numbers. Never a float.
      • attempts (integer, required)
      • failed_attempts (integer, required)
      • cost_nano (NanoUSD, required, pattern: ”^-?[0-9]+$”) — An amount of money in nano-USD (1 USD = 1,000,000,000) as a decimal integer string. It is a string because an int64 does not survive JavaScript numbers. Never a float.
      • unknown_cost (integer, required) — Attempts whose upstream cost is unknown; cost_nano is a lower bound while this is not zero.
      • margin_nano (NanoUSD, required, pattern: ”^-?[0-9]+$”) — An amount of money in nano-USD (1 USD = 1,000,000,000) as a decimal integer string. It is a string because an int64 does not survive JavaScript numbers. Never a float.
      • margin_ppm (integer, required, nullable) — margin / revenue in parts per million, rounded toward zero; null when revenue is zero.
  • total (MarginTotals, required) — Summed measures. Revenue is what the organisations were charged (usage_records.cost_nano); cost is the upstream cost of every attempt, failed ones included, on the attempt’s channel.
    • records (integer, required) — Usage records delivered by this row’s channel.
    • requests (integer, required)
    • input_tokens (integer, required)
    • output_tokens (integer, required)
    • list_nano (NanoUSD, required, pattern: ”^-?[0-9]+$”) — An amount of money in nano-USD (1 USD = 1,000,000,000) as a decimal integer string. It is a string because an int64 does not survive JavaScript numbers. Never a float.
    • revenue_nano (NanoUSD, required, pattern: ”^-?[0-9]+$”) — An amount of money in nano-USD (1 USD = 1,000,000,000) as a decimal integer string. It is a string because an int64 does not survive JavaScript numbers. Never a float.
    • attempts (integer, required)
    • failed_attempts (integer, required)
    • cost_nano (NanoUSD, required, pattern: ”^-?[0-9]+$”) — An amount of money in nano-USD (1 USD = 1,000,000,000) as a decimal integer string. It is a string because an int64 does not survive JavaScript numbers. Never a float.
    • unknown_cost (integer, required) — Attempts whose upstream cost is unknown; cost_nano is a lower bound while this is not zero.
    • margin_nano (NanoUSD, required, pattern: ”^-?[0-9]+$”) — An amount of money in nano-USD (1 USD = 1,000,000,000) as a decimal integer string. It is a string because an int64 does not survive JavaScript numbers. Never a float.
    • margin_ppm (integer, required, nullable) — margin / revenue in parts per million, rounded toward zero; null when revenue is zero.

Margin by model, channel or organisation

operationId adminGetMarginBreakdown · auth: adminSession

Groups the range by one dimension, largest revenue first. Uses the daily summary when from and to are whole UTC days or the range is longer than 31 days (then rounded out to whole days).

Parameter In Type Required Description
from query string<date-time> yes Inclusive lower bound (rounded down to the bucket).
to query string<date-time> yes Exclusive upper bound (rounded up to the bucket).
by query MarginDimension yes
model_id query string<uuid> no Only this model (the nil uuid selects usage without a model).
channel_id query string<uuid> no Only this channel (the nil uuid selects usage that reached no channel).
org_id query string<uuid> no Only this organisation.
limit query integer<int32> no (minimum: 1, maximum: 1000, default: 100)
Status Meaning Body
200 OK application/json MarginBreakdown
default Error envelope. The HTTP status follows the error kind. application/json Error

Response 200 application/json — MarginBreakdown

  • by (MarginDimension, required)
  • from (string, required)
  • to (string, required)
  • granularity (MarginGranularity, required, default: “day”)
  • data (array of MarginBreakdownRow, required)
    • key (string, required) — Model, channel or org id; the nil uuid for “none”.
    • label (string, required) — Model slug, channel name or org name; empty when unknown.
    • totals (MarginTotals, required) — Summed measures. Revenue is what the organisations were charged (usage_records.cost_nano); cost is the upstream cost of every attempt, failed ones included, on the attempt’s channel.
      • records (integer, required) — Usage records delivered by this row’s channel.
      • requests (integer, required)
      • input_tokens (integer, required)
      • output_tokens (integer, required)
      • list_nano (NanoUSD, required, pattern: ”^-?[0-9]+$”) — An amount of money in nano-USD (1 USD = 1,000,000,000) as a decimal integer string. It is a string because an int64 does not survive JavaScript numbers. Never a float.
      • revenue_nano (NanoUSD, required, pattern: ”^-?[0-9]+$”) — An amount of money in nano-USD (1 USD = 1,000,000,000) as a decimal integer string. It is a string because an int64 does not survive JavaScript numbers. Never a float.
      • attempts (integer, required)
      • failed_attempts (integer, required)
      • cost_nano (NanoUSD, required, pattern: ”^-?[0-9]+$”) — An amount of money in nano-USD (1 USD = 1,000,000,000) as a decimal integer string. It is a string because an int64 does not survive JavaScript numbers. Never a float.
      • unknown_cost (integer, required) — Attempts whose upstream cost is unknown; cost_nano is a lower bound while this is not zero.
      • margin_nano (NanoUSD, required, pattern: ”^-?[0-9]+$”) — An amount of money in nano-USD (1 USD = 1,000,000,000) as a decimal integer string. It is a string because an int64 does not survive JavaScript numbers. Never a float.
      • margin_ppm (integer, required, nullable) — margin / revenue in parts per million, rounded toward zero; null when revenue is zero.

Export the margin summary as CSV

operationId adminExportMargin · auth: adminSession

One line per (bucket, org, model, channel) of the summary, oldest first, at most 200000 lines. Columns: bucket, org_id, model_id, channel_id, records, requests, input_tokens, output_tokens, list_nano, revenue_nano, attempts, failed_attempts, cost_nano, unknown_cost, margin_nano. Amounts are nano-USD integers. The nil uuid stands for “none”. Header X-Truncated: true when lines were cut off.

Parameter In Type Required Description
from query string<date-time> yes Inclusive lower bound (rounded down to the bucket).
to query string<date-time> yes Exclusive upper bound (rounded up to the bucket).
granularity query MarginGranularity no (default: “day”)
model_id query string<uuid> no Only this model (the nil uuid selects usage without a model).
channel_id query string<uuid> no Only this channel (the nil uuid selects usage that reached no channel).
org_id query string<uuid> no Only this organisation.
Status Meaning Body
200 CSV file (attachment). text/csv string
default Error envelope. The HTTP status follows the error kind. application/json Error

Response 200 text/csv — string

Payment provider fees

operationId adminGetPaymentFees · auth: adminSession

Net fees the payment providers kept (ledger account payment_fees) for transactions booked in the window, per provider. Not allocated to models or channels. At most 366 days.

Parameter In Type Required Description
from query string<date-time> yes Inclusive lower bound (rounded down to the bucket).
to query string<date-time> yes Exclusive upper bound (rounded up to the bucket).
Status Meaning Body
200 OK application/json PaymentFeeSummary
default Error envelope. The HTTP status follows the error kind. application/json Error

Response 200 application/json — PaymentFeeSummary

  • from (string, required)
  • to (string, required)
  • total_nano (NanoUSD, required, pattern: ”^-?[0-9]+$”) — An amount of money in nano-USD (1 USD = 1,000,000,000) as a decimal integer string. It is a string because an int64 does not survive JavaScript numbers. Never a float.
  • providers (array of PaymentFeeTotal, required)
    • provider (string, required)
    • amount_nano (NanoUSD, required, pattern: ”^-?[0-9]+$”) — An amount of money in nano-USD (1 USD = 1,000,000,000) as a decimal integer string. It is a string because an int64 does not survive JavaScript numbers. Never a float.
    • txns (integer, required)

Margin alerts evaluated now

operationId adminGetMarginAlerts · auth: adminSession

Offerings whose list sell price is below their cost price, and channels whose margin was negative in the last complete hours in a row.

Status Meaning Body
200 OK application/json MarginAlerts
default Error envelope. The HTTP status follows the error kind. application/json Error

Response 200 application/json — MarginAlerts

  • evaluated_at (string, required)
  • inverted (array of MarginPriceInversion, required)
    • offering_id (string, required)
    • model_id (string, required)
    • channel_id (string, required)
    • items (array of string, required) — Price components sold below cost (“input”, “output”, …; tiers as “input@200000”, image variants as “images:<variant>”).
  • negative (array of MarginChannelStreak, required)
    • channel_id (string, required)
    • hours (integer, required) — Consecutive complete hours, ending with the last one, with a negative margin.
    • margin_nano (NanoUSD, required, pattern: ”^-?[0-9]+$”) — An amount of money in nano-USD (1 USD = 1,000,000,000) as a decimal integer string. It is a string because an int64 does not survive JavaScript numbers. Never a float.

Refresh state of the margin summary

operationId adminGetMarginStatus · auth: adminSession

Status Meaning Body
200 OK application/json MarginStatus
default Error envelope. The HTTP status follows the error kind. application/json Error

Response 200 application/json — MarginStatus

  • refreshed_through (string, required, nullable) — End of the last hour the incremental refresh recomputed.
  • refreshed_at (string, required, nullable)
  • late_checked_at (string, required, nullable)
  • rebuild (object, required)
    • from (string, required)
    • to (string, required)
    • next (string, required) — Next hour to recompute (equals to when done).
    • requested_by (string, required, nullable)
    • requested_at (string, required, nullable)
    • done_at (string, required, nullable)

Recompute a range of the margin summary

operationId adminRebuildMargin · auth: adminSession

Schedules a recompute of [from, to) (rounded out to whole hours, at most 400 days back, capped at the current hour) that the worker processes in chunks; replaces a pending one. The result is identical to the incremental refresh.

Request body (required) application/json — MarginRebuildRequest

  • from (string, required)
  • to (string, required)
Status Meaning Body
202 Scheduled. application/json MarginStatus
default Error envelope. The HTTP status follows the error kind. application/json Error

Response 202 application/json — MarginStatus

  • refreshed_through (string, required, nullable) — End of the last hour the incremental refresh recomputed.
  • refreshed_at (string, required, nullable)
  • late_checked_at (string, required, nullable)
  • rebuild (object, required)
    • from (string, required)
    • to (string, required)
    • next (string, required) — Next hour to recompute (equals to when done).
    • requested_by (string, required, nullable)
    • requested_at (string, required, nullable)
    • done_at (string, required, nullable)