Get Usage Summary
Retrieve overall usage statistics for your account.curl -X GET "https://api.tensorone.ai/v2/accounts/usage" \
-H "Authorization: Bearer YOUR_API_KEY" \
-G -d "period=30d"
Query Parameters
period: Time period (1d,7d,30d,90d,180d)timezone: Timezone for date calculations (default: account timezone)
Response
{
"period": "30d",
"periodStart": "2024-02-20T00:00:00Z",
"periodEnd": "2024-03-20T23:59:59Z",
"summary": {
"totalCost": 1250.75,
"totalComputeHours": 485.2,
"totalEndpointExecutions": 12450,
"totalDataTransfer": "125.8GB",
"averageDailyCost": 41.69,
"costTrend": "+12.5%"
},
"breakdown": {
"compute": {
"cost": 980.5,
"hours": 485.2,
"percentage": 78.4
},
"storage": {
"cost": 125.25,
"gb": "2.5TB",
"percentage": 10.0
},
"dataTransfer": {
"cost": 95.0,
"gb": "125.8GB",
"percentage": 7.6
},
"other": {
"cost": 50.0,
"percentage": 4.0
}
},
"topResources": [
{
"type": "gpu",
"name": "NVIDIA A100",
"cost": 645.3,
"hours": 201.5,
"percentage": 51.6
},
{
"type": "gpu",
"name": "NVIDIA RTX 4090",
"cost": 335.2,
"hours": 283.7,
"percentage": 26.8
}
]
}
Get Detailed Usage
Retrieve detailed usage data with timeline breakdown.curl -X GET "https://api.tensorone.ai/v2/accounts/usage/detailed" \
-H "Authorization: Bearer YOUR_API_KEY" \
-G -d "period=7d" -d "granularity=day"
Query Parameters
period: Time period (1d,7d,30d,90d)granularity: Data granularity (hour,day,week)resources: Filter by resource types (gpu,storage,transfer)
Response
{
"period": "7d",
"granularity": "day",
"timeline": [
{
"date": "2024-03-14",
"cost": 45.2,
"computeHours": 18.5,
"executions": 420,
"dataTransfer": "4.2GB",
"resources": {
"gpu": {
"a100": { "hours": 12.0, "cost": 38.4 },
"rtx4090": { "hours": 6.5, "cost": 6.8 }
}
}
},
{
"date": "2024-03-15",
"cost": 52.8,
"computeHours": 21.2,
"executions": 485,
"dataTransfer": "5.1GB",
"resources": {
"gpu": {
"a100": { "hours": 15.5, "cost": 49.6 },
"rtx4090": { "hours": 5.7, "cost": 3.2 }
}
}
}
],
"projections": {
"monthlyEstimate": 1650.0,
"dailyAverage": 48.75,
"confidence": 0.85
}
}
Get GPU Usage
Get detailed GPU usage statistics and performance metrics.curl -X GET "https://api.tensorone.ai/v2/accounts/usage/gpu" \
-H "Authorization: Bearer YOUR_API_KEY" \
-G -d "period=30d" -d "includeMetrics=true"
Response
{
"period": "30d",
"gpuUsage": [
{
"gpuType": "NVIDIA A100",
"totalHours": 201.5,
"totalCost": 645.3,
"averageUtilization": 87.2,
"peakUtilization": 98.5,
"sessions": 145,
"averageSessionDuration": "1h 23m",
"performance": {
"averageMemoryUsage": 75.8,
"averageTemperature": 68.5,
"efficiency": 0.92
},
"usage": [
{
"date": "2024-03-01",
"hours": 8.5,
"cost": 27.2,
"utilization": 89.2,
"sessions": 6
}
]
},
{
"gpuType": "NVIDIA RTX 4090",
"totalHours": 283.7,
"totalCost": 335.2,
"averageUtilization": 82.4,
"peakUtilization": 95.1,
"sessions": 201,
"averageSessionDuration": "1h 25m",
"performance": {
"averageMemoryUsage": 68.5,
"averageTemperature": 71.2,
"efficiency": 0.88
}
}
]
}
Get Endpoint Usage
Retrieve usage statistics for serverless endpoints.curl -X GET "https://api.tensorone.ai/v2/accounts/usage/endpoints" \
-H "Authorization: Bearer YOUR_API_KEY" \
-G -d "period=30d"
Response
{
"period": "30d",
"endpointUsage": [
{
"endpointId": "ep_1234567890abcdef",
"name": "stable-diffusion-xl",
"executions": 5420,
"computeHours": 125.8,
"cost": 402.56,
"averageExecutionTime": "1.4s",
"successRate": 98.7,
"usage": [
{
"date": "2024-03-01",
"executions": 180,
"computeHours": 4.2,
"cost": 13.44,
"averageExecutionTime": "1.3s"
}
],
"topUsers": [
{
"userId": "usr_abc123",
"executions": 1250,
"percentage": 23.1
}
]
}
],
"summary": {
"totalExecutions": 12450,
"totalCost": 980.5,
"averageExecutionCost": 0.0788,
"mostUsedEndpoint": "stable-diffusion-xl"
}
}
Get Cost Breakdown
Get detailed cost breakdown by service, resource type, and time period.curl -X GET "https://api.tensorone.ai/v2/accounts/usage/costs" \
-H "Authorization: Bearer YOUR_API_KEY" \
-G -d "period=30d" -d "breakdown=service"
Query Parameters
breakdown: Breakdown type (service,resource,region,team)currency: Currency code (default:USD)
Response
{
"period": "30d",
"currency": "USD",
"breakdown": "service",
"totalCost": 1250.75,
"services": [
{
"service": "GPU Compute",
"cost": 980.5,
"percentage": 78.4,
"details": {
"a100": { "cost": 645.3, "hours": 201.5 },
"rtx4090": { "cost": 335.2, "hours": 283.7 }
}
},
{
"service": "Storage",
"cost": 125.25,
"percentage": 10.0,
"details": {
"model_storage": { "cost": 75.0, "gb": 1500 },
"data_storage": { "cost": 50.25, "gb": 1005 }
}
},
{
"service": "Data Transfer",
"cost": 95.0,
"percentage": 7.6,
"details": {
"ingress": { "cost": 0.0, "gb": 45.2 },
"egress": { "cost": 95.0, "gb": 125.8 }
}
},
{
"service": "API Requests",
"cost": 50.0,
"percentage": 4.0,
"details": {
"management_api": { "cost": 25.0, "requests": 125000 },
"inference_api": { "cost": 25.0, "requests": 12450 }
}
}
],
"trends": {
"weekOverWeek": "+8.5%",
"monthOverMonth": "+12.3%"
}
}
Get Usage Alerts
Configure and retrieve usage alerts and notifications.curl -X GET "https://api.tensorone.ai/v2/accounts/usage/alerts" \
-H "Authorization: Bearer YOUR_API_KEY"
Response
{
"alerts": [
{
"id": "alert_1234567890",
"name": "Monthly Cost Alert",
"type": "cost",
"threshold": 1000.0,
"current": 1250.75,
"percentage": 125.1,
"status": "triggered",
"triggeredAt": "2024-03-18T14:30:00Z",
"notificationsSent": 2
},
{
"id": "alert_0987654321",
"name": "GPU Hours Alert",
"type": "compute_hours",
"threshold": 400.0,
"current": 485.2,
"percentage": 121.3,
"status": "triggered",
"triggeredAt": "2024-03-19T09:15:00Z",
"notificationsSent": 1
}
],
"settings": {
"emailNotifications": true,
"slackNotifications": true,
"webhookUrl": "https://yourapp.com/webhooks/usage-alerts"
}
}
Code Examples
Python SDK
from tensorone import TensorOneAPI
from datetime import datetime, timedelta
client = TensorOneAPI(api_key="your_api_key")
# Get usage summary
usage = client.accounts.usage.get_summary(period="30d")
print(f"Total cost: ${usage.summary.total_cost}")
print(f"Compute hours: {usage.summary.total_compute_hours}")
# Get detailed timeline
detailed = client.accounts.usage.get_detailed(
period="7d",
granularity="day"
)
for day in detailed.timeline:
print(f"{day.date}: ${day.cost} ({day.compute_hours}h)")
# Get GPU usage
gpu_usage = client.accounts.usage.get_gpu(
period="30d",
include_metrics=True
)
for gpu in gpu_usage.gpu_usage:
print(f"{gpu.gpu_type}: {gpu.total_hours}h @ {gpu.average_utilization}% util")
# Get cost breakdown
costs = client.accounts.usage.get_costs(
period="30d",
breakdown="service"
)
for service in costs.services:
print(f"{service.service}: ${service.cost} ({service.percentage}%)")
# Set up cost alert
alert = client.accounts.usage.create_alert(
name="Production Cost Alert",
type="cost",
threshold=2000.00,
period="monthly"
)
# Export usage data for analysis
usage_data = client.accounts.usage.export(
period="90d",
format="csv",
include_details=True
)
JavaScript SDK
import { TensorOneAPI } from "@tensorone/sdk";
const client = new TensorOneAPI("your_api_key");
// Get usage summary
const usage = await client.accounts.usage.getSummary({ period: "30d" });
console.log(`Total cost: $${usage.summary.totalCost}`);
console.log(`Compute hours: ${usage.summary.totalComputeHours}`);
// Get detailed usage with timeline
const detailed = await client.accounts.usage.getDetailed({
period: "7d",
granularity: "day",
});
detailed.timeline.forEach((day) => {
console.log(`${day.date}: $${day.cost} (${day.computeHours}h)`);
});
// Get GPU usage statistics
const gpuUsage = await client.accounts.usage.getGpu({
period: "30d",
includeMetrics: true,
});
gpuUsage.gpuUsage.forEach((gpu) => {
console.log(`${gpu.gpuType}: ${gpu.totalHours}h @ ${gpu.averageUtilization}% util`);
});
// Get endpoint usage
const endpoints = await client.accounts.usage.getEndpoints({ period: "30d" });
endpoints.endpointUsage.forEach((endpoint) => {
console.log(`${endpoint.name}: ${endpoint.executions} executions, $${endpoint.cost}`);
});
// Create usage alert
const alert = await client.accounts.usage.createAlert({
name: "Development Cost Alert",
type: "cost",
threshold: 500.0,
period: "monthly",
});
// Generate usage report
const report = await client.accounts.usage.generateReport({
period: "30d",
format: "pdf",
includeCharts: true,
});
Error Responses
400 Bad Request
{
"error": "INVALID_PERIOD",
"message": "Invalid time period specified",
"details": {
"validPeriods": ["1d", "7d", "30d", "90d", "1y"],
"received": "invalid_period"
}
}
403 Forbidden
{
"error": "INSUFFICIENT_PERMISSIONS",
"message": "Access to billing information requires billing scope",
"details": {
"requiredScope": "billing"
}
}
429 Too Many Requests
{
"error": "RATE_LIMIT_EXCEEDED",
"message": "Usage API rate limit exceeded",
"details": {
"limit": 100,
"period": "1h",
"resetAt": "2024-03-20T18:00:00Z"
}
}
Best Practices
Cost Optimization
- Monitor usage trends to identify cost spikes
- Set up proactive alerts before reaching budget limits
- Use detailed breakdowns to identify optimization opportunities
- Track GPU utilization to right-size resources
Resource Management
- Analyze endpoint performance to optimize execution times
- Monitor storage usage and clean up unused data
- Track data transfer costs and optimize data flow
- Use projections for capacity planning
Monitoring and Alerts
- Set multiple alert thresholds (warning and critical)
- Configure alerts for different metrics (cost, hours, executions)
- Use webhooks for real-time notifications
- Regular review of usage patterns and trends
Use Cases
Budget Management
# Set up comprehensive budget monitoring
def setup_budget_alerts():
# Monthly cost alert at 80% of budget
client.accounts.usage.create_alert(
name="Monthly Budget Warning",
type="cost",
threshold=4000.00, # 80% of $5000 budget
period="monthly"
)
# Daily cost alert for unexpected spikes
client.accounts.usage.create_alert(
name="Daily Cost Spike",
type="cost",
threshold=200.00,
period="daily"
)
Performance Optimization
# Analyze GPU efficiency
def analyze_gpu_efficiency():
gpu_usage = client.accounts.usage.get_gpu(period="30d", include_metrics=True)
for gpu in gpu_usage.gpu_usage:
efficiency = gpu.performance.efficiency
utilization = gpu.average_utilization
if efficiency < 0.8 or utilization < 70:
print(f"GPU {gpu.gpu_type} may need optimization:")
print(f" Efficiency: {efficiency:.2f}")
print(f" Utilization: {utilization:.1f}%")
Cost Attribution
# Track costs by team or project
def generate_team_report():
costs = client.accounts.usage.get_costs(
period="30d",
breakdown="team"
)
for team in costs.teams:
print(f"Team {team.name}: ${team.cost}")
# Generate detailed team report
team_report = client.accounts.usage.get_detailed(
period="30d",
filters={"team_id": team.id}
)
Capacity Planning
# Use projections for capacity planning
def plan_capacity():
detailed = client.accounts.usage.get_detailed(period="90d")
monthly_estimate = detailed.projections.monthly_estimate
if monthly_estimate > 8000: # Budget threshold
print("Warning: Projected monthly cost exceeds budget")
print(f"Estimated: ${monthly_estimate}")
# Analyze growth trend
print(f"Confidence: {detailed.projections.confidence:.1%}")

