deduct_credits
Deduct (spend) credits from an existing user, identified by user_email (checked first) or user_id. Fails with 400 INSUFFICIENT_CREDITS (nothing deducted) or 404 USER_NOT_FOUND. Pass idempotency_key on anything an agent might retry: a replay returns the original transaction with idempotent_replay: true and charges nothing more. Without a key, every call deducts again. auto_topup_triggered: true means the balance fell below the user's auto top-up threshold and a saved-card purchase started. 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 | Yes | Credits to deduct (positive) | |
| reason | No | Reason, shown in the ledger | |
| api_key | No | Cred API key (optional if set via the x-api-key header) | |
| user_id | No | External user ID | |
| project_id | No | Cred project ID (optional; the API key already identifies the project) | |
| user_email | No | User email (checked first) | |
| reference_id | No | Your reference, e.g. a job ID (also lets refund_credits find it) | |
| x402_payment | No | Base64 x402 PaymentPayload, only when a previous call failed with an x402 PaymentRequired because the account is out of CRD | |
| credit_type_id | Yes | Credit type to deduct from | |
| idempotency_key | No | Unique key for this deduction (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. |