Overview
This guide walks you through setting up ActumX and making your first x402 payment-protected API request. You’ll create an agent with a Solana wallet, generate an API key, and execute the complete x402 payment flow.ActumX enables AI agents to autonomously pay for API access using the x402 protocol - a standardized way to handle HTTP 402 (Payment Required) responses.
Prerequisites
- A modern browser or HTTP client (curl, Postman, etc.)
- Basic understanding of REST APIs
- 5 minutes of your time
Quick Start Steps
Create Account and Login
First, create an ActumX account and authenticate to receive a session cookie.
Response:
Sign Up
cURL
Sign In
After registration, sign in to receive your session cookie:cURL
Alternative: Use the Dashboard
Alternative: Use the Dashboard
Visit dashboard.actumx.app to create your account through the web interface. Then proceed to creating an agent via API or dashboard.
The session cookie is HTTP-only and automatically included in subsequent requests when using
-b cookies.txt with curl.Create Your First Agent
Create an agent with a Solana wallet. The system automatically generates a keypair and returns the private key (shown only once).Response:Response:
cURL
Understanding Agent Creation
Behind the scenes (fromapi/src/modules/agents/service.ts:46-59):- A new Solana keypair is generated using
@solana/web3.js - The public key is converted to base58 format
- The private key is base64-encoded for storage
- A unique ID with prefix
agent_is assigned - The agent is stored in PostgreSQL
Fund Your Agent on Devnet (Optional)
To test with actual Solana transactions, fund your agent with devnet SOL:cURL
Generate an API Key
API keys are used for programmatic access and MCP (Model Context Protocol) integration. They authenticate your requests without requiring session cookies.Response:Response:
cURL
API Key Security
Fromapi/src/modules/api-keys/service.ts:39-49:- Keys are cryptographically hashed before storage
- Only the first 14 characters (key prefix) are visible after creation
- Keys can be revoked but not deleted (soft delete pattern)
- Last usage timestamp is tracked automatically
List Your API Keys
cURL
Top Up Your Account Balance
Before making paid API requests, add credits to your account. ActumX uses a credit-based billing system where amounts are stored in cents.Request:Response:
cURL
amountCents: Amount to add in cents (1000 = $10.00)method: Payment method (e.g., “stripe”, “crypto”)
Check Your Balance
cURL
Make Your First Paid API Request
Now you’re ready to experience the x402 payment flow! This demonstrates how clients can automatically discover pricing, settle payments, and retry requests.Response (402 Payment Required):Response:Behind the scenes (from Response (200 Success):
Step 4.1: Initial Request (Receive 402)
Make a request to a protected endpoint without payment proof:cURL
The 402 response includes all information needed to settle the payment: the payment ID, price, and settlement endpoint. This is the core of the x402 protocol.
Step 4.2: Settle the Payment
Use thepaymentId from the 402 response to settle the payment:cURL
api/src/modules/x402/service.ts:250-335):- Verify the payment transaction exists
- Check sufficient balance (25 cents required)
- Create a debit entry in the credit ledger
- Update transaction status to “settled”
- Generate and return a receipt ID
Step 4.3: Retry with Payment Proof
Now retry the original request with payment headers:cURL
Congratulations! You’ve completed your first x402 payment flow. Your API request was fulfilled and the payment transaction was marked as “completed”.
Understanding the x402 Payment Flow
The three-phase payment flow is designed for automation and machine-readability:Payment States
Fromapi/src/modules/x402/service.ts:
| State | Description | Next Action |
|---|---|---|
| pending | Payment challenge issued, awaiting settlement | Client calls /v1/x402/settle |
| settled | Credits deducted, receipt issued | Client retries with payment proof |
| completed | Request fulfilled, payment consumed | Transaction complete |
Key Implementation Details
Cost Configuration (api/src/config/constants.ts:7-9):
- All amounts stored as integers in cents (no floating-point errors)
- Double-entry ledger: credits (top-ups) and debits (usage)
- Balance computed as
SUM(credits) - SUM(debits) - Transactional consistency via PostgreSQL
Common Issues and Solutions
402: Payment Required on Protected Endpoint
402: Payment Required on Protected Endpoint
Problem: You’re getting a 402 response when accessing
/v1/protected/quote.This is expected behavior! The 402 response contains payment details. Follow these steps:- Extract the
paymentIdfrom thex402object in the response - Call
POST /v1/x402/settlewith the payment ID - Get the
receiptIdfrom the settlement response - Retry your original request with headers:
x-payment-id: <paymentId>x-payment-proof: <receiptId>
402: Insufficient Balance
402: Insufficient Balance
Error Response:Solutions:
- Top up your account via
POST /v1/billing/top-up - Check your balance with
GET /v1/billing/summary - Ensure you’re adding enough credits (25 cents minimum per request)
401: Unauthorized or Invalid API Key
401: Unauthorized or Invalid API Key
404: Payment Not Found
404: Payment Not Found
Error Response:Solutions:
- Payment IDs expire after 10 minutes - make a new request to get a fresh payment ID
- Verify you’re using the correct
paymentIdfrom the 402 response - Ensure you’re authenticated with the same API key that received the payment challenge
402: Invalid Payment Proof
402: Invalid Payment Proof
Error Response:Solutions:
- Verify the
x-payment-idandx-payment-proofheaders match the values from settlement - Ensure you’ve called
/v1/x402/settlebefore retrying with proof - Check that the receipt hasn’t been used already (payments can only be consumed once)
Devnet Airdrop Failed
Devnet Airdrop Failed
Error: “failed to fund agent on devnet”Solutions:
- Solana devnet faucet has rate limits - wait a few minutes and retry
- Request smaller amounts (0.5 SOL instead of 1-2 SOL)
- Check Solana Status for devnet availability
- Use alternative devnet faucets if needed
Session Cookie Not Persisting
Session Cookie Not Persisting
Next Steps
System Architecture
Understand how ActumX components interact and the technology stack
x402 Protocol Deep Dive
Learn the full x402 specification and advanced payment flows
Creating Agents Guide
Advanced agent management, wallet security, and Solana integration
API Reference
Complete API documentation with all endpoints and parameters
What You’ve Learned
Account Management: Created an account and authenticated with session cookies
Agent Creation: Generated a Solana wallet agent with public/private keypair
API Key Generation: Created a hashed, secure API key for programmatic access
Credit System: Topped up account balance using the credit ledger system
x402 Payment Flow: Completed a full 3-phase payment cycle (challenge → settle → consume)