latestOpenAPI 3.1.02026-08-218667571.2 MB

a8ca30023371

Admin APIs
clients

Buy Grants

Create a token purchase for the client with comprehensive validation and error handling.

This endpoint provides a production-ready token purchase flow supporting:

  • Credit card payments via Stripe PaymentIntent
  • ACH payments via Stripe PaymentIntent
  • Invoice payments for eligible plans

The endpoint implements proper:

  • Input validation and sanitization
  • User permission checks
  • Business rule enforcement
  • Comprehensive error handling
  • Audit logging

Args: client_id: UUID string of the client to purchase tokens for request: Purchase request with token_amount, payment_method, and optional fields user: Authenticated user making the request

Returns: Dict containing purchase details: - payment_method: The payment method used - payment_id: Internal payment tracking ID - token_amount: Number of tokens purchased - total_amount: Total cost in USD - For Card/ACH: PaymentIntent with client_secret for frontend processing - For Invoice: Invoice details with hosted_invoice_url

Raises: 400: Invalid input parameters or business rule violations 401: User not authenticated 403: User lacks permission for this client 404: Client plan or tokens not found 422: Business logic violations 500: System errors 502: External service (Stripe) errors

post/api/v1/admin/clients/{client_id}/buy-grants

Path parameters

client_idstring required

Request body

token_amountnumber required
payment_methodstring required
is_recurringboolean
success_urlstring nullable
cancel_urlstring nullable
token_idstring uuid nullable

Optional token ID to use for purchase. If not provided, the primary active token will be used.

token_purchase_type'primary' | 'mcp' | 'mcp_primary' nullable

Optional token purchase type. If 'mcp_primary' (or legacy 'mcp') is provided and token_id is not set, the backend will use the MCP Primary token id from environment configuration.

Response

Successful Response

object required