Quick Start Guide
This guide walks you through the complete process of using Sub2API, from registration to monitoring your usage.
Prerequisites
- A valid email address
- A payment method (credit card via Stripe)
- Minimum $10 USD for initial top-up
Step 1: Sign Up and Verify Email
- Visit app.tokenlio.ai
- Click Sign Up
- Enter your email and create a password
- Check your email for the verification link
- Click the link to verify your account
- Log in to access your personal workspace
Step 2: Top Up Your Balance
Sub2API uses a prepaid, pay-as-you-go model. You need to add credit before making API calls.
- Navigate to Billing in the left sidebar
- Click Top Up Balance
- Enter the amount (minimum $10 USD)
- Click Proceed to Payment
- Complete payment through Stripe
- Your balance will be credited immediately
Payment Notes
- We accept major credit cards via Stripe
- Minimum top-up: $10 USD
- All transactions are secure and encrypted
- You'll receive a receipt via email
Step 3: Create an API Key
API keys authenticate your requests to Sub2API.
- Go to API Keys in the console
- Click Create New Key
- Enter a descriptive name:
Developmentfor testingProductionfor live applicationsProject Namefor specific projects
- (Optional) Set quota limits
- Click Create
- Copy the key immediately - it will only be shown once
- Store it securely
WARNING
Your API key will only be displayed once at creation. If you lose it, you'll need to create a new one.
Key Security
- Store keys in environment variables
- Never commit keys to version control
- Use different keys for development and production
- Disable or delete unused keys
Step 4: Make Your First Request
Now you're ready to call the API!
Using cURL
curl https://api.tokenlio.ai/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "gpt-4-turbo",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is Sub2API?"}
]
}'Using Python
First, install the OpenAI SDK:
pip install openaiThen use it with Sub2API:
from openai import OpenAI
# Initialize client with Sub2API
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.tokenlio.ai/v1"
)
# Make a request
response = client.chat.completions.create(
model="gpt-4-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is Sub2API?"}
],
temperature=0.7,
max_tokens=150
)
print(response.choices[0].message.content)Using Node.js
First, install the OpenAI SDK:
npm install openaiThen use it with Sub2API:
import OpenAI from 'openai';
// Initialize client with Sub2API
const client = new OpenAI({
apiKey: process.env.SUB2API_KEY,
baseURL: 'https://api.tokenlio.ai/v1',
});
async function main() {
const response = await client.chat.completions.create({
model: 'gpt-4-turbo',
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'What is Sub2API?' }
],
temperature: 0.7,
max_tokens: 150,
});
console.log(response.choices[0].message.content);
}
main();Streaming Responses
Sub2API supports streaming for real-time token generation:
stream = client.chat.completions.create(
model="gpt-4-turbo",
messages=[{"role": "user", "content": "Tell me a story"}],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")Step 5: Monitor Your Usage
Track your API usage and costs in real-time.
View Usage Summary
- Go to Usage in the console
- Select a time range (today, week, month, custom)
- View:
- Total requests
- Tokens consumed (input/output)
- Total cost
- Breakdown by model
Check Request Logs
- Navigate to Request Logs
- See detailed information for each request:
- Timestamp
- Model used
- Token counts
- Cost
- Status (success/error)
- Request ID (for support)
Monitor Balance
Your current balance is always visible in the top bar. When balance runs low:
- You'll receive email notifications
- Requests will fail with insufficient balance errors
- Top up to resume service
Step 6: Using with Teams (Optional)
If you're working with a team, create an organization workspace:
- Click your profile in the top right
- Select Create Organization
- Name your organization
- Top up the organization balance
- Go to Organization > Members
- Click Invite Member
- Enter their email address
- They'll receive an invitation link
Organization Benefits
- Shared billing: One balance for the whole team
- Centralized management: Owner controls all settings
- Individual keys: Each member creates their own keys
- Usage tracking: See which keys consume what resources
Learn more in our Team Collaboration Guide (coming soon).
Common Error Codes
| Code | Meaning | Solution |
|---|---|---|
| 401 | Invalid API key | Check your key is correct and active |
| 402 | Insufficient balance | Top up your account |
| 429 | Rate limit exceeded | Reduce request frequency or contact support |
| 500 | Server error | Retry or contact support |
Best Practices
Environment Setup
Create a .env file for your API key:
SUB2API_KEY=your_key_hereLoad it in your application:
# Python
import os
from dotenv import load_dotenv
load_dotenv()
api_key = os.getenv('SUB2API_KEY')// Node.js
import 'dotenv/config';
const apiKey = process.env.SUB2API_KEY;Error Handling
Always wrap API calls in error handling:
from openai import OpenAI, OpenAIError
try:
response = client.chat.completions.create(...)
except OpenAIError as e:
print(f"API error: {e}")
# Handle error (log, retry, alert, etc.)Rate Limiting
Be mindful of rate limits:
- Implement exponential backoff for retries
- Cache responses when possible
- Use streaming for long responses
- Monitor usage to avoid surprises
Next Steps
Now that you're up and running:
- Explore available models and their pricing
- Learn about authentication in detail
- Read the API reference for advanced features
- Review billing details to optimize costs
Getting Help
If you encounter issues:
- Check the FAQ for common questions
- Review error codes above
- Email support@tokenlio.ai
- Include your request ID for faster support