Billing & Subscriptions API
Comprehensive billing management including LLM token usage, API call tracking, subscription management, and Stripe integration for payments. Monitor usage, receive alerts, and manage your organization's subscription.
Overview
Billing Types
- • LLM Tokens: AI/Nelo usage tracking
- • API Calls: Request-based billing
- • Storage: File storage usage
- • PDF Processing: Document extraction
Features
- • Real-time usage monitoring
- • Quota alerts (75%, 90%, 100%)
- • Monthly billing reports
- • Stripe subscription management
- • Usage projections and forecasting
Subscription Tiers
- • 2 machines
- • 100 MB storage
- • 50K LLM tokens/mo
- • Basic support
- • 25 machines
- • 10 GB storage
- • 2.5M LLM tokens/mo
- • Priority support
- • Unlimited machines
- • 50 GB storage
- • 10M LLM tokens/mo
- • Dedicated support
- • Unlimited everything
- • Custom storage
- • Custom tokens
- • SSO, SLA, dedicated
LLM Token Billing
Track AI/LLM token consumption across Nelo conversations, semantic tag analysis, PDF processing, and other AI features. All services share a unified token pool based on your subscription tier.
/v1/billing/llm/overviewAuth RequiredResponse
{
"organization_id": "org_001",
"billing_period": {
"start": "2024-08-01T00:00:00Z",
"end": "2024-08-31T23:59:59Z"
},
"subscription_tier": "professional",
"token_quota": {
"total": 2500000,
"used": 1875000,
"remaining": 625000,
"percent_used": 75.0
},
"usage_by_service": {
"nelo_chat": 1200000,
"semantic_analysis": 450000,
"pdf_processing": 225000
},
"alerts": [
{
"type": "quota_warning",
"threshold": 75,
"message": "You've used 75% of your monthly token quota"
}
],
"updated_at": "2024-08-26T14:30:00Z"
}Try it out
curl -X GET "https://sapienstream.com/api/v1/billing/llm/overview" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json"/v1/billing/llm/projection/{service_type}Auth RequiredParameters
service_typestringRequiredService type (nelo, semantic, pdf_analysis, all)
Response
{
"service_type": "all",
"current_usage": 1875000,
"projected_usage": 2340000,
"days_remaining": 5,
"average_daily_usage": 93000,
"projection_confidence": 0.85,
"will_exceed_quota": false,
"estimated_overage": 0,
"recommendation": "Current usage is on track. No action needed."
}Try it out
curl -X GET "https://sapienstream.com/api/v1/billing/llm/projection/{service_type}" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json"/v1/billing/llm/report/{year}/{month}Auth RequiredParameters
yearintegerRequiredYear (e.g., 2024)
monthintegerRequiredMonth (1-12)
Response
{
"year": 2024,
"month": 8,
"status": "in_progress",
"total_tokens": 1875000,
"total_cost": 18.75,
"usage_breakdown": [
{"service": "nelo_chat", "tokens": 1200000, "cost": 12.00},
{"service": "semantic_analysis", "tokens": 450000, "cost": 4.50},
{"service": "pdf_processing", "tokens": 225000, "cost": 2.25}
],
"daily_usage": [
{"date": "2024-08-01", "tokens": 72000},
{"date": "2024-08-02", "tokens": 85000}
],
"peak_usage_day": "2024-08-15",
"peak_usage_tokens": 145000
}Try it out
curl -X GET "https://sapienstream.com/api/v1/billing/llm/report/{year}/{month}" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json"/v1/billing/llm/finalize/{year}/{month}Auth RequiredParameters
yearintegerRequiredYear
monthintegerRequiredMonth
Response
{
"year": 2024,
"month": 7,
"status": "finalized",
"total_tokens": 2340000,
"total_cost": 23.40,
"finalized_at": "2024-08-01T00:00:01Z",
"invoice_id": "inv_abc123"
}Try it out
curl -X POST "https://sapienstream.com/api/v1/billing/llm/finalize/{year}/{month}" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json"/v1/billing/llm/alertsAuth RequiredResponse
{
"alerts": [
{
"id": "alert_001",
"type": "quota_warning",
"severity": "warning",
"threshold_percent": 75,
"current_percent": 78.5,
"message": "You've used 78.5% of your monthly token quota",
"action_url": "/account/billing",
"created_at": "2024-08-20T10:00:00Z"
}
],
"has_critical_alerts": false
}Try it out
curl -X GET "https://sapienstream.com/api/v1/billing/llm/alerts" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json"/v1/billing/llm/usage-summaryAuth RequiredResponse
{
"period": "current_month",
"services": [
{
"name": "Nelo Chat",
"service_type": "nelo",
"tokens_used": 1200000,
"percent_of_total": 64.0,
"trend": "+12% vs last month"
},
{
"name": "Semantic Analysis",
"service_type": "semantic",
"tokens_used": 450000,
"percent_of_total": 24.0,
"trend": "-5% vs last month"
},
{
"name": "PDF Processing",
"service_type": "pdf_analysis",
"tokens_used": 225000,
"percent_of_total": 12.0,
"trend": "+8% vs last month"
}
]
}Try it out
curl -X GET "https://sapienstream.com/api/v1/billing/llm/usage-summary" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json"API Usage Billing
Track API request usage for billing purposes. Includes endpoint breakdown, response time analytics, and overage tracking.
/v1/billing/api/overviewAuth RequiredResponse
{
"organization_id": "org_001",
"billing_period": {
"start": "2024-08-01T00:00:00Z",
"end": "2024-08-31T23:59:59Z"
},
"request_quota": {
"total": 100000,
"used": 67890,
"remaining": 32110,
"percent_used": 67.9
},
"endpoints_breakdown": [
{"endpoint": "/machines", "requests": 23456},
{"endpoint": "/tags", "requests": 18765},
{"endpoint": "/components", "requests": 12345}
],
"avg_response_time_ms": 145
}Try it out
curl -X GET "https://sapienstream.com/api/v1/billing/api/overview" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json"/v1/billing/api/projectionAuth RequiredResponse
{
"current_requests": 67890,
"projected_requests": 89500,
"days_remaining": 5,
"average_daily_requests": 4320,
"will_exceed_quota": false,
"recommendation": "Usage is within normal range."
}Try it out
curl -X GET "https://sapienstream.com/api/v1/billing/api/projection" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json"/v1/billing/api/report/{year}/{month}Auth RequiredParameters
yearintegerRequiredYear
monthintegerRequiredMonth
Response
{
"year": 2024,
"month": 8,
"total_requests": 67890,
"successful_requests": 66543,
"failed_requests": 1347,
"success_rate": 98.0,
"avg_response_time_ms": 145,
"peak_hour": "14:00",
"peak_requests_per_hour": 4567
}Try it out
curl -X GET "https://sapienstream.com/api/v1/billing/api/report/{year}/{month}" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json"Stripe Integration
Manage subscriptions, payments, and billing information through our Stripe integration.
/v1/payments/checkout-sessionAuth RequiredRequest Body
{
"price_id": "price_professional_monthly",
"success_url": "https://app.sapienstream.com/account/billing?success=true",
"cancel_url": "https://app.sapienstream.com/pricing"
}Response
{
"checkout_url": "https://checkout.stripe.com/pay/cs_live_abc123...",
"session_id": "cs_live_abc123def456"
}Try it out
curl -X POST "https://sapienstream.com/api/v1/payments/checkout-session" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json"/v1/payments/customer-portalAuth RequiredRequest Body
{
"return_url": "https://app.sapienstream.com/account/billing"
}Response
{
"portal_url": "https://billing.stripe.com/session/abc123..."
}Try it out
curl -X POST "https://sapienstream.com/api/v1/payments/customer-portal" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json"/v1/payments/subscriptionAuth RequiredResponse
{
"subscription_id": "sub_abc123",
"plan": "professional",
"status": "active",
"current_period_start": "2024-08-01T00:00:00Z",
"current_period_end": "2024-08-31T23:59:59Z",
"cancel_at_period_end": false,
"payment_method": {
"type": "card",
"brand": "visa",
"last4": "4242"
},
"next_invoice": {
"amount": 99.00,
"currency": "usd",
"due_date": "2024-09-01T00:00:00Z"
}
}Try it out
curl -X GET "https://sapienstream.com/api/v1/payments/subscription" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json"/v1/payments/subscription/upgradeAuth RequiredRequest Body
{
"new_plan": "small_teams"
}Response
{
"subscription_id": "sub_abc123",
"previous_plan": "professional",
"new_plan": "small_teams",
"effective_date": "2024-08-26T00:00:00Z",
"prorated_amount": 45.00,
"next_billing_amount": 199.00
}Try it out
curl -X PUT "https://sapienstream.com/api/v1/payments/subscription/upgrade" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json"/v1/payments/subscription/cancelAuth RequiredRequest Body
{
"reason": "Not using enough features",
"feedback": "Would love more PLC integration options"
}Response
{
"subscription_id": "sub_abc123",
"status": "active",
"cancel_at_period_end": true,
"cancellation_date": "2024-08-31T23:59:59Z",
"features_available_until": "2024-08-31T23:59:59Z"
}Try it out
curl -X POST "https://sapienstream.com/api/v1/payments/subscription/cancel" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json"/v1/payments/historyAuth RequiredParameters
limitintegerMax results (default: 10)
Response
{
"payments": [
{
"id": "pi_abc123",
"amount": 99.00,
"currency": "usd",
"status": "succeeded",
"description": "Professional Plan - August 2024",
"invoice_url": "https://invoice.stripe.com/i/abc123",
"created_at": "2024-08-01T00:00:00Z"
},
{
"id": "pi_def456",
"amount": 99.00,
"currency": "usd",
"status": "succeeded",
"description": "Professional Plan - July 2024",
"invoice_url": "https://invoice.stripe.com/i/def456",
"created_at": "2024-07-01T00:00:00Z"
}
]
}Try it out
curl -X GET "https://sapienstream.com/api/v1/payments/history" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json"Subscription Policies
/v1/subscription-policies/plansResponse
{
"plans": [
{
"id": "free",
"name": "Free",
"price_monthly": 0,
"features": {
"max_machines": 2,
"max_storage_mb": 100,
"max_llm_tokens": 50000,
"semantic_analysis": false,
"api_access": false
}
},
{
"id": "professional",
"name": "Professional",
"price_monthly": 99,
"features": {
"max_machines": 25,
"max_storage_mb": 10240,
"max_llm_tokens": 2500000,
"semantic_analysis": true,
"api_access": true
}
}
]
}Try it out
curl -X GET "https://sapienstream.com/api/v1/subscription-policies/plans" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json"/v1/subscription-policies/plans/{plan_id}Parameters
plan_idstringRequiredPlan identifier
Response
{
"id": "professional",
"name": "Professional",
"description": "For growing teams and production environments",
"price_monthly": 99,
"price_yearly": 990,
"features": {
"max_machines": 25,
"max_users": 10,
"max_storage_mb": 10240,
"max_llm_tokens": 2500000,
"semantic_analysis": true,
"api_access": true,
"priority_support": true,
"custom_integrations": false
},
"rate_limits": {
"api_requests_per_minute": 100,
"api_requests_per_hour": 1000
}
}Try it out
curl -X GET "https://sapienstream.com/api/v1/subscription-policies/plans/{plan_id}" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json"/v1/subscription-policies/check-limitAuth RequiredRequest Body
{
"resource": "machines",
"action": "create"
}Response
{
"allowed": true,
"current_usage": 18,
"limit": 25,
"remaining": 7,
"message": "You can create 7 more machines on your current plan."
}Try it out
curl -X POST "https://sapienstream.com/api/v1/subscription-policies/check-limit" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json"/v1/subscription-policies/featuresAuth RequiredResponse
{
"plan": "professional",
"features": {
"nelo_chat": true,
"semantic_analysis": true,
"pdf_extraction": true,
"api_access": true,
"bulk_operations": true,
"priority_support": true,
"custom_branding": false,
"sso": false,
"dedicated_support": false
}
}Try it out
curl -X GET "https://sapienstream.com/api/v1/subscription-policies/features" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json"/v1/subscription-policies/limitsAuth RequiredResponse
{
"plan": "professional",
"limits": {
"max_machines": 25,
"max_users": 10,
"max_components": 500,
"max_storage_mb": 10240,
"max_llm_tokens_per_month": 2500000,
"api_requests_per_minute": 100,
"api_requests_per_hour": 1000,
"max_api_keys": 10
}
}Try it out
curl -X GET "https://sapienstream.com/api/v1/subscription-policies/limits" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json"/v1/subscription-policies/usage-scenariosParameters
machinesintegerNumber of machines
usersintegerNumber of users
storage_gbnumberStorage needed in GB
Response
{
"scenario": {
"machines": 15,
"users": 5,
"storage_gb": 5
},
"recommended_plan": "professional",
"monthly_cost": 99,
"yearly_cost": 990,
"savings_yearly": 198,
"fits_within_limits": true,
"headroom": {
"machines": 10,
"users": 5,
"storage_gb": 5
}
}Try it out
curl -X GET "https://sapienstream.com/api/v1/subscription-policies/usage-scenarios" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json"Quota Management
Your subscription includes a monthly token allocation (e.g., 2.5M for Professional) that is shared across all AI-powered features: Nelo conversations, semantic tag analysis, and PDF processing. This provides flexibility in how you use your AI budget.
Alert Thresholds
- • 75%: Warning notification sent
- • 90%: Urgent warning, upgrade prompt
- • 100%: Services limited, immediate action required
// Example: Quota Status Response
{
"subscription_tier": "professional",
"quota": {
"total_llm_tokens": 2500000,
"used_llm_tokens": 1875000,
"remaining_llm_tokens": 625000,
"percent_used": 75.0
},
"rate_limits": {
"api_requests_per_minute": {
"limit": 100,
"current": 45,
"reset_in_seconds": 32
}
},
"resource_usage": {
"machines": { "used": 18, "limit": 25 },
"storage_mb": { "used": 5120, "limit": 10240 },
"users": { "used": 5, "limit": 10 }
},
"can_upgrade": true,
"upgrade_url": "/account/billing/upgrade"
}