packages/cloud-frontend/content/api/credits.mdx
import { Callout, Tabs } from "@/docs/components";
Manage your credits, billing settings, and view usage.
<Callout type="info"> **API Key Support:** All billing endpoints support API key authentication. This enables: - **Developers** to monitor usage and manage billing programmatically - **AI Agents** to autonomously manage their own budgets and ensure continuous operation - **Automation** to configure auto-top-up settings without manual intervention </Callout>Get your current credit balance.
| Parameter | Type | Description |
|---|---|---|
fresh | boolean | Set to true to bypass cache (use after payment confirmation) |
{
"balance": 50.0
}
Get comprehensive credit status including organization balance, agent budgets, app earnings, and redeemable earnings.
{
"success": true,
"organization": {
"id": "org_abc123",
"name": "My Organization",
"creditBalance": 50.0,
"autoTopUpEnabled": false,
"autoTopUpThreshold": null,
"autoTopUpAmount": null,
"hasPaymentMethod": true
},
"agents": [
{
"id": "agent_xyz789",
"name": "My Assistant",
"isPublic": false,
"monetizationEnabled": false,
"hasBudget": true,
"allocated": 10.0,
"spent": 2.5,
"available": 7.5,
"dailyLimit": 5.0,
"dailySpent": 1.0,
"dailyRemaining": 4.0,
"isPaused": false,
"pauseReason": null,
"totalEarnings": 0,
"totalRequests": 150
}
],
"agentsSummary": {
"total": 3,
"withBudget": 2,
"paused": 0,
"totalAllocated": 20.0,
"totalSpent": 5.0,
"totalAvailable": 15.0
},
"apps": [
{
"id": "app_def456",
"name": "Customer Portal",
"slug": "customer-portal",
"monetizationEnabled": true,
"inferenceMarkupPercentage": 20,
"totalCreatorEarnings": 125.5,
"totalPlatformRevenue": 31.38
}
],
"earnings": {
"availableBalance": 125.5,
"totalEarned": 200.0,
"totalRedeemed": 74.5,
"totalPending": 0,
"breakdown": {
"miniapps": 100.0,
"agents": 75.0,
"mcps": 25.0
}
},
"recentTransactions": [
{
"id": "txn_abc123",
"type": "usage",
"amount": -0.05,
"description": "Chat completion (gpt-4o)",
"createdAt": "2024-01-15T10:30:00Z"
}
],
"pricing": {
"creditsPerDollar": 100,
"minimumTopUp": 5.0,
"x402Enabled": true
}
}
Create a Stripe checkout session to purchase credits.
{
"amount": 50.0
}
{
"success": true,
"checkoutUrl": "https://checkout.stripe.com/c/pay/cs_xxx...",
"sessionId": "cs_xxx..."
}
Redirect the user to checkoutUrl to complete the payment.
Verify a completed payment and add credits.
{
"sessionId": "cs_xxx..."
}
{
"success": true,
"creditsAdded": 50.0,
"newBalance": 100.0
}
Get billing configuration including auto-top-up settings.
{
"success": true,
"settings": {
"autoTopUp": {
"enabled": true,
"amount": 25.0,
"threshold": 5.0,
"hasPaymentMethod": true
},
"limits": {
"minAmount": 1,
"maxAmount": 1000,
"minThreshold": 0,
"maxThreshold": 1000
}
}
}
Configure auto-top-up to automatically replenish credits when balance falls below a threshold.
<Callout type="info"> **Why Auto-Top-Up?** AI agents operating autonomously need uninterrupted access to credits. Auto-top-up ensures your agents never stop working due to insufficient balance. </Callout>{
"autoTopUp": {
"enabled": true,
"amount": 25.0,
"threshold": 5.0
}
}
| Parameter | Type | Description |
|---|---|---|
autoTopUp.enabled | boolean | Enable or disable auto-top-up |
autoTopUp.amount | number | Amount to charge when triggered ($1-$1000) |
autoTopUp.threshold | number | Balance threshold to trigger top-up ($0-$1000) |
{
"success": true,
"message": "Billing settings updated successfully",
"settings": {
"autoTopUp": {
"enabled": true,
"amount": 25.0,
"threshold": 5.0,
"hasPaymentMethod": true
}
}
}
Manually trigger an auto-top-up check. Useful for testing or when you want to top up immediately.
{
"success": true,
"message": "Auto top-up successful! Added $25.00",
"amount": 25.0,
"previousBalance": 3.5,
"newBalance": 28.5
}
Get credit transaction history for your organization.
| Parameter | Type | Description |
|---|---|---|
limit | integer | Max results returned (default: 100) |
hours | integer | Limit results to the last N hours |
{
"transactions": [
{
"id": "txn_abc123",
"organization_id": "org_123",
"type": "usage",
"amount": -100,
"description": "Text to speech generation",
"metadata": null,
"stripe_payment_intent_id": null,
"created_at": "2024-01-15T10:30:00.000Z"
}
],
"total": 1,
"period": {
"start": "2024-01-15T09:30:00.000Z",
"end": "2024-01-15T10:30:00.000Z"
}
}
Note: offset is not supported for this endpoint.
For cryptocurrency payments, use the crypto payment endpoints:
<div className="api-endpoint"> <span className="method-badge method-badge-post">POST</span> <span className="path">/api/crypto/payments</span> </div>Create a crypto payment request.
<div className="api-endpoint"> <span className="method-badge method-badge-get">GET</span> <span className="path">/api/crypto/status</span> </div>Check crypto payment status.
Pricing is calculated from current model/provider configuration and usage. Use the billing dashboard, API Explorer, and model catalog endpoints for live rates rather than copying static numbers from this page.
<Callout type="info"> Actual pricing is calculated based on model and token usage. Check the [Dashboard](/dashboard/billing) for real-time pricing. </Callout>