Skip to main content

resources/finops.ts

Source: sdks/typescript/packages/sdk/src/resources/finops.ts. Back to the TypeScript SDK reference index.

note

This page is generated by tools/docs/gen_sdk_reference.py from the SDK sources and the OpenAPI text folders. Do not edit it by hand: change the source and regenerate.

Interface TokenUnits​

Token units of a Usage Event; cached tokens are part of the input and reasoning tokens part of the output.

Fields:

NameTypeRequiredDescription
input_tokensnumberyesTotal input tokens reported by the provider.
output_tokensnumberyesTotal output tokens reported by the provider.
cached_input_tokensnumbernoInput tokens served from the cache, included in input_tokens.
reasoning_tokensnumbernoExplicit reasoning tokens, at least 0; overrides the reserve of reasoning_effort.

Type alias ReconciliationSource​

Format of a bill import: openai, anthropic, aws_cur, azure, gcp or generic_csv.

Definition: "openai" \| "anthropic" \| "aws_cur" \| "azure" \| "gcp" \| "generic_csv".

Interface FinOpsSettings​

FinOps settings of the tenant: currency, monthly budget, variance threshold and reservation lifetime.

Fields:

NameTypeRequiredDescription
currencystringyesISO 4217 currency code, for example EUR.
monthly_budgetstring | nullyesMonthly budget of the tenant, at least 0: the measured spend of the month is compared to it and budget alerts fire at the thresholds (50, 80 and 100 percent by default). It does not refuse calls by itself; use hard quotas for that.
variance_threshold_pctstringyesVariance between measured and billed cost, in percent, above which a variance alert is raised (default 10).
reservation_ttl_secondsnumberyesDefault lifetime of a quota reservation in seconds, greater than 0 (default 900).

Type alias SummaryGroupBy​

Grouping of FinOpsResource.summary: tenant, project, agent, model, provider, usage_type or day.

Definition: "tenant" \| "project" \| "agent" \| "model" \| "provider" \| "usage_type" \| "day".

Class FinOpsResource​

FinOps. Cost management of AI usage: price cards, usage events, estimates, quotas and reservations, GPU cost allocation, billing reconciliation and alerts.

Resource

Attributes:

NameTypeRequiredDescription
alertsAlertsyesFinOps alerts (GET /v1/finops/alerts).
allocationPoliciesAllocationPoliciesyesCost allocation policies: list and create on /v1/finops/allocation-policies.
fxRatesFxRatesyesExchange rates: list and put on /v1/finops/fx-rates.
gpuGpuyesGPU usage: ingestSamples and allocation on /v1/finops/gpu.
priceCardsPriceCardsyesPrice cards: list, create, get and retire on /v1/finops/price-cards.
reconciliationReconciliationyesReconciliation with provider bills: imports, run and report (/v1/finops/reconciliation).
settingsSettingsyesFinOps settings of the tenant: get and update on /v1/finops/settings.
usageUsageyesUsage Events: ingest, ingestBatch, list and iterate on /v1/finops/usage.

FinOpsResource.checkBudget​

checkBudget(query: { agent?: string; project?: string; run?: string } = {}, opts?: CallOptions)

Read the quota consumption. Each quota of the tenant with its current window and the cost and tokens used and reserved in it. Run quotas need run to find their window. Requires a reader role and a tenant principal.

Route: /v1/quotas/usage (GET).

NameTypeDefaultRequiredDescription
query{ agent?: string; project?: string; run?: string }{}noQuery string parameters of the route.
optsCallOptionsnoPer call options (query, idempotency key, traceparent, headers).

Raises: the typed errors of the transport (Errors).

FinOpsResource.createMediaPrice​

createMediaPrice(body: Doc, opts?: CallOptions)

Add a media price revision. Adds a dated price revision for a media unit and answers 201. A revision never rewrites an older one. The same unit, provider, resource and start date answers 409 media_price_exists; an invalid field 422 media_price_invalid. Audited. Requires finops or tenant_admin, and a tenant principal.

Route: /v1/finops/media-prices (POST).

NameTypeDefaultRequiredDescription
bodyDocyesunit (audio_second, image, video_second, gpu_second, storage_gb_month), provider, unit_price (number, at least 0), currency (ISO 4217), source (where the price comes from, required), optional resource (default *, the whole provider) and effective_from (ISO 8601, default now).
optsCallOptionsnoPer call options (query, idempotency key, traceparent, headers).

Raises: the typed errors of the transport (Errors).

FinOpsResource.estimate​

estimate(body: Doc, opts?: CallOptions)

Estimate the cost of a call. Prices a planned call with the price card in force (most specific model pattern and region first), converts it to the tenant currency and checks it against the matching quotas, without reserving anything. Reasoning tokens are added according to the billing mode of the card. No card answers 404 price_card_not_found; a missing FX rate 422 fx_rate_missing. Requires a usage or reader role and a tenant principal.

Route: /v1/finops/estimate (POST).

NameTypeDefaultRequiredDescription
bodyDocyesThe planned call to price.
optsCallOptionsnoPer call options (query, idempotency key, traceparent, headers).

Raises: the typed errors of the transport (Errors).

FinOpsResource.estimateMediaCost​

estimateMediaCost(body: Doc, opts?: CallOptions)

Estimate media costs. Prices up to 100 media items with the revision in force at their date (exact resource first, then the provider wide * revision). An item without price comes back with amount: null, status: unavailable and reason: price_unknown; total is given only when every item is priced in one currency (complete: true). Invalid items answer 422 media_price_invalid with the field. Requires a reader role or agent, and a tenant principal.

Route: /v1/finops/media-costs/estimate (POST).

NameTypeDefaultRequiredDescription
bodyDocyesitems: 1 to 100 objects with unit (audio_second, image, video_second, gpu_second, storage_gb_month), provider, quantity (positive number), optional resource (default *) and at (ISO 8601, default now).
optsCallOptionsnoPer call options (query, idempotency key, traceparent, headers).

Raises: the typed errors of the transport (Errors).

FinOpsResource.mediaPrices​

mediaPrices(query: { unit?: string } = {}, opts?: CallOptions)

List the media prices. Dated media price revisions of the tenant by unit, provider, resource and date, with the list of supported units. An unknown unit answers 422 media_price_invalid. Requires a reader role and a tenant principal.

Route: /v1/finops/media-prices (GET).

NameTypeDefaultRequiredDescription
query{ unit?: string }{}noQuery string parameters of the route.
optsCallOptionsnoPer call options (query, idempotency key, traceparent, headers).

Raises: the typed errors of the transport (Errors).

FinOpsResource.recordUsage​

recordUsage(event: UsageEvent | Doc, opts?: CallOptions)

Ingest a usage event. Validates a Usage Event v1, prices it (measured cost in the tenant currency) and stores it; answers 201, or 200 with duplicate: true when the same event_id was already stored. An invalid event answers 422 usage_event_invalid with the errors; an event of another tenant 403 usage_tenant_mismatch. One audit event per call, never the payload. Requires finops, tenant_admin, agent or developer, and a tenant principal.

Route: /v1/finops/usage (POST).

NameTypeDefaultRequiredDescription
eventUsageEvent | DocyesUsage Event to record; sending the same event_id twice records it once.
optsCallOptionsnoPer call options (query, idempotency key, traceparent, headers).

Raises: the typed errors of the transport (Errors).

FinOpsResource.reserve​

reserve(body: ReserveBody, opts?: CallOptions)

Reserve cost and tokens. Reserves an amount on every enabled quota matching the scope (tenant quotas always match; a user principal adds its own user scope) and answers 201 with the reservation, its items per quota and window, the soft quotas exceeded and its expiry. A hard quota that would be exceeded answers 429 quota_exceeded with Retry-After: 60, and nothing is reserved. Expired reservations are released first. Audited. Requires finops, tenant_admin, agent or developer, and a tenant principal.

Route: /v1/quotas/reserve (POST).

NameTypeDefaultRequiredDescription
bodyReserveBodyyesAmount, scope and lifetime of the reservation.
optsCallOptionsnoPer call options (query, idempotency key, traceparent, headers).

Raises: the typed errors of the transport (Errors).

FinOpsResource.summary​

summary(query: { group_by?: SummaryGroupBy; from?: string; to?: string } & Query = {}, opts?: CallOptions)

Summarize the spend. Usage events of the tenant grouped by one dimension, per currency: number of events, tokens, GPU seconds, estimated, measured and billed amounts (billed is null when nothing was reconciled). An unknown grouping answers 400 finops_group_by_invalid. Requires a reader role and a tenant principal.

Route: /v1/finops/summary (GET).

NameTypeDefaultRequiredDescription
query{ group_by?: SummaryGroupBy; from?: string; to?: string } & Query{}noQuery string parameters of the route.
optsCallOptionsnoPer call options (query, idempotency key, traceparent, headers).

Raises: the typed errors of the transport (Errors).

Interface QuotaReservation​

POST /v1/quotas/reserve, commit and release response; id is the reservation id.

Doc

Fields:

NameTypeRequiredDescription
idstringyesId of the reservation, used to commit or release it.
tenant_idstringyesTenant of the agent. Default default.
status"reserved" | "committed" | "released" | "expired" | stringyesreserved, committed, released or expired.
amount{ cost: { amount: string; currency: string }; tokens: number }yesReserved cost (amount and currency) and tokens.
expires_atstringyesDate and time (ISO 8601, UTC) after which the item is no longer valid.
quotasDoc[]yesQuotas the reservation counts against.
soft_exceededDoc[]yesSoft quotas the reservation goes over.

Interface ReserveBody​

Body of POST /v1/quotas/reserve: cost, tokens, scope and lifetime of the reservation.

Fields:

NameTypeRequiredDescription
coststring | numbernoCost to reserve.
tokensnumbernoTokens to reserve.
scopeDocnoWhat is backed up (clusters, services, data sets), as an object.
ttl_secondsnumbernoLifetime in seconds. Once it has elapsed, the item expires and is no longer accepted.

Interface CommitBody​

Body of QuotasResource.commit: the measured cost and tokens of the reservation.

Fields:

NameTypeRequiredDescription
coststring | numbernoMeasured cost to commit.
tokensnumbernoMeasured tokens to commit.

Interface WithReservationOptions​

Options of QuotasResource.withReservation.

Fields:

NameTypeRequiredDescription
commitBody(result: T) => CommitBodynoBuilds the commit body (measured cost and tokens) from the callback result.
optsCallOptionsnoPer call options accepted by every SDK method.

Interface QuotaCreate​

Body of POST /v1/quotas.

Doc

Fields:

NameTypeRequiredDescription
namestringyesName of the quota.
scope_type"tenant" | "project" | "user" | "agent" | "model" | "provider"noWhat the quota limits: tenant (default), project, agent, user, model or provider.
scope_valuestringnoIdentifier of the project, agent, user, model or provider; required unless scope_type is tenant, where it must be null.
period"request" | "run" | "hour" | "day" | "month"noPeriod of the quota: request, run, hour, day or month.
limit_coststring | numbernoCost limit over the period.
limit_tokensnumbernoToken limit over the period.
currencystringnoISO 4217 currency code, for example EUR.
enforcement"hard" | "soft"nohard refuses over the limit, soft only reports it.
enabledbooleannoWhether the quota is enforced.

Class QuotasResource​

FinOps. Cost management of AI usage: price cards, usage events, estimates, quotas and reservations, GPU cost allocation, billing reconciliation and alerts.

Resource

Attributes:

NameTypeRequiredDescription
fn(reservation: QuotaReservation)yesCallback of withReservation, run with the reservation.
optionsWithReservationOptions<T>yesOptions of withReservation: commit body builder and per call options.
reserveBodyReserveBody,yesBody of the reservation made by withReservation.

QuotasResource.commit​

commit(id: string, body: CommitBody = {}, opts?: CallOptions)

Commit a reservation. Replaces the reserved amount by the measured one on every quota window of the reservation and checks the alert thresholds. A closed reservation answers 409 reservation_closed; an unknown one 404 reservation_not_found. Audited. Requires finops, tenant_admin, agent or developer, and a tenant principal.

Route: /v1/quotas/{reservation_id}/commit (POST).

NameTypeDefaultRequiredDescription
idstringyesIdentifier (UUID) of the reservation returned by POST /v1/quotas/reserve.
bodyCommitBody{}noMeasured cost and tokens of the call.
optsCallOptionsnoPer call options (query, idempotency key, traceparent, headers).

Raises: the typed errors of the transport (Errors).

QuotasResource.create​

create(body: QuotaCreate, opts?: CallOptions)

Create a quota. Creates a quota of the tenant and answers 201. A cost or token limit is required, and scope_value is required unless scope_type is tenant (422 validation_error). Without currency, the tenant currency applies. Audited. Requires finops or tenant_admin, and a tenant principal.

Route: /v1/quotas (POST).

NameTypeDefaultRequiredDescription
bodyQuotaCreateyesThe new quota.
optsCallOptionsnoPer call options (query, idempotency key, traceparent, headers).

Raises: the typed errors of the transport (Errors).

QuotasResource.delete​

delete(id: string, opts?: CallOptions)

Delete a quota. Deletes a quota of the tenant and answers 204. Unknown id: 404 quota_not_found. Audited (finops.quota.delete). Requires finops or tenant_admin.

Route: /v1/quotas/{quota_id} (DELETE).

NameTypeDefaultRequiredDescription
idstringyesIdentifier (UUID) of the quota.
optsCallOptionsnoPer call options (query, idempotency key, traceparent, headers).

Raises: the typed errors of the transport (Errors).

QuotasResource.list​

list(params?: ListParams, opts?: CallOptions)

List the quotas. Quotas of the tenant by name, including those mirrored from the LLM projects (llm-project:...). One page only. Requires a reader role and a tenant principal.

Route: /v1/quotas (GET).

NameTypeDefaultRequiredDescription
paramsListParamsnoExtra fields merged into the request.
optsCallOptionsnoPer call options (query, idempotency key, traceparent, headers).

Raises: the typed errors of the transport (Errors).

QuotasResource.release​

release(id: string, opts?: CallOptions)

Release a reservation. Gives the reserved amount back to every quota window of the reservation without consuming anything (the call failed or was not made). A closed reservation answers 409 reservation_closed; an unknown one 404 reservation_not_found. Audited. Requires finops, tenant_admin, agent or developer, and a tenant principal.

Route: /v1/quotas/{reservation_id}/release (POST).

NameTypeDefaultRequiredDescription
idstringyesIdentifier (UUID) of the reservation.
optsCallOptionsnoPer call options (query, idempotency key, traceparent, headers).

Raises: the typed errors of the transport (Errors).

QuotasResource.replace​

replace(id: string, body: Doc, opts?: CallOptions)

Replace a quota. Replaces every field of a quota (same rules as on creation; without currency, the current one is kept). Unknown id: 404 quota_not_found. Audited. Requires finops or tenant_admin, and a tenant principal.

Route: /v1/quotas/{quota_id} (PUT).

NameTypeDefaultRequiredDescription
idstringyesIdentifier (UUID) of the quota.
bodyDocyesThe complete quota.
optsCallOptionsnoPer call options (query, idempotency key, traceparent, headers).

Raises: the typed errors of the transport (Errors).

QuotasResource.reserve​

reserve(body: ReserveBody, opts?: CallOptions)

Reserve cost and tokens. Reserves an amount on every enabled quota matching the scope (tenant quotas always match; a user principal adds its own user scope) and answers 201 with the reservation, its items per quota and window, the soft quotas exceeded and its expiry. A hard quota that would be exceeded answers 429 quota_exceeded with Retry-After: 60, and nothing is reserved. Expired reservations are released first. Audited. Requires finops, tenant_admin, agent or developer, and a tenant principal.

Route: /v1/quotas/reserve (POST).

NameTypeDefaultRequiredDescription
bodyReserveBodyyesAmount, scope and lifetime of the reservation.
optsCallOptionsnoPer call options (query, idempotency key, traceparent, headers).

Raises: the typed errors of the transport (Errors).

QuotasResource.usage​

usage(query?: Query, opts?: CallOptions)

Read the quota consumption. Each quota of the tenant with its current window and the cost and tokens used and reserved in it. Run quotas need run to find their window. Requires a reader role and a tenant principal.

Route: /v1/quotas/usage (GET).

NameTypeDefaultRequiredDescription
queryQuerynoQuery string parameters of the route.
optsCallOptionsnoPer call options (query, idempotency key, traceparent, headers).

Raises: the typed errors of the transport (Errors).

QuotasResource.withReservation​

async withReservation(reserveBody: ReserveBody, fn: (reservation: QuotaReservation) = Promise<T>, options: WithReservationOptions<T> = {},): Promise<T>

Reserves quota, runs fn, then commits on success or releases on failure; the callback error is rethrown after the release.

NameTypeDefaultRequiredDescription
reserveBodyReserveBodyyesCost, tokens, scope and lifetime to reserve.
fn(reservation: QuotaReservation)Promise<T>, options: WithReservationOptions<T> = {},noWork to run under the reservation.

Returns: Promise<T>. Result of fn.

Functions​

tokenUnits​

tokenUnits(input: number, output: number, detail: { cached?: number; reasoning?: number } = {}): TokenUnits

Token units following the FinOps rule: input_tokens already includes the cached tokens and output_tokens already includes the reasoning tokens (provider totals, never added on top).

NameTypeDefaultRequiredDescription
inputnumberyesTotal input tokens.
outputnumberyesTotal output tokens.
detail{ cached?: number; reasoning?: number }{}noCached and reasoning tokens, each at most its total.

Returns: TokenUnits. The units, cached and reasoning fields only when not zero; throws RangeError when a part exceeds its total.

Raises: RangeError.