Credit Management API
Manage and monitor your API credit usage programmatically.
Overview
The Credit Management API allows you to check balances, view usage history, and purchase credits programmatically. All credit operations are tied to your API key.
Credit Balance
Get Current Balance
http
GET /api/developer/credits
Authorization: Bearer inspira_your_api_key_here
Response
json
{
"success": true,
"balance": 500.5,
"currency": "credits",
"lastUpdated": "2025-01-06T12:00:00.000Z"
}
Credit Usage
Understanding Credit Costs
Different API endpoints consume different amounts of credits:
Service | Credits per Request | Description |
---|---|---|
Chat API | 0.06 per 1k tokens | Based on total tokens processed |
Image Generation | 1.5 credits | Per image generated |
Video Generation | 7.5 credits | Per video created |
Book Grading | 3.0 credits | Per grading request |
Detection Tools | 0.15-0.2 credits | Per detection request |
EduFi Tutoring | 10 credits | Per tutoring session |
Blockchain Tools | 0.5-2.0 credits | Varies by complexity |
Writing Tools | 0.2-0.5 credits | Per analysis |
Credit Calculation Examples
Chat API
Tokens used: 5,000
Credits consumed: 5,000 / 1,000 * 0.06 = 0.3 credits
Image Generation
1 image request = 1.5 credits
4 images = 6.0 credits
Usage History
Get Usage History
http
GET /api/developer/usage
Authorization: Bearer inspira_your_api_key_here
Query Parameters
Parameter | Type | Description |
---|---|---|
limit | number | Number of records to return (default: 50) |
offset | number | Number of records to skip |
startDate | string | ISO date string for start of range |
endDate | string | ISO date string for end of range |
endpoint | string | Filter by specific endpoint |
Response
json
{
"success": true,
"usage": [
{
"id": "usage_123456",
"timestamp": "2025-01-06T12:00:00.000Z",
"endpoint": "/api/rest/generate-image",
"method": "POST",
"credits": 1.5,
"status": 200,
"metadata": {
"model": "stable-diffusion",
"size": "1024x1024"
}
}
],
"pagination": {
"total": 150,
"limit": 50,
"offset": 0
}
}
Purchase Credits
Create Purchase Order
http
POST /api/developer/purchase
Authorization: Bearer inspira_your_api_key_here
Content-Type: application/json
Request Body
json
{
"amount": 100,
"currency": "USDT"
}
Response
json
{
"success": true,
"orderId": "order_123456",
"amount": 100,
"credits": 500,
"paymentAddress": "0x...",
"expiresAt": "2025-01-06T13:00:00.000Z",
"status": "pending"
}
Verify Purchase
http
GET /api/developer/purchase/:orderId
Authorization: Bearer inspira_your_api_key_here
Credit Packages
Available Packages
Package | Price (USDT) | Credits | Bonus |
---|---|---|---|
Starter | $10 | 100 | - |
Basic | $50 | 500 | - |
Pro | $100 | 1,100 | 10% |
Business | $500 | 6,000 | 20% |
Enterprise | $1,000 | 13,000 | 30% |
Package Pricing
json
{
"packages": [
{
"id": "starter",
"name": "Starter Package",
"price": 10,
"credits": 100,
"bonus": 0
},
{
"id": "pro",
"name": "Pro Package",
"price": 100,
"credits": 1100,
"bonus": 100
}
]
}
Credit Monitoring
Set Low Balance Alert
http
POST /api/developer/alerts
Authorization: Bearer inspira_your_api_key_here
Content-Type: application/json
json
{
"type": "low_balance",
"threshold": 50,
"webhookUrl": "https://your-app.com/webhooks/low-credits"
}
Usage Analytics
http
GET /api/developer/analytics
Authorization: Bearer inspira_your_api_key_here
Response
json
{
"success": true,
"period": "last_30_days",
"totalCreditsUsed": 1523.4,
"averageDaily": 50.78,
"topEndpoints": [
{
"endpoint": "/api/rest/generate-image",
"credits": 450,
"percentage": 29.5
},
{
"endpoint": "/api/rest/chat",
"credits": 380.4,
"percentage": 25.0
}
],
"dailyUsage": [
{
"date": "2025-01-06",
"credits": 65.3
}
]
}
Credit Headers
All API responses include credit information in headers:
http
X-Credits-Used: 1.5
X-Credits-Remaining: 498.5
X-Credits-Reset: 2025-01-07T00:00:00.000Z
Best Practices
Efficient Credit Usage
Batch Operations
- Group similar requests when possible
- Use bulk endpoints where available
Optimize Parameters
- Use appropriate quality settings
- Avoid unnecessary high-resolution outputs
- Limit token counts in chat requests
Monitor Usage
- Set up usage alerts
- Review analytics regularly
- Track credit consumption by endpoint
Credit Conservation
javascript
// Example: Optimize image generation
const optimizedRequest = {
prompt: "A beautiful sunset",
size: "512x512", // Smaller size uses fewer credits
quality: "standard", // Standard quality is more economical
n: 1 // Generate one image at a time
};
Error Handling
Insufficient Credits
json
{
"error": "Insufficient credits",
"code": "INSUFFICIENT_CREDITS",
"required": 10,
"available": 5.5,
"purchaseUrl": "https://app.inspirahub.net/developer?tab=credits"
}
Credit Limit Exceeded
json
{
"error": "Monthly credit limit exceeded",
"code": "CREDIT_LIMIT_EXCEEDED",
"limit": 10000,
"used": 10050,
"resetDate": "2025-02-01T00:00:00.000Z"
}
Webhooks
Credit Events
Configure webhooks for credit-related events:
credits.low
- Balance falls below thresholdcredits.purchased
- Credits successfully addedcredits.expired
- Credits expired (if applicable)
json
{
"event": "credits.low",
"timestamp": "2025-01-06T12:00:00.000Z",
"data": {
"balance": 45.5,
"threshold": 50,
"apiKeyId": "key_123456"
}
}
SDK Methods
JavaScript/TypeScript
javascript
// Check balance
const balance = await client.credits.getBalance();
// Get usage history
const usage = await client.credits.getUsage({
limit: 100,
startDate: '2025-01-01'
});
// Purchase credits
const order = await client.credits.purchase({
amount: 100,
currency: 'USDT'
});
Python
python
# Check balance
balance = client.credits.get_balance()
# Get usage history
usage = client.credits.get_usage(
limit=100,
start_date='2025-01-01'
)
# Purchase credits
order = client.credits.purchase(
amount=100,
currency='USDT'
)