Skip to content

Initialize Tenant Credits

POST
/api/v1/admin/billing/initialize-credits

Idempotently seed a tenant’s Redis credit balance (operator-only).

CreditManager.initialize_credits runs only from the Stripe checkout webhook, so enterprise (“custom invoicing”) and operator/manually provisioned tenants never get a balance — which breaks the forge credit pre-check and every hard credit gate. This endpoint back-fills them without a Stripe charge. Idempotent: it never resets an already-seeded tenant (see ensure_credits_initialized).

Args: body: Target tenant and optional plan override. user: The authenticated platform operator (injected). session: DB session for the plan lookup.

Changing a plan and granting credits are separate here. seeded reports the grant, which happens only for a never-provisioned tenant; plan_cache_updated reports the plan, which is written every time so that an operator plan change actually reaches the feature gates.

Returns: {tenant_id, plan, seeded, plan_row_updated, plan_cache_updated}seeded is False when the balance already existed.

Raises: HTTPException 400: Invalid tenant id or plan. HTTPException 404: Tenant not found (when plan is omitted). HTTPException 503: Redis-backed credit manager unavailable, or the plan could not be recorded where the gates read it.

Authorizations

Request Body required

Request body for operator credit initialization.

object
plan
Any of:
string
tenant_id
required

Tenant UUID to initialize.

string

Responses

200

Successful Response

object
key
additional properties
any

422

Validation Error

object
detail
Array<object>
object
ctx
object
input
loc
required
Array
msg
required
string
type
required
string