execute_swap
Swap a user's credits along a swap pair: deducts source_amount of the source type and credits the converted amount (after fee) in the target type. Errors: 400 INSUFFICIENT_CREDITS, 404 USER_NOT_FOUND, 400 outside min/max. On a bidirectional pair, direction "reverse" spends the target type for the source type at 1/rate (else 400 SWAP_NOT_BIDIRECTIONAL). Pass an idempotency_key so a retry replays the original swap (idempotent_replay: true); the same key on a different request is 409 IDEMPOTENCY_KEY_REUSED. 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 |
|---|---|---|---|
| api_key | No | Cred API key (optional if set via the x-api-key header) | |
| user_id | No | External user ID | |
| direction | No | Default forward | |
| project_id | No | Cred project ID (optional; the API key already identifies the project) | |
| user_email | No | User email (alternative) | |
| swap_pair_id | Yes | Swap pair ID | |
| x402_payment | No | Base64 x402 PaymentPayload, only when a previous call failed with an x402 PaymentRequired because the account is out of CRD | |
| source_amount | Yes | Credits to spend (in the target type when direction is reverse) | |
| idempotency_key | No | Unique key for this swap (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. |