curl --request POST \
--url 'https://toapis.com/v1/tokens' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"name": "My New Token",
"expired_time": -1,
"remain_credits": 200,
"unlimited_quota": false
}'
import requests
API_BASE = 'https://toapis.com'
API_KEY = 'sk-xxxxxxxxxxxxxxxxxxxxxx'
headers = {
'Authorization': f'Bearer {API_KEY}',
'Content-Type': 'application/json'
}
def create_token():
payload = {
'name': 'My New Token',
'expired_time': -1, # Never expires
'remain_credits': 200,
'unlimited_quota': False
}
response = requests.post(
f'{API_BASE}/v1/tokens',
headers=headers,
json=payload
)
data = response.json()
if data.get('success'):
token_data = data['data']
print(f"Token created successfully!")
print(f"Token name: {token_data['name']}")
print(f"Token key: sk-{token_data['key']}")
print("Please store this key securely, it's only shown once!")
else:
print(f"Creation failed: {data.get('message')}")
return data
create_token()
const API_BASE = 'https://toapis.com';
const API_KEY = 'sk-xxxxxxxxxxxxxxxxxxxxxx';
async function createToken() {
const payload = {
name: 'My New Token',
expired_time: -1, // Never expires
remain_credits: 200,
unlimited_quota: false
};
const response = await fetch(`${API_BASE}/v1/tokens`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
});
const data = await response.json();
if (data.success) {
const tokenData = data.data;
console.log('Token created successfully!');
console.log(`Token name: ${tokenData.name}`);
console.log(`Token key: sk-${tokenData.key}`);
console.log("Please store this key securely, it's only shown once!");
} else {
console.error('Creation failed:', data.message);
}
return data;
}
createToken();
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
type CreateTokenRequest struct {
Name string `json:"name"`
ExpiredTime int64 `json:"expired_time"`
RemainCredits float64 `json:"remain_credits"`
UnlimitedQuota bool `json:"unlimited_quota"`
}
type TokenResponse struct {
Success bool `json:"success"`
Message string `json:"message,omitempty"`
Data struct {
Id int `json:"id"`
Key string `json:"key"`
Name string `json:"name"`
Status int `json:"status"`
CreatedTime int64 `json:"created_time"`
ExpiredTime int64 `json:"expired_time"`
RemainQuota int `json:"remain_quota"`
UnlimitedQuota bool `json:"unlimited_quota"`
} `json:"data"`
}
func main() {
url := "https://toapis.com/v1/tokens"
apiKey := "sk-xxxxxxxxxxxxxxxxxxxxxx"
payload := CreateTokenRequest{
Name: "My New Token",
ExpiredTime: -1,
RemainCredits: 200,
UnlimitedQuota: false,
}
jsonData, _ := json.Marshal(payload)
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
req.Header.Set("Authorization", "Bearer "+apiKey)
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
var result TokenResponse
json.Unmarshal(body, &result)
if result.Success {
fmt.Println("Token created successfully!")
fmt.Printf("Token name: %s\n", result.Data.Name)
fmt.Printf("Token key: sk-%s\n", result.Data.Key)
fmt.Println("Please store this key securely, it's only shown once!")
} else {
fmt.Printf("Creation failed: %s\n", result.Message)
}
}
<?php
$api_key = 'sk-xxxxxxxxxxxxxxxxxxxxxx';
$payload = [
'name' => 'My New Token',
'expired_time' => -1,
'remain_credits' => 200,
'unlimited_quota' => false
];
$ch = curl_init('https://toapis.com/v1/tokens');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer $api_key",
"Content-Type: application/json"
]);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
if ($data['success']) {
echo "Token created successfully!\n";
echo "Token name: " . $data['data']['name'] . "\n";
echo "Token key: sk-" . $data['data']['key'] . "\n";
echo "Please store this key securely, it's only shown once!\n";
} else {
echo "Creation failed: " . $data['message'] . "\n";
}
?>
{
"success": true,
"message": "",
"credits_per_usd": 200,
"data": {
"id": 123,
"user_id": 456,
"key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"status": 1,
"name": "My New Token",
"created_time": 1738483200,
"accessed_time": 1738483200,
"expired_time": -1,
"remain_quota": 500000,
"remain_credits": 200,
"unlimited_quota": false,
"used_quota": 0,
"used_credits": 0,
"daily_credits": 0,
"monthly_credits": 0,
"model_limits_enabled": false,
"model_limits": "",
"group": "",
"cross_group_retry": false
}
}
{
"success": false,
"message": "令牌名称过长"
}
{
"error": {
"code": 401,
"message": "Authentication failed, please check your API key",
"type": "authentication_error"
}
}
{
"error": {
"code": 429,
"message": "Too many requests, please try again later",
"type": "rate_limit_error"
}
}
Account
Create API Token
Create a new API token via API
POST
/
v1
/
tokens
curl --request POST \
--url 'https://toapis.com/v1/tokens' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"name": "My New Token",
"expired_time": -1,
"remain_credits": 200,
"unlimited_quota": false
}'
import requests
API_BASE = 'https://toapis.com'
API_KEY = 'sk-xxxxxxxxxxxxxxxxxxxxxx'
headers = {
'Authorization': f'Bearer {API_KEY}',
'Content-Type': 'application/json'
}
def create_token():
payload = {
'name': 'My New Token',
'expired_time': -1, # Never expires
'remain_credits': 200,
'unlimited_quota': False
}
response = requests.post(
f'{API_BASE}/v1/tokens',
headers=headers,
json=payload
)
data = response.json()
if data.get('success'):
token_data = data['data']
print(f"Token created successfully!")
print(f"Token name: {token_data['name']}")
print(f"Token key: sk-{token_data['key']}")
print("Please store this key securely, it's only shown once!")
else:
print(f"Creation failed: {data.get('message')}")
return data
create_token()
const API_BASE = 'https://toapis.com';
const API_KEY = 'sk-xxxxxxxxxxxxxxxxxxxxxx';
async function createToken() {
const payload = {
name: 'My New Token',
expired_time: -1, // Never expires
remain_credits: 200,
unlimited_quota: false
};
const response = await fetch(`${API_BASE}/v1/tokens`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
});
const data = await response.json();
if (data.success) {
const tokenData = data.data;
console.log('Token created successfully!');
console.log(`Token name: ${tokenData.name}`);
console.log(`Token key: sk-${tokenData.key}`);
console.log("Please store this key securely, it's only shown once!");
} else {
console.error('Creation failed:', data.message);
}
return data;
}
createToken();
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
type CreateTokenRequest struct {
Name string `json:"name"`
ExpiredTime int64 `json:"expired_time"`
RemainCredits float64 `json:"remain_credits"`
UnlimitedQuota bool `json:"unlimited_quota"`
}
type TokenResponse struct {
Success bool `json:"success"`
Message string `json:"message,omitempty"`
Data struct {
Id int `json:"id"`
Key string `json:"key"`
Name string `json:"name"`
Status int `json:"status"`
CreatedTime int64 `json:"created_time"`
ExpiredTime int64 `json:"expired_time"`
RemainQuota int `json:"remain_quota"`
UnlimitedQuota bool `json:"unlimited_quota"`
} `json:"data"`
}
func main() {
url := "https://toapis.com/v1/tokens"
apiKey := "sk-xxxxxxxxxxxxxxxxxxxxxx"
payload := CreateTokenRequest{
Name: "My New Token",
ExpiredTime: -1,
RemainCredits: 200,
UnlimitedQuota: false,
}
jsonData, _ := json.Marshal(payload)
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
req.Header.Set("Authorization", "Bearer "+apiKey)
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
var result TokenResponse
json.Unmarshal(body, &result)
if result.Success {
fmt.Println("Token created successfully!")
fmt.Printf("Token name: %s\n", result.Data.Name)
fmt.Printf("Token key: sk-%s\n", result.Data.Key)
fmt.Println("Please store this key securely, it's only shown once!")
} else {
fmt.Printf("Creation failed: %s\n", result.Message)
}
}
<?php
$api_key = 'sk-xxxxxxxxxxxxxxxxxxxxxx';
$payload = [
'name' => 'My New Token',
'expired_time' => -1,
'remain_credits' => 200,
'unlimited_quota' => false
];
$ch = curl_init('https://toapis.com/v1/tokens');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer $api_key",
"Content-Type: application/json"
]);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
if ($data['success']) {
echo "Token created successfully!\n";
echo "Token name: " . $data['data']['name'] . "\n";
echo "Token key: sk-" . $data['data']['key'] . "\n";
echo "Please store this key securely, it's only shown once!\n";
} else {
echo "Creation failed: " . $data['message'] . "\n";
}
?>
{
"success": true,
"message": "",
"credits_per_usd": 200,
"data": {
"id": 123,
"user_id": 456,
"key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"status": 1,
"name": "My New Token",
"created_time": 1738483200,
"accessed_time": 1738483200,
"expired_time": -1,
"remain_quota": 500000,
"remain_credits": 200,
"unlimited_quota": false,
"used_quota": 0,
"used_credits": 0,
"daily_credits": 0,
"monthly_credits": 0,
"model_limits_enabled": false,
"model_limits": "",
"group": "",
"cross_group_retry": false
}
}
{
"success": false,
"message": "令牌名称过长"
}
{
"error": {
"code": 401,
"message": "Authentication failed, please check your API key",
"type": "authentication_error"
}
}
{
"error": {
"code": 429,
"message": "Too many requests, please try again later",
"type": "rate_limit_error"
}
}
- Create a new API token via API
- Customize token name and expiration time
- Configure quota limits and model restrictions
- Token key is only returned once upon creation
Security NoticePlease securely store the returned token key (
key field). It is only displayed once upon creation and cannot be retrieved later.Authorizations
string
required
All endpoints require Bearer Token authenticationGet your API Key:Visit the API Key Management Page to get your API KeyAdd it to the request header:
Authorization: Bearer YOUR_API_KEY
Body
string
required
Token name, maximum 50 charactersExample:
"My New Token"integer
default:"-1"
Token expiration time (Unix timestamp in seconds)
- Set to
-1for never expires - Set to a specific timestamp to expire at that time
1738483200 (2025-02-02 00:00:00 UTC)integer
default:"0"
Token remaining quota (internal units)Conversion:
500000 = $1 USDExample: 500000 (equivalent to $1)float
default:"0"
Token remaining credits. If provided, it overrides
remain_quotaConversion: 200 credits = $1 USD = 500000 internal quotaExample: 200 (equivalent to $1)float
default:"0"
Daily token limit in credits. If provided, it is converted to
daily_quotaExample: 100 (equivalent to $0.5 daily limit)float
default:"0"
Monthly token limit in credits. If provided, it is converted to
monthly_quotaExample: 1000 (equivalent to $5 monthly limit)boolean
default:"false"
Whether the token has unlimited quota
true: Unlimited quota, no restrictionsfalse: Limited quota, usesremain_quotavalue
falseboolean
default:"false"
Whether to enable model restrictions
true: Enable model restrictions, only models inmodel_limitscan be usedfalse: No model restrictions
falsestring
default:""
List of allowed models (comma-separated)Only effective when
model_limits_enabled is trueExample: "gpt-4o,gpt-4o-mini,claude-3-5-sonnet"string
default:""
Token group nameUsed to specify the channel group for this tokenExample:
"default"Response
boolean
Whether the request was successful
string
Error message (only returned on failure)
object
Created token information (returned on success)
Show data field details
Show data field details
integer
Token ID
string
Token key (only returned once upon creation, please store securely)Format is a 48-character random string, use with
sk- prefixstring
Token name
integer
Token status
1: Enabled2: Disabled3: Expired4: Quota exhausted
integer
Owner user ID
integer
Creation time (Unix timestamp)
integer
Expiration time (Unix timestamp), -1 means never expires
integer
Remaining quota
float
Remaining credits, calculated with
1 USD = 200 creditsboolean
Whether it has unlimited quota
integer
Used quota
float
Used credits
float
Daily limit in credits
float
Monthly limit in credits
boolean
Whether model limits are enabled
string
Model limits list
string
Group name
curl --request POST \
--url 'https://toapis.com/v1/tokens' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"name": "My New Token",
"expired_time": -1,
"remain_credits": 200,
"unlimited_quota": false
}'
import requests
API_BASE = 'https://toapis.com'
API_KEY = 'sk-xxxxxxxxxxxxxxxxxxxxxx'
headers = {
'Authorization': f'Bearer {API_KEY}',
'Content-Type': 'application/json'
}
def create_token():
payload = {
'name': 'My New Token',
'expired_time': -1, # Never expires
'remain_credits': 200,
'unlimited_quota': False
}
response = requests.post(
f'{API_BASE}/v1/tokens',
headers=headers,
json=payload
)
data = response.json()
if data.get('success'):
token_data = data['data']
print(f"Token created successfully!")
print(f"Token name: {token_data['name']}")
print(f"Token key: sk-{token_data['key']}")
print("Please store this key securely, it's only shown once!")
else:
print(f"Creation failed: {data.get('message')}")
return data
create_token()
const API_BASE = 'https://toapis.com';
const API_KEY = 'sk-xxxxxxxxxxxxxxxxxxxxxx';
async function createToken() {
const payload = {
name: 'My New Token',
expired_time: -1, // Never expires
remain_credits: 200,
unlimited_quota: false
};
const response = await fetch(`${API_BASE}/v1/tokens`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
});
const data = await response.json();
if (data.success) {
const tokenData = data.data;
console.log('Token created successfully!');
console.log(`Token name: ${tokenData.name}`);
console.log(`Token key: sk-${tokenData.key}`);
console.log("Please store this key securely, it's only shown once!");
} else {
console.error('Creation failed:', data.message);
}
return data;
}
createToken();
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
type CreateTokenRequest struct {
Name string `json:"name"`
ExpiredTime int64 `json:"expired_time"`
RemainCredits float64 `json:"remain_credits"`
UnlimitedQuota bool `json:"unlimited_quota"`
}
type TokenResponse struct {
Success bool `json:"success"`
Message string `json:"message,omitempty"`
Data struct {
Id int `json:"id"`
Key string `json:"key"`
Name string `json:"name"`
Status int `json:"status"`
CreatedTime int64 `json:"created_time"`
ExpiredTime int64 `json:"expired_time"`
RemainQuota int `json:"remain_quota"`
UnlimitedQuota bool `json:"unlimited_quota"`
} `json:"data"`
}
func main() {
url := "https://toapis.com/v1/tokens"
apiKey := "sk-xxxxxxxxxxxxxxxxxxxxxx"
payload := CreateTokenRequest{
Name: "My New Token",
ExpiredTime: -1,
RemainCredits: 200,
UnlimitedQuota: false,
}
jsonData, _ := json.Marshal(payload)
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
req.Header.Set("Authorization", "Bearer "+apiKey)
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
var result TokenResponse
json.Unmarshal(body, &result)
if result.Success {
fmt.Println("Token created successfully!")
fmt.Printf("Token name: %s\n", result.Data.Name)
fmt.Printf("Token key: sk-%s\n", result.Data.Key)
fmt.Println("Please store this key securely, it's only shown once!")
} else {
fmt.Printf("Creation failed: %s\n", result.Message)
}
}
<?php
$api_key = 'sk-xxxxxxxxxxxxxxxxxxxxxx';
$payload = [
'name' => 'My New Token',
'expired_time' => -1,
'remain_credits' => 200,
'unlimited_quota' => false
];
$ch = curl_init('https://toapis.com/v1/tokens');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer $api_key",
"Content-Type: application/json"
]);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
if ($data['success']) {
echo "Token created successfully!\n";
echo "Token name: " . $data['data']['name'] . "\n";
echo "Token key: sk-" . $data['data']['key'] . "\n";
echo "Please store this key securely, it's only shown once!\n";
} else {
echo "Creation failed: " . $data['message'] . "\n";
}
?>
{
"success": true,
"message": "",
"credits_per_usd": 200,
"data": {
"id": 123,
"user_id": 456,
"key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"status": 1,
"name": "My New Token",
"created_time": 1738483200,
"accessed_time": 1738483200,
"expired_time": -1,
"remain_quota": 500000,
"remain_credits": 200,
"unlimited_quota": false,
"used_quota": 0,
"used_credits": 0,
"daily_credits": 0,
"monthly_credits": 0,
"model_limits_enabled": false,
"model_limits": "",
"group": "",
"cross_group_retry": false
}
}
{
"success": false,
"message": "令牌名称过长"
}
{
"error": {
"code": 401,
"message": "Authentication failed, please check your API key",
"type": "authentication_error"
}
}
{
"error": {
"code": 429,
"message": "Too many requests, please try again later",
"type": "rate_limit_error"
}
}
Use Cases
- Automate creation of multiple API tokens
- Create separate tokens for different applications or services
- Batch manage token lifecycle through scripts
Token Key FormatThe
key field returned upon success is a 48-character random string. When using, add the sk- prefix for the complete format: sk-xxxxxxxx...Best Practices
- Create different tokens for different purposes for easier tracking and management
- Set reasonable expiration times and rotate tokens regularly
- Enable model limits if you only need access to specific models for enhanced security
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| 令牌名称过长 | Name exceeds 50 characters | Use a shorter token name |
| 生成令牌失败 | Internal system error | Retry later or contact support |
| Authentication failed | API Key is invalid or expired | Check if the API Key is correct |
Security Notice
- The created token key is only returned once in the response, save it immediately
- Do not hardcode API Keys in client-side code
- Always use HTTPS in production
- Create separate tokens for each application for easier management and revocation
⌘I