Skip to content

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:

ServiceCredits per RequestDescription
Chat API0.06 per 1k tokensBased on total tokens processed
Image Generation1.5 creditsPer image generated
Video Generation7.5 creditsPer video created
Book Grading3.0 creditsPer grading request
Detection Tools0.15-0.2 creditsPer detection request
EduFi Tutoring10 creditsPer tutoring session
Blockchain Tools0.5-2.0 creditsVaries by complexity
Writing Tools0.2-0.5 creditsPer 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

ParameterTypeDescription
limitnumberNumber of records to return (default: 50)
offsetnumberNumber of records to skip
startDatestringISO date string for start of range
endDatestringISO date string for end of range
endpointstringFilter 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

PackagePrice (USDT)CreditsBonus
Starter$10100-
Basic$50500-
Pro$1001,10010%
Business$5006,00020%
Enterprise$1,00013,00030%

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

  1. Batch Operations

    • Group similar requests when possible
    • Use bulk endpoints where available
  2. Optimize Parameters

    • Use appropriate quality settings
    • Avoid unnecessary high-resolution outputs
    • Limit token counts in chat requests
  3. 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 threshold
  • credits.purchased - Credits successfully added
  • credits.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'
)

Next Steps

Revolutionizing Education with AI and Web3