Skip to main content

Billing API

Table of Contents

Top

upsquad/billing/v1/billing.proto

AgentUsageEntry

AgentUsageEntry is one row of the per-agent usage breakdown. Added by issue #894.

FieldTypeLabelDescription
agent_idstringagent_id is the agent UUID.
agent_namestringagent_name is the human-readable agent name (joined from agents.name). Empty string when the agent record has been deleted but usage rows remain (e.g. after a hard-delete).
llm_tokensint64llm_tokens is the total LLM tokens consumed by this agent in the period.
agent_hoursdoubleagent_hours is the total compute hours billed against this agent.

CheckFeatureGateRequest

CheckFeatureGateRequest evaluates a feature gate for the caller's org.

FieldTypeLabelDescription
feature_keystringfeature_key identifies the feature to check (e.g. "max_agents", "max_workflows", "llm_tokens_monthly").

CheckFeatureGateResponse

CheckFeatureGateResponse returns the gate evaluation result.

FieldTypeLabelDescription
allowedboolallowed is true if the organisation is within limits.
current_usageint32current_usage is the current count/amount for this feature.
limitint32limit is the plan limit for this feature. Zero means unlimited.
unlimitedboolunlimited is true when the plan has no cap for this feature.
plan_tierstringplan_tier is the organisation's current plan.
messagestringmessage is a human-readable explanation of the gate result.

GetSubscriptionRequest

GetSubscriptionRequest retrieves the subscription for the caller's org. The org_id is derived from the JWT scope -- no field needed in the request.

GetSubscriptionResponse

GetSubscriptionResponse returns the subscription details.

FieldTypeLabelDescription
subscriptionSubscriptionsubscription is the organisation's current subscription.

GetUsageByAgentRequest

GetUsageByAgentRequest queries per-agent usage for a date range. org_id is JWT-scoped via the scope middleware -- not in the request. Added by issue #894.

FieldTypeLabelDescription
start_timegoogle.protobuf.Timestampstart_time is the beginning of the query range (inclusive).
end_timegoogle.protobuf.Timestampend_time is the end of the query range (exclusive).
pageint32page is the 1-based page number for pagination. Defaults to 1.
page_sizeint32page_size is the maximum number of results per page. Max 100, default 20.

GetUsageByAgentResponse

GetUsageByAgentResponse returns the per-agent usage breakdown. Added by issue #894.

FieldTypeLabelDescription
entriesAgentUsageEntryrepeatedentries is the per-agent usage rows for the period, sorted by llm_tokens descending then agent_id ascending.
total_countint32total_count is the total number of agents with usage in the period (for pagination).

GetUsageByModelRequest

GetUsageByModelRequest queries per-model usage for a date range. org_id is JWT-scoped via the scope middleware -- not in the request. Added by issue #894.

FieldTypeLabelDescription
start_timegoogle.protobuf.Timestampstart_time is the beginning of the query range (inclusive).
end_timegoogle.protobuf.Timestampend_time is the end of the query range (exclusive).

GetUsageByModelResponse

GetUsageByModelResponse returns the per-model usage breakdown. Added by issue #894.

FieldTypeLabelDescription
entriesModelUsageEntryrepeatedentries is the per-model usage rows for the period, sorted by cost_usd descending then model_name ascending.

GetUsageSummaryRequest

GetUsageSummaryRequest queries usage data for a date range.

FieldTypeLabelDescription
start_dategoogle.protobuf.Timestampstart_date is the beginning of the query range (inclusive).
end_dategoogle.protobuf.Timestampend_date is the end of the query range (exclusive).

GetUsageSummaryResponse

GetUsageSummaryResponse returns daily usage breakdown and totals.

FieldTypeLabelDescription
daysUsageDayrepeateddays is the list of per-day usage entries.
totalUsageMetricstotal is the aggregated usage over the entire range.

Invoice

Invoice represents a monthly bill generated from usage records.

FieldTypeLabelDescription
idstringid is the invoice UUID or synthetic identifier.
org_idstringorg_id is the tenant organisation UUID.
invoice_numberstringinvoice_number is the human-readable invoice number.
billing_period_startgoogle.protobuf.Timestampbilling_period_start is the start of the billing period.
billing_period_endgoogle.protobuf.Timestampbilling_period_end is the end of the billing period.
statusstringstatus is the invoice state: "draft", "finalized", "paid", "void".
subtotal_centsint64subtotal_cents is the pre-tax amount in cents.
tax_centsint64tax_cents is the tax amount in cents.
total_centsint64total_cents is the total amount in cents.
usage_summaryUsageMetricsusage_summary is the aggregated usage for the billing period.
generated_atgoogle.protobuf.Timestampgenerated_at is when the invoice was generated.
due_dategoogle.protobuf.Timestampdue_date is the payment due date.

ListInvoicesRequest

ListInvoicesRequest returns paginated invoices.

FieldTypeLabelDescription
pageint32page is the 1-based page number for pagination.
page_sizeint32page_size is the maximum number of results per page. Max 100, default 20.

ListInvoicesResponse

ListInvoicesResponse returns a paginated list of invoices.

FieldTypeLabelDescription
invoicesInvoicerepeatedinvoices is the list of invoice records.
total_countint32total_count is the total number of invoices (for pagination).

ListPlansRequest

ListPlansRequest takes no parameters -- the plan catalogue is platform-wide. Added by LLD #855.

ListPlansResponse

ListPlansResponse returns the ordered plan catalogue. Added by LLD #855.

FieldTypeLabelDescription
plansPlanrepeatedplans is the ordered list of plans: free, pro, enterprise.

ModelUsageEntry

ModelUsageEntry is one row of the per-model usage breakdown. Added by issue #894.

FieldTypeLabelDescription
model_namestringmodel_name is the LLM model identifier (e.g. "claude-sonnet-4", "gpt-4o").
llm_tokensint64llm_tokens is the total tokens (input + output) consumed for this model in the period.
cost_usddoublecost_usd is the total cost in USD recorded for this model.

Plan

Plan is one entry in the plan catalogue returned by ListPlans. Added by LLD #855.

FieldTypeLabelDescription
namestringname is the canonical identifier: "free"
display_namestringdisplay_name is the human-readable name (e.g. "Free", "Pro").
descriptionstringdescription is marketing copy for the plan tier.
price_cents_per_seatint64price_cents_per_seat is the per-seat cost in cents per billing period. Pro tier is a PLACEHOLDER until PRD #552 (Pricing & Packaging) is approved -- callers should render a "Subject to change" badge when is_placeholder_price is true.
currencystringcurrency is the ISO currency code ("USD").
billing_periodstringbilling_period is the billing cadence ("monthly").
featuresPlanFeaturerepeatedfeatures is the feature-gate set that applies to this plan.
is_placeholder_priceboolis_placeholder_price is true when price_cents_per_seat is a placeholder pending PRD #552 approval (Pro tier MVP only).

PlanFeature

PlanFeature is one feature-gate entry attached to a Plan. Added by LLD #855.

FieldTypeLabelDescription
feature_keystringfeature_key matches feature_gates.feature_key.
limit_valueint64limit_value is the plan cap for this feature. -1 signals "no cap" (i.e. the DB row stores NULL limit_value).
unlimitedboolunlimited is true when the plan has no cap for this feature.
display_stringstringdisplay_string is a pre-formatted label for the client UI (e.g. "Unlimited agents", "Up to 10 agents").

RecordUsageRequest

RecordUsageRequest logs a usage event.

FieldTypeLabelDescription
agent_idstringagent_id is the agent that generated the usage (optional).
metric_typestringmetric_type is the usage category: "llm_tokens", "agent_hours", or "storage_bytes".
quantityint64quantity is the amount of usage to record.
unit_costdoubleunit_cost is the per-unit cost (optional, defaults to 0).

RecordUsageResponse

RecordUsageResponse confirms the usage was recorded.

FieldTypeLabelDescription
usage_recordUsageRecordusage_record is the created usage record.

Subscription

Subscription represents an organisation's billing plan and status.

FieldTypeLabelDescription
idstringid is the subscription UUID.
org_idstringorg_id is the tenant organisation UUID.
plan_tierstringplan_tier is the current plan: "free", "pro", or "enterprise".
statusstringstatus is the subscription state: "active", "trialing", "past_due", "cancelled", or "suspended".
external_idstringexternal_id is the identifier from an external payment provider (if any).
trial_ends_atgoogle.protobuf.Timestamptrial_ends_at is when the trial period expires (if applicable).
current_period_startgoogle.protobuf.Timestampcurrent_period_start is the start of the current billing period.
current_period_endgoogle.protobuf.Timestampcurrent_period_end is the end of the current billing period.
created_atgoogle.protobuf.Timestampcreated_at is when the subscription was created.
updated_atgoogle.protobuf.Timestampupdated_at is when the subscription was last modified.

UpdatePlanRequest

UpdatePlanRequest changes the subscription plan tier.

FieldTypeLabelDescription
new_planstringnew_plan is the target plan tier: "free", "pro", or "enterprise".

UpdatePlanResponse

UpdatePlanResponse returns the updated subscription.

FieldTypeLabelDescription
subscriptionSubscriptionsubscription is the updated subscription.

UsageDay

UsageDay represents usage metrics for a single day.

FieldTypeLabelDescription
dategoogle.protobuf.Timestampdate is the calendar date for this usage entry.
usageUsageMetricsusage is the aggregated metrics for this day.

UsageMetrics

UsageMetrics contains aggregated usage data for a billing period.

FieldTypeLabelDescription
llm_tokensint64llm_tokens is the total LLM tokens consumed.
agent_hoursdoubleagent_hours is the total agent compute hours.
storage_bytesint64storage_bytes is the total storage consumed in bytes.

UsageRecord

UsageRecord represents a single usage event for billing.

FieldTypeLabelDescription
idstringid is the usage record UUID.
org_idstringorg_id is the tenant organisation UUID.
agent_idstringagent_id is the agent that generated the usage (optional).
metric_typestringmetric_type is the usage category: "llm_tokens", "agent_hours", or "storage_bytes".
quantityint64quantity is the amount of usage recorded.
unit_costdoubleunit_cost is the per-unit cost in the smallest currency unit.
recorded_atgoogle.protobuf.Timestamprecorded_at is when the usage was recorded.

BillingService

BillingService manages subscriptions, usage metering, invoice generation, and feature gate evaluation for organisations on the UpsQuad platform. All operations are scoped to a tenant organisation via JWT-derived scope claims.

Method NameRequest TypeResponse TypeDescription
GetSubscriptionGetSubscriptionRequestGetSubscriptionResponseGetSubscription retrieves the current subscription for the caller's organisation.
UpdatePlanUpdatePlanRequestUpdatePlanResponseUpdatePlan changes the subscription plan tier for the caller's organisation. In MVP this is a manual admin operation; future versions will integrate with external payment providers.
GetUsageSummaryGetUsageSummaryRequestGetUsageSummaryResponseGetUsageSummary returns daily usage breakdown for billing charts, aggregated by metric type over a date range.
ListInvoicesListInvoicesRequestListInvoicesResponseListInvoices returns paginated synthetic monthly invoices generated from usage records.
RecordUsageRecordUsageRequestRecordUsageResponseRecordUsage logs a usage event for billing and feature gate evaluation.
CheckFeatureGateCheckFeatureGateRequestCheckFeatureGateResponseCheckFeatureGate evaluates whether the caller's organisation is within the plan limits for a given feature.
ListPlansListPlansRequestListPlansResponseListPlans returns the catalogue of plans with display metadata and per-plan feature gates. L1 clearance floor — every authenticated user sees the catalogue (upgrade funnel). Added by LLD #855.
GetUsageByAgentGetUsageByAgentRequestGetUsageByAgentResponseGetUsageByAgent returns usage aggregated per agent for the given period, suitable for the /billing/usage agent breakdown view. Added by issue #894 (BillingService usage breakdown RPCs).
GetUsageByModelGetUsageByModelRequestGetUsageByModelResponseGetUsageByModel returns usage aggregated per LLM model for the given period, suitable for the /billing/usage model breakdown view. Reads from llm_usage_events (per-call attribution hook). Added by issue #894 (BillingService usage breakdown RPCs).

Scalar Value Types

.proto TypeNotesC++JavaPythonGoC#PHPRuby
doubledoubledoublefloatfloat64doublefloatFloat
floatfloatfloatfloatfloat32floatfloatFloat
int32Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint32 instead.int32intintint32intintegerBignum or Fixnum (as required)
int64Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint64 instead.int64longint/longint64longinteger/stringBignum
uint32Uses variable-length encoding.uint32intint/longuint32uintintegerBignum or Fixnum (as required)
uint64Uses variable-length encoding.uint64longint/longuint64ulonginteger/stringBignum or Fixnum (as required)
sint32Uses variable-length encoding. Signed int value. These more efficiently encode negative numbers than regular int32s.int32intintint32intintegerBignum or Fixnum (as required)
sint64Uses variable-length encoding. Signed int value. These more efficiently encode negative numbers than regular int64s.int64longint/longint64longinteger/stringBignum
fixed32Always four bytes. More efficient than uint32 if values are often greater than 2^28.uint32intintuint32uintintegerBignum or Fixnum (as required)
fixed64Always eight bytes. More efficient than uint64 if values are often greater than 2^56.uint64longint/longuint64ulonginteger/stringBignum
sfixed32Always four bytes.int32intintint32intintegerBignum or Fixnum (as required)
sfixed64Always eight bytes.int64longint/longint64longinteger/stringBignum
boolboolbooleanbooleanboolboolbooleanTrueClass/FalseClass
stringA string must always contain UTF-8 encoded or 7-bit ASCII text.stringStringstr/unicodestringstringstringString (UTF-8)
bytesMay contain any arbitrary sequence of bytes.stringByteStringstr[]byteByteStringstringString (ASCII-8BIT)