Payment Flow Guide
ASG Agent Cloud uses a 2-step payment flow based on the HTTP 402 Payment Required standard. This guide shows you exactly how it works with copy-paste curl examples.How It Works
Step 1: Request a Quote
Call any billable tool without a payment proof. The gateway returns a402 Payment Required response with a quote and payment instructions.
402 Response
Step 2: Pay and Retry
After sending USDC on Solana mainnet, retry the same tool call with your payment proof attached. ASG supports two methods:Method A: Body payment_proof (Primary)
Include the payment proof directly in the request body:
Method B: X-Payment Header (x402 Standard)
Encode the payment proof as base64 JSON and pass it in the X-Payment header:
Success Response (200)
Field Reference
| Field | Description | Example |
|---|---|---|
tx_ref | Solana transaction signature (base58) | 5x7Hk... |
amount_usdc | Amount in USDC (string) | "0.01" |
memo | Format: step_id:quote_id:nonce | "step_xyz:qt_abc123:1" |
network | Must be solana-mainnet | "solana-mainnet" |
idempotency_key | Unique per request (prevents double-billing) | "550e8400-..." |
quote_id | Quote ID from 402 response | "qt_abc123" |
Idempotency
Always include an
idempotency_key with your payment proof. If a request is retried with the same key, ASG returns the cached result without charging again. This prevents double-billing on network errors.Error Handling
| Error Code | Meaning | Action |
|---|---|---|
PAYMENT_REQUIRED | No payment attached | Get quote, pay, retry |
QUOTE_EXPIRED | Quote TTL exceeded | Request a new quote |
INVALID_PAYMENT | Payment verification failed | Check tx_ref and amount |
RATE_LIMITED | Too many requests | Back off and retry |
Next Steps
Tool Availability
See which tools are currently active
Billing Overview
Understand the billing model
SDK Examples
TypeScript examples with payment flow
Payment Contract
Full technical payment contract reference