Wallet & Billing
Learn about AgentRouter's wallet system and billing mechanism
Wallet & Billing
AgentRouter uses a built-in wallet system for billing. Each API call deducts the corresponding cost from your wallet based on actual token usage.
Wallet System
Check Balance
Visit the Wallet page to view:
- Current Balance - Available amount (USD)
- Consumption Statistics - Today, this week, this month spending
- Transaction History - Detailed top-up and deduction records
Welcome Bonus
New users automatically receive a $1.00 welcome bonus after registration, allowing you to start using the API immediately.
Balance Precision
Wallet balance is accurate to 8 decimal places (0.00000001 USD), ensuring precise billing.
Billing Method
Token-Based Billing
AgentRouter bills based on actual tokens consumed:
Total Cost = (Input tokens / 1,000,000) × Input price + (Output tokens / 1,000,000) × Output priceBilling Examples
Using gpt-4o (Input $2.50/M, Output $10.00/M):
| Input Tokens | Output Tokens | Calculation | Total Cost |
|---|---|---|---|
| 100 | 200 | (100/1M)×$2.50 + (200/1M)×$10.00 | $0.00225 |
| 1,000 | 2,000 | (1K/1M)×$2.50 + (2K/1M)×$10.00 | $0.0225 |
| 10,000 | 20,000 | (10K/1M)×$2.50 + (20K/1M)×$10.00 | $0.225 |
Real-Time Deduction
After each API request completes:
- Calculate actual tokens consumed
- Calculate cost based on model pricing
- Deduct from wallet balance
- Record transaction history
Transaction Records
Record Contents
Each transaction includes:
- Transaction Time - Accurate to the second
- Type - CREDIT (top-up) or DEDUCTION (deduction)
- Amount - Positive for top-up, negative for deduction
- Balance - Balance after transaction
- Description - Transaction explanation
Deduction Record Example
{
"type": "DEDUCTION",
"amount": "-0.00225",
"balance": "0.99775",
"description": "API call: gpt-4o (100 input + 200 output tokens)",
"metadata": {
"model": "gpt-4o",
"inputTokens": 100,
"outputTokens": 200,
"apiKeyId": "key_abc123"
}
}Top-Up Record Example
{
"type": "CREDIT",
"amount": "10.00",
"balance": "11.00",
"description": "Manual credit by admin",
"metadata": {
"method": "admin",
"operator": "admin@example.com"
}
}Top-Up Methods
Current Top-Up Method
Currently, you need to contact an administrator for top-ups:
- Determine top-up amount
- Contact administrator
- Administrator manually adds balance
- Check wallet to confirm receipt
Future Plans
Top-up methods in development:
- Credit Card Payment - Stripe integration
- PayPal - Support PayPal balance payments
- Cryptocurrency - Support stablecoins like USDT
- Enterprise Contracts - Monthly/annual subscriptions
Insufficient Balance Handling
Error Response
When balance is insufficient, API returns 402 Payment Required:
{
"error": {
"message": "Insufficient balance",
"type": "insufficient_funds",
"code": "insufficient_balance"
}
}Preventive Measures
-
Set Balance Alerts (in development)
- Send email alerts when balance falls below threshold
- Configurable alert amount
-
Estimate Costs
- Estimate token consumption before making requests
- Use
max_tokensto limit maximum output
-
Regular Top-Ups
- Top up regularly based on usage
- Maintain sufficient balance buffer
Cost Optimization Tips
1. Choose Appropriate Model
Use different models for different scenarios:
# Use cheaper model for simple tasks
if task_complexity == "simple":
model = "gpt-3.5-turbo" # $0.50/M
elif task_complexity == "medium":
model = "gpt-4o-mini" # $0.15/M
else:
model = "gpt-4o" # $2.50/M2. Control Context Length
# Limit number of historical messages
MAX_HISTORY = 10
messages = conversation_history[-MAX_HISTORY:]
# Add new message
messages.append({"role": "user", "content": user_input})
response = client.chat.completions.create(
model="gpt-4o",
messages=messages
)3. Use max_tokens Limit
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Write an article"}],
max_tokens=500 # Limit maximum output
)4. Cache Common Responses
import hashlib
import json
cache = {}
def cached_completion(client, messages, **kwargs):
# Generate cache key
cache_key = hashlib.md5(
json.dumps({"messages": messages, **kwargs}).encode()
).hexdigest()
# Check cache
if cache_key in cache:
return cache[cache_key]
# Call API
response = client.chat.completions.create(
messages=messages,
**kwargs
)
# Save to cache
cache[cache_key] = response
return response5. Streaming Response Optimization
# Use streaming response, can terminate early
stream = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Tell me a story"}],
stream=True
)
collected_text = ""
for chunk in stream:
if chunk.choices[0].delta.content:
collected_text += chunk.choices[0].delta.content
# Terminate early when target length is reached
if len(collected_text) > 500:
breakCost Monitoring
View Usage Statistics
On the Wallet page you can view:
- By Time - Today, this week, this month spending
- By Model - Usage and cost for each model
- By API Key - Consumption for each key
- Trend Charts - Visualize spending trends
Export Transaction Records
(In development) Will support:
- CSV Export - Export to Excel-readable format
- JSON Export - Programmatic processing
- PDF Reports - Monthly billing reports
Billing Transparency
Token Counting
AgentRouter uses token counts returned by upstream providers:
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello!"}]
)
# View token usage
print(f"Input: {response.usage.prompt_tokens}")
print(f"Output: {response.usage.completion_tokens}")
print(f"Total: {response.usage.total_tokens}")Public Pricing
All model pricing is publicly transparent:
- View on Supported Models page
- Pricing consistent with upstream providers
- No hidden fees
Real-Time Billing
Each request is billed immediately after completion, with no delay.
Enterprise Features (In Development)
Team Wallets
- Team members share wallet balance
- Administrators allocate quotas
- Member usage statistics
Budget Control
- Set monthly budget limits
- Allocate budget by user or project
- Automatic restriction when budget exceeded
Invoice Management
- Automatically generate monthly invoices
- Support VAT invoices
- Enterprise information management
API Balance Query
Query Current Balance
import requests
response = requests.get(
"https://your-agentrouter.com/api/wallet/balance",
headers={"Authorization": "Bearer sk-ar-your-api-key"}
)
data = response.json()
print(f"Balance: ${data['balance']}")Query Transaction History
response = requests.get(
"https://your-agentrouter.com/api/wallet/transactions",
headers={"Authorization": "Bearer sk-ar-your-api-key"},
params={
"limit": 100,
"offset": 0
}
)
transactions = response.json()
for tx in transactions:
print(f"{tx['createdAt']}: {tx['amount']} ({tx['description']})")FAQ
1. Why did my balance suddenly decrease?
Check Transaction History, each deduction has a detailed explanation.
2. How do I estimate the cost of a request?
Use the following formula:
Cost ≈ (Estimated total tokens / 1,000,000) × Average priceOr use max_tokens to limit maximum cost.
3. Can I apply for a refund?
Automatic refunds are currently not supported. For special cases, please contact the support team.
4. Does balance expire?
No, wallet balance is permanently valid.
5. What is the minimum top-up amount?
Minimum $10 is recommended, but can be adjusted based on actual needs.
Next Steps
- Supported Models - View model pricing
- API Key Management - Manage API keys
- Getting Started - Start using API