Charges the user's saved Stripe payment method and immediately credits the account. The purchase is subject to the per-purchase and monthly limits set in the Agent API Billing configuration.
RequestPOST https://payments.builtwith.com/v1/billing/api-purchase
Send the scoped Agent Billing Key as Authorization: Bearer YOUR_AGENT_BILLING_KEY, and send a unique Idempotency-Key. Reuse that key only when retrying the identical purchase.
Request Body| Field | Type | Required | Description |
|---|
credits | number | Yes | Number of credits to purchase in fixed increments of 2,000. Must not exceed max_per_purchase or the remaining monthly allowance. |
Success Response (HTTP 200)| Field | Type | Description |
|---|
success | boolean | true |
credits_purchased | number | Credits added to the account. |
cost_usd | number | Amount charged in USD. |
payment_id | string | Stripe PaymentIntent ID for reconciliation. |
credits_available | number | Updated available credit balance after the purchase. |
Example RequestAuthorization: Bearer YOUR_AGENT_BILLING_KEY
Idempotency-Key: 72b7b97c-3b6d-4c64-9bbf-20fd2a931514
Content-Type: application/json
{ "credits": 2000 }Example Success Response{
"success": true,
"credits_purchased": 2000,
"cost_usd": 99.00,
"payment_id": "pi_3abc123xyz",
"credits_available": 10766
}Error Responses| HTTP | Meaning |
|---|
| 400 | Validation failure - missing idempotency key, credits not in 2,000 increments, per-purchase limit exceeded, or UTC monthly limit breached. |
| 401 | Missing or invalid Agent Billing Key. Includes a WWW-Authenticate challenge. |
| 402 | Stripe payment failed or no chargeable payment method on file. |
| 403 | A broad API key was supplied instead of the scoped billing key, or account billing is suspended. |
| 409 | Idempotency key is still in progress or was previously used with different input. |
| 405 | Method not allowed - endpoint requires POST. |