Resource Charges API
Charge users for any pay-per-use resource or service
Resource Charges API
Charge users directly for any pay-per-use resource. Unlike AI Gateway monetization (percentage-based fees), resource charges transfer the full payment amount directly to your wallet.
Perfect for Plaid API calls, file processing, data API access, or any metered service.
How It Works
- User consumes a resource in your application
- You call the charge API with the amount
- Payment is signed using the user's authorized token
- Settlement completes instantly to your merchant wallet
- You deliver the resource to the user
Endpoint
Authentication
The user must have authorized spending via one of these methods:
| Method | Header | Description |
|---|---|---|
| API Token | X-Agnic-Token: agnic_tok_... | User's API token |
| OAuth | Authorization: Bearer agnic_at_... | OAuth access token |
Request
Headers
| Header | Required | Description |
|---|---|---|
X-Merchant-Id | Yes | Your Privy DID (did:privy:...) |
X-Merchant-Wallet | Yes | Your wallet address (0x...) |
Body
| Field | Type | Required | Description |
|---|---|---|---|
amount | string | Yes | USDC amount in atomic units (6 decimals). "100000" = $0.10 |
reference | string | No | Your correlation ID for tracking |
description | string | No | Description for logging/audit |
Amount is in atomic units (6 decimals). To charge $1.00, use "1000000". To charge $0.01, use "10000".
Response
Success (200)
Error Responses
Missing Headers (400)
Invalid Amount (400)
Limit Exceeded (400)
Network Not Allowed (400)
Code Examples
Python
TypeScript / JavaScript
cURL
Use Cases
Plaid API Integration
Charge users when they link bank accounts or fetch transactions:
File Processing Service
Charge per file or per MB processed:
Data API Access
Charge per query or per record:
Amount Conversion
| USD Amount | Atomic Units | Code |
|---|---|---|
| $0.01 | 10000 | "10000" |
| $0.05 | 50000 | "50000" |
| $0.10 | 100000 | "100000" |
| $0.50 | 500000 | "500000" |
| $1.00 | 1000000 | "1000000" |
| $5.00 | 5000000 | "5000000" |
Formula: atomic_units = usd_amount * 1,000,000
Spending Limits
User tokens have spending limits that apply to resource charges:
| Limit Type | Description |
|---|---|
| Per-Transaction | Maximum amount for a single charge |
| Daily | Total charges allowed per day |
| Monthly | Total charges allowed per month |
If a charge exceeds any limit, the API returns an error with details about the limit and current spending.
Viewing Your Earnings
Track resource charge earnings at pay.agnic.ai/earnings:
- Resource Charges Total: Sum of all charges received
- Total Charges: Number of successful charges
- Charge History: Date, amount, reference, status, and transaction hash
Resource charges appear separately from AI Gateway fee earnings, making it easy to track different revenue streams.
Constraints
| Constraint | Details |
|---|---|
| Network | Base mainnet only (no testnet) |
| Currency | USDC only |
| Settlement | Instant to merchant wallet |
| Minimum | No minimum (but gas costs apply) |
Best Practices
- Charge before delivering - Always confirm payment success before providing the resource
- Use references - Include meaningful references for reconciliation
- Handle failures gracefully - Show users clear error messages for limit or balance issues
- Consider UX - Inform users of costs before charging