Skip to main content

enterprise_ai.quotas

Source: sdks/python/src/enterprise_ai/quotas/__init__.py. Back to the Python 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.

Model Reservation​

An open reservation. commit or release once.

Fields:

NameTypeRequiredDescription
clientQuotasClientyes/v1/quotas.
idstryesIdentifier of the reservation returned by the server.
datadict[str, Any]noAnswer of the reservation call as returned by the server.
statestrnoreserved, then committed after a normal exit or released after an exception.
actualAnynoMeasured {cost, tokens} set by commit, sent at the end of the block; None when not set.

Reservation.commit​

commit(cost: Any = None, tokens: int | None = None) -> Any

Mark the measured cost and tokens; sent when the block exits.

NameTypeDefaultRequiredDescription
costAnyNonenoMeasured cost, as a decimal string or number, optional.
tokensint | NoneNonenoMeasured number of tokens, optional.

Returns: Any. The recorded {cost, tokens}, or None when neither is given.

Class QuotasClient​

/v1/quotas.

Resource

QuotasClient.areservation​

async areservation(cost: Any = '0', tokens: int = 0, **kwargs: Any) -> AsyncIterator[Reservation]

Async variant of :meth:reservation.

NameTypeDefaultRequiredDescription
costAny'0'noCost to reserve, as a decimal string or number (default "0").
tokensint0noNumber of tokens to reserve (default 0).
**kwargsAnynoOptions of reserve: scope, ttl_seconds, idempotency_key.

Returns: AsyncIterator[Reservation]. A Reservation: An open reservation. commit or release once.

QuotasClient.commit​

commit(reservation_id: str, cost: number | string = None, tokens: int | None = None) -> Any

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
reservation_idstryesIdentifier (UUID) of the reservation returned by POST /v1/quotas/reserve.
costnumber | stringNonenoMeasured cost in the currency of the reservation, at least 0, default 0.
tokensint | NoneNonenoMeasured tokens, at least 0, default 0.

Returns: Any. Decoded JSON answer of the operation "Commit a reservation".

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

QuotasClient.create​

create(name: str, scope_type: str, scope_value: str | None = None, limit_cost: number | string | null = None, limit_tokens: int | None = None, period: str = 'month', **extra: Any) -> Any

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
namestryesName of the quota, 1 to 200 characters.
scope_typestryesWhat the quota limits: tenant (default), project, agent, user, model or provider.
scope_valuestr | NoneNonenoIdentifier of the project, agent, user, model or provider; required unless scope_type is tenant, where it must be null.
limit_costnumber | string | nullNonenoCost limit per window, at least 0, in currency.
limit_tokensint | NoneNonenoToken limit per window, at least 0.
periodstr'month'noWindow of the limit: request (each call), run, hour, day or month (default), in UTC.
**extraAnynoExtra fields merged into the request body.

Returns: Any. Decoded JSON answer of the operation "Create a quota".

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

QuotasClient.delete​

delete(quota_id: str) -> Any

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
quota_idstryesIdentifier (UUID) of the quota.

Returns: Any. Decoded JSON answer of the operation "Delete a quota".

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

QuotasClient.list​

list(**page: Any) -> Any

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
**pageAnynoPagination options passed to the listing: limit (maximum number of items per page) and cursor (the next_cursor of the previous page). Iterating the returned page follows every cursor.

Returns: Any. Decoded JSON answer of the operation "List the quotas".

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

QuotasClient.release​

release(reservation_id: str) -> Any

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
reservation_idstryesIdentifier (UUID) of the reservation.

Returns: Any. Decoded JSON answer of the operation "Release a reservation".

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

QuotasClient.replace​

replace(quota_id: str, quota: dict[str, Any]) -> Any

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
quota_idstryesIdentifier (UUID) of the quota.
quotadict[str, Any]yesInitial quota of the project; the defaults of the quota apply when omitted.

Returns: Any. Decoded JSON answer of the operation "Replace a quota".

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

QuotasClient.reservation​

reservation(cost: Any = '0', tokens: int = 0, **kwargs: Any) -> Iterator[Reservation]

Reserve, then commit on success or release on error (sync client).

NameTypeDefaultRequiredDescription
costAny'0'noCost to reserve, as a decimal string or number (default "0").
tokensint0noNumber of tokens to reserve (default 0).
**kwargsAnynoOptions of reserve: scope, ttl_seconds, idempotency_key.

Returns: Iterator[Reservation]. A Reservation: An open reservation. commit or release once.

QuotasClient.reserve​

reserve(cost: number | string = '0', tokens: int = 0, scope: dict[str, Any] | None = None, ttl_seconds: int | None = None, idempotency_key: str | None = None) -> Any

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
costnumber | string'0'noCost to reserve in the tenant currency, 0 to 10^15, default 0; converted to the currency of each quota.
tokensint0noTokens to reserve, 0 to 2^62, default 0.
scopedict[str, Any] | NoneNonenoWho the call is for: keys project, agent, user, model, provider, run (or the same with _id), matched against the quota scopes.
ttl_secondsint | NoneNonenoLifetime of the reservation in seconds, 1 to 86400; default the tenant reservation_ttl_seconds (900). An expired reservation is released.
idempotency_keystr | NoneNonenoIdempotency-Key header: a retry with the same key replays the first answer.

Returns: Any. Decoded JSON answer of the operation "Reserve cost and tokens".

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

QuotasClient.usage​

usage(**filters: Any) -> Any

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
**filtersAnynoQuery parameters such as agent, project or run.

Returns: Any. Decoded JSON answer of the operation "Read the quota consumption".

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