Account Management
NagaAI provides comprehensive account management capabilities, allowing you to monitor usage, track spending, and manage API keys programmatically. These features help you maintain control over your account, optimize costs, and organize access across different projects.
Account management endpoints require authentication with a provisioning key, not a regular API key. This ensures secure administrative access to your account.
You can obtain your provisioning key from the NagaAI Dashboard.
Quick Navigation
Overview
Account management includes three main areas that work together to give you complete control over your NagaAI account:
-
Balance Monitoring: Check your current account balance and available credits with real-time spending visibility, automated alerts, and billing workflow integration.
-
Activity Tracking: View detailed usage statistics, costs, and patterns including cost optimization insights, usage trend analysis, and model performance tracking.
-
API Key Management: Create, configure, and control multiple API keys with environment separation, budget control through per-key limits, and enhanced security.
What You Can Do
- Monitor spending in real-time
- Set up budget alerts and usage tracking
- Organize API keys for different environments
- Control access with per-key credit limits
- Analyze usage patterns by model and time period
- Track costs per project or team
Balance Monitoring
Check your account balance at any time to see available credits. This is useful for:
- Monitoring remaining funds before large batch operations
- Setting up automated low-balance alerts
- Integrating balance checks into billing workflows
Here's how to check your current balance:
import requests
response = requests.get(
"https://api.naga.ac/v1/account/balance",
headers={"Authorization": "Bearer YOUR_PROVISIONING_KEY"}
)
balance = response.json()
print(f"Current balance: ${balance['balance']}")
The balance is returned as a string representing USD amount (e.g., "125.50"
).
Activity Tracking
View comprehensive usage statistics for your account, including daily breakdowns, model usage, and per-key analytics. This powerful feature helps you:
- Understand spending patterns over time
- Identify which models are most used
- Track usage per API key for cost allocation
- Analyze daily trends and optimize usage
Usage Statistics Include
-
Total Stats: Overall requests, costs, and tokens for the period to monitor aggregate spending and track token consumption.
-
Daily Breakdown: Day-by-day analysis of usage to identify usage spikes, trends, and compare day-over-day performance.
-
Top Models: Most frequently used models with associated costs to help optimize model selection and understand cost per model.
-
API Key Usage: Per-key statistics for cost attribution, allowing you to allocate costs by project or team and track usage by environment.
To retrieve activity data for your account, make the following request:
# Get activity for the last 7 days
response = requests.get(
"https://api.naga.ac/v1/account/activity",
headers={"Authorization": "Bearer YOUR_PROVISIONING_KEY"},
params={"days": 7}
)
activity = response.json()
print(f"Total requests: {activity['total_stats']['total_requests']}")
print(f"Total cost: ${activity['total_stats']['total_cost']}")
print(f"Most used model: {activity['top_models'][0]['model_name']}")
- Query statistics for 1-30 days (default: 30 days)
- Results are cached for 5 minutes for optimal performance
API Key Management
Organize and control access to your account with multiple API keys. Each key can have its own configuration, making it easy to:
- Separate production and development environments
- Set individual spending limits per project
- Enable or disable keys without affecting others
- Track usage separately for different applications
Create API Keys
You can create new API keys programmatically with custom names and optional credit limits. Here's an example:
response = requests.post(
"https://api.naga.ac/v1/account/keys",
headers={
"Authorization": "Bearer YOUR_PROVISIONING_KEY",
"Content-Type": "application/json"
},
json={
"name": "Production API Key",
"credit_limit": 500.00
}
)
key_data = response.json()
print(f"New API Key: {key_data['key']}") # Store this securely!
API keys are only shown once during creation. Store them securely immediately as they cannot be retrieved again.
List, Update & Delete Keys
- List All Keys
- Update Keys
- Delete Keys
View all API keys and their configurations:
response = requests.get(
"https://api.naga.ac/v1/account/keys",
headers={"Authorization": "Bearer YOUR_PROVISIONING_KEY"}
)
keys = response.json()
for key in keys['keys']:
print(f"{key['name']}: {'enabled' if key['is_enabled'] else 'disabled'}")
Modify key names, enable/disable keys, or adjust credit limits:
response = requests.patch(
f"https://api.naga.ac/v1/account/keys/{key_id}",
headers={
"Authorization": "Bearer YOUR_PROVISIONING_KEY",
"Content-Type": "application/json"
},
json={
"name": "Updated Key Name",
"is_enabled": True,
"credit_limit": 200.00
}
)
Permanently remove API keys when no longer needed:
response = requests.delete(
f"https://api.naga.ac/v1/account/keys/{key_id}",
headers={"Authorization": "Bearer YOUR_PROVISIONING_KEY"}
)
Deleting an API key is permanent. Any applications using the deleted key will immediately lose access.
Common Use Cases
- Budget Management
- Multi-Environment Setup
- Cost Analysis
Set up automated monitoring to prevent overspending:
def check_budget():
# Check balance
balance_response = requests.get(
"https://api.naga.ac/v1/account/balance",
headers={"Authorization": "Bearer YOUR_PROVISIONING_KEY"}
)
balance = float(balance_response.json()['balance'])
# Get recent spending
activity_response = requests.get(
"https://api.naga.ac/v1/account/activity?days=1",
headers={"Authorization": "Bearer YOUR_PROVISIONING_KEY"}
)
daily_cost = float(activity_response.json()['total_stats']['total_cost'])
# Alert if balance is low or daily spend is high
if balance < 50:
send_alert(f"Low balance: ${balance}")
if daily_cost > 100:
send_alert(f"High daily spend: ${daily_cost}")
Organize keys for different environments with appropriate limits:
environments = [
{"name": "Production", "limit": 1000.00},
{"name": "Staging", "limit": 100.00},
{"name": "Development", "limit": 50.00},
{"name": "Testing", "limit": 25.00}
]
for env in environments:
response = requests.post(
"https://api.naga.ac/v1/account/keys",
headers={"Authorization": "Bearer YOUR_PROVISIONING_KEY"},
json={"name": env["name"], "credit_limit": env["limit"]}
)
print(f"Created {env['name']} key")
Analyze spending patterns to optimize usage:
response = requests.get(
"https://api.naga.ac/v1/account/activity?days=30",
headers={"Authorization": "Bearer YOUR_PROVISIONING_KEY"}
)
activity = response.json()
# Analyze by model
print("Cost by model:")
for model in activity['top_models']:
cost = float(model['total_cost'])
requests = model['request_count']
avg_cost = cost / requests
print(f"{model['model_name']}: ${cost:.2f} ({requests} requests, ${avg_cost:.4f} avg)")
# Analyze by API key
print("\nCost by API key:")
for key in activity['api_key_usage']:
print(f"{key['api_key_name']}: ${key['total_cost']}")
Learn More
All account management operations use your provisioning key, which has higher privileges than regular API keys. Keep your provisioning key secure and never share it with unauthorized users.