Pricing
Configure flexible pricing strategies for your x402-enabled database.
Overview
The x402 Gateway supports multiple pricing strategies to match your business model. Choose the approach that best aligns with your database usage patterns and value proposition.
Current Implementation: Row-Based Pricing
The default pricing model charges based on the number of rows returned by queries.
Configuration
POST /api/providers/:id/pricing
{
"basePricePer1000Rows": 1.0, // Base price in USDC per 1000 rows
"markupMultiplier": 2.0 // Markup multiplier
}Cost Calculation
Final Cost = (rowCount / 1000) × basePricePer1000Rows × markupMultiplierExamples
Configuration:
Base price: $1.00 per 1000 rows
Markup: 2.0x
Query Costs:
10
(10/1000) × $1.00 × 2.0
$0.02
500
(500/1000) × $1.00 × 2.0
$1.00
5,000
(5000/1000) × $1.00 × 2.0
$10.00
100,000
(100000/1000) × $1.00 × 2.0
$200.00
When to Use
Analytics databases with predictable row counts
Read-heavy workloads where data volume matters
Simple pricing that's easy to explain to users
Content APIs serving articles, products, or records
Alternative Pricing Models
While not yet implemented in the gateway, you can configure these strategies by adjusting your pricing parameters:
1. Complexity-Based Pricing
Charge based on PostgreSQL query cost from EXPLAIN plan.
Formula:
Cost = (explainCost / 1000) × basePrice × markupExample Configuration:
{
"basePricePerCost": 0.015,
"markupMultiplier": 1.5
}Use Cases:
Complex analytical queries with joins
Databases with varying query complexity
Incentivize query optimization
Pricing Examples:
Simple SELECT
10
$0.0002
JOIN 2 tables
5,000
$0.11
Complex aggregation
50,000
$1.13
2. Data Transfer Pricing
Charge based on the size of data returned (in bytes/MB).
Formula:
Cost = (dataSizeMB) × pricePerMB × markupExample Configuration:
{
"pricePerMB": 0.10,
"markupMultiplier": 2.0
}Use Cases:
Image or file storage databases
APIs returning large JSON payloads
Video metadata or blob storage
Pricing Examples:
1 KB
(0.001 MB) × $0.10 × 2.0
$0.0002
10 MB
10 × $0.10 × 2.0
$2.00
100 MB
100 × $0.10 × 2.0
$20.00
3. Query Type Pricing
Different prices for different SQL operations.
Example Configuration:
{
"selectPrice": 0.01,
"insertPrice": 0.05,
"updatePrice": 0.05,
"deletePrice": 0.10,
"markupMultiplier": 1.5
}Use Cases:
Databases with mixed read/write workloads
Discourage expensive write operations
Incentivize read-only queries
Pricing Examples:
SELECT
$0.01
$0.015
INSERT
$0.05
$0.075
UPDATE
$0.05
$0.075
DELETE
$0.10
$0.15
4. Time-Based Pricing
Charge based on query execution time.
Formula:
Cost = (executionTimeMs / 1000) × pricePerSecond × markupExample Configuration:
{
"pricePerSecond": 0.05,
"markupMultiplier": 2.0
}Use Cases:
CPU-intensive queries
Long-running analytics
Databases with execution time SLAs
Pricing Examples:
50ms
(50/1000) × $0.05 × 2.0
$0.005
1 second
(1000/1000) × $0.05 × 2.0
$0.10
30 seconds
(30000/1000) × $0.05 × 2.0
$3.00
5. Hybrid Pricing
Combine multiple factors for comprehensive pricing.
Formula:
Cost = (rowCost + complexityCost + sizeCost) × markupExample Configuration:
{
"rowPrice": 0.001, // per row
"complexityPrice": 0.00001, // per cost unit
"sizePrice": 0.05, // per MB
"markupMultiplier": 1.5
}Use Cases:
Enterprise databases with diverse workloads
Maximum control over pricing
Value-based pricing models
Example Calculation:
Query: SELECT * FROM large_table LIMIT 5000
- Rows: 5,000
- EXPLAIN cost: 10,000
- Size: 5 MB
rowCost = 5000 × $0.001 = $5.00
complexityCost = 10000 × $0.00001 = $0.10
sizeCost = 5 × $0.05 = $0.25
Total = ($5.00 + $0.10 + $0.25) × 1.5 = $8.03Markup Multiplier
The markup multiplier allows you to:
Cover operational costs (infrastructure, monitoring, support)
Generate profit margins on top of base costs
Differentiate pricing tiers (premium vs. standard)
Adjust for market conditions without changing base prices
Common Markup Strategies
1.0x
Cost recovery only
0%
1.5x
Standard SaaS pricing
33%
2.0x
Premium service
50%
3.0x
Enterprise/white-glove
67%
Pricing Best Practices
Start Conservative
Begin with higher prices and adjust based on:
Market feedback
Competitor analysis
Customer acquisition cost
Operational costs
Monitor Usage Patterns
Track:
Average query costs
Peak usage times
Common query patterns
Agent spending behavior
Communicate Clearly
Provide agents with:
Cost estimation before queries
Historical spending data
Pricing tier documentation
Cost optimization tips
Offer Predictability
Consider:
Maximum query costs
Daily spending caps
Volume discounts
Prepaid credits
Cost Estimation
Before executing queries, the gateway provides cost estimates:
{
"estimatedCost": "2.45",
"basedOn": "row_count",
"confidence": "high"
}Confidence Levels:
High: Row count or data size can be predicted accurately
Medium: EXPLAIN cost estimates available
Low: Complex queries with unpredictable results
Volume Discounts
Coming soon: Automatic volume discounts for high-usage agents.
Example Tiers:
{
"tier1": { "threshold": 0, "discount": 0 },
"tier2": { "threshold": 1000, "discount": 0.1 },
"tier3": { "threshold": 10000, "discount": 0.2 },
"tier4": { "threshold": 100000, "discount": 0.3 }
}Real-World Pricing Examples
Yearn Finance Case Study
Database: Kong indexer data (24-hour retention) Update Frequency: Every 15 minutes Average Query: 5,000 rows
Pricing Configuration:
{
"basePricePer1000Rows": 1.0,
"markupMultiplier": 2.0
}Monthly Costs:
Traditional Neon: $207/month
SerenDB + x402: ~$30/month
Savings: 85%
Analytics API
Database: User behavior analytics Average Query: 10,000 rows (complex aggregations) Query Volume: 1,000 queries/day
Pricing Configuration:
{
"basePricePer1000Rows": 0.5,
"markupMultiplier": 2.5
}Daily Revenue:
Per query: (10,000/1000) × $0.50 × 2.5 = $12.50
Daily: $12.50 × 1,000 = $12,500
Monthly: $375,000
Updating Pricing
Update pricing at any time:
curl -X POST https://x402.serendb.com/api/providers/:id/pricing \
-H "X-API-Key: your_api_key" \
-H "Content-Type: application/json" \
-d '{
"basePricePer1000Rows": 1.5,
"markupMultiplier": 2.0
}'Notes:
Changes take effect immediately for new queries
In-flight queries use previous pricing
Agents are notified of pricing changes via API responses
Need Help?
Get Started - Quick start guide
API Reference - Complete API documentation
Examples - Pricing implementation examples
GitHub Issues: https://github.com/serenorg/serenai-x402/issues
Last updated