refund_credits
Refund or reverse credits. MOVES MONEY for purchases: with purchase_id or stripe_payment_intent_id it refunds the Stripe charge (prorated when partial; refund_payment: false skips the money) and claws the purchased credits back. With transaction_id (or reference_id = latest matching transaction) it reverses that ledger entry: an issue is clawed back, a deduct is returned to the user. Pass exactly one source. amount refunds part (default: all). idempotency_key is required here: retry with the same key to get the first result (idempotent_replay: true). Errors: 404 PURCHASE_NOT_FOUND / TRANSACTION_NOT_FOUND, 409 ALREADY_REFUNDED, 400 REFUND_EXCEEDS_ORIGINAL, 400 INSUFFICIENT_CREDITS (user already spent them), 400 NOT_REFUNDABLE (redeem/escrow entries), 402 STRIPE_REFUND_FAILED (no credits changed). Costs 1 CRD (platform credit) per call, charged even when the call is then rejected (a 429 RATE_LIMITED costs nothing). Error results include request_id; quote it to support.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| amount | No | Credits to refund (default: the full original amount) | |
| reason | No | Reason, shown in the ledger | |
| api_key | No | Cred API key (optional if set via the x-api-key header) | |
| metadata | No | Extra metadata stored on the refund transaction | |
| project_id | No | Cred project ID (optional; the API key already identifies the project) | |
| purchase_id | No | Cred purchase ID (refunds the payment + credits) | |
| reference_id | No | Reverse the latest non-refund transaction with this reference_id | |
| x402_payment | No | Base64 x402 PaymentPayload, only when a previous call failed with an x402 PaymentRequired because the account is out of CRD | |
| refund_payment | No | Purchases only: false reverses credits without refunding money (default true) | |
| transaction_id | No | Ledger transaction ID to reverse | |
| idempotency_key | Yes | Unique key for this refund (max 255 chars). Retrying with the same key and same arguments returns the first result instead of repeating it; reusing it for different arguments fails with 409 IDEMPOTENCY_KEY_REUSED. Generate a fresh key (e.g. a UUID) per intended operation and reuse it only to retry that operation. | |
| stripe_payment_intent_id | No | Stripe pi_… of the purchase (alternative to purchase_id) |