Skip to main content

Billing Overview

Retrieve an overview of your billing information, including current plan, usage, and upcoming charges.

Endpoint

GET /billing

Example Request

curl -X GET "https://api.astracollab.app/v1/billing" \
  -H "Authorization: Bearer your-api-key-here"

Response

{
  "success": true,
  "data": {
    "plan": {
      "id": "plan_studio",
      "name": "Studio",
      "price": 29.99,
      "currency": "USD",
      "billingCycle": "monthly",
      "features": {
        "storage": {
          "limit": 107374182400,
          "used": 53687091200,
          "unit": "bytes"
        },
        "requests": {
          "limit": 50000,
          "used": 12500,
          "unit": "requests_per_hour"
        },
        "fileSize": {
          "limit": 5368709120,
          "unit": "bytes"
        }
      }
    },
    "usage": {
      "currentPeriod": {
        "start": "2024-01-01T00:00:00Z",
        "end": "2024-01-31T23:59:59Z",
        "storage": {
          "used": 53687091200,
          "percentage": 50.0
        },
        "requests": {
          "used": 12500,
          "percentage": 25.0
        },
        "files": {
          "count": 1500,
          "limit": 10000
        }
      },
      "projected": {
        "storage": 64424509440,
        "requests": 15000,
        "files": 1800
      }
    },
    "billing": {
      "nextBillingDate": "2024-02-01T00:00:00Z",
      "currentBalance": 0.00,
      "currency": "USD",
      "paymentMethod": {
        "type": "card",
        "last4": "4242",
        "brand": "visa",
        "expiryMonth": 12,
        "expiryYear": 2025
      }
    },
    "limits": {
      "storage": {
        "limit": 107374182400,
        "used": 53687091200,
        "remaining": 53687091200,
        "unit": "bytes"
      },
      "requests": {
        "limit": 50000,
        "used": 12500,
        "remaining": 37500,
        "unit": "requests_per_hour"
      },
      "fileSize": {
        "limit": 5368709120,
        "unit": "bytes"
      },
      "apiKeys": {
        "limit": 10,
        "used": 3,
        "remaining": 7
      }
    }
  }
}

Response Object Properties

Plan Information

PropertyTypeDescription
idstringPlan identifier
namestringPlan name
pricenumberMonthly price
currencystringCurrency code
billingCyclestringBilling frequency
featuresobjectPlan features and limits

Usage Information

PropertyTypeDescription
currentPeriodobjectCurrent billing period usage
projectedobjectProjected usage for current period

Billing Information

PropertyTypeDescription
nextBillingDatestringNext billing date
currentBalancenumberCurrent account balance
currencystringCurrency code
paymentMethodobjectPayment method details

Limits Information

PropertyTypeDescription
storageobjectStorage limits and usage
requestsobjectAPI request limits
fileSizeobjectMaximum file size limit
apiKeysobjectAPI key limits

Available Plans

PlanPriceStorageRequests/HourMax File SizeAPI Keys
Free$01 GB1,000100 MB2
Creator$9.9910 GB10,0001 GB5
Studio$29.99100 GB50,0005 GB10
Production$99.991 TB100,00010 GB25

Error Responses

Insufficient Permissions

{
  "success": false,
  "error": {
    "code": "INSUFFICIENT_PERMISSIONS",
    "message": "You don't have permission to view billing information"
  }
}

Billing Not Available

{
  "success": false,
  "error": {
    "code": "BILLING_NOT_AVAILABLE",
    "message": "Billing information is not available for this account"
  }
}

SDK Examples

curl -X GET "https://api.astracollab.app/v1/billing" \
  -H "Authorization: Bearer your-api-key-here"

Usage Monitoring

Monitor usage to avoid hitting limits:
const checkUsageAlerts = (billing) => {
  const alerts = [];
  
  // Storage usage alerts
  const storagePercentage = billing.usage.currentPeriod.storage.percentage;
  if (storagePercentage > 90) {
    alerts.push({
      type: 'warning',
      message: `Storage usage is at ${storagePercentage}%`
    });
  } else if (storagePercentage > 80) {
    alerts.push({
      type: 'info',
      message: `Storage usage is at ${storagePercentage}%`
    });
  }
  
  // Request usage alerts
  const requestPercentage = billing.usage.currentPeriod.requests.percentage;
  if (requestPercentage > 90) {
    alerts.push({
      type: 'warning',
      message: `Request usage is at ${requestPercentage}%`
    });
  }
  
  return alerts;
};

Plan Comparison

Compare current plan with others:
const comparePlans = (currentPlan) => {
  const plans = [
    { id: 'free', name: 'Free', price: 0, storage: 1073741824 },
    { id: 'creator', name: 'Creator', price: 9.99, storage: 10737418240 },
    { id: 'studio', name: 'Studio', price: 29.99, storage: 107374182400 },
    { id: 'production', name: 'Production', price: 99.99, storage: 1099511627776 }
  ];
  
  return plans.map(plan => ({
    ...plan,
    isCurrent: plan.id === currentPlan.id,
    upgradeCost: plan.price - currentPlan.price
  }));
};

Cost Optimization

Analyze usage patterns for cost optimization:
const analyzeCostOptimization = (billing) => {
  const recommendations = [];
  
  // Check if current plan is overkill
  const storageUtilization = billing.usage.currentPeriod.storage.percentage;
  if (storageUtilization < 20) {
    recommendations.push({
      type: 'downgrade',
      message: 'Consider downgrading to a lower plan - you\'re only using 20% of storage'
    });
  }
  
  // Check if approaching limits
  if (storageUtilization > 80) {
    recommendations.push({
      type: 'upgrade',
      message: 'Consider upgrading to avoid hitting storage limits'
    });
  }
  
  return recommendations;
};