Skip to content

分发令牌管理 API

  • Endpoint Name: Get All Tokens
  • HTTP Method: GET
  • Path: /api/token/
  • Authentication: User
  • Description: Retrieve a paginated list of all tokens belonging to the current user

💡 Request Example:

const response = await fetch('https://api.4allapi.com/api/token/?p=1&size=20', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer your_user_token',
'New-Api-User': 'your_user_id'
}
});
const data = await response.json();

✅ Success Response Example:

{
"success": true,
"message": "",
"data": {
"items": [
{
"id": 1,
"name": "API Token",
"key": "<YOUR_API_KEY>",
"status": 1,
"remain_quota": 1000000,
"unlimited_quota": false,
"expired_time": 1640995200,
"created_time": 1640908800,
"accessed_time": 1640995000
}
],
"total": 5,
"page": 1,
"page_size": 20
}
}

❗ Failure Response Example:

{
"success": false,
"message": "Failed to retrieve token list"
}

🧾 Field Descriptions:

  • p (number): Page number, defaults to 1
  • size (number): Number of items per page, defaults to 20
  • items (array): List of token information
  • total (number): Total number of tokens
  • page (number): Current page number
  • page_size (number): Number of items per page
  • Endpoint Name: Get Single Token
  • HTTP Method: GET
  • Path: /api/token/:id
  • Authentication: User
  • Description: Retrieve detailed information for a specified token

💡 Request Example:

const response = await fetch('https://api.4allapi.com/api/token/123', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer your_user_token',
'New-Api-User': 'your_user_id'
}
});
const data = await response.json();

✅ Success Response Example:

{
"success": true,
"message": "",
"data": {
"id": 123,
"name": "API Token",
"key": "sk-your-token-placeholder",
"status": 1,
"remain_quota": 1000000,
"unlimited_quota": false,
"model_limits_enabled": true,
"model_limits": "gpt-3.5-turbo,gpt-4",
"allow_ips": "192.168.1.1,10.0.0.1",
"group": "default",
"expired_time": 1640995200,
"created_time": 1640908800,
"accessed_time": 1640995000
}
}

❗ Failure Response Example:

{
"success": false,
"message": "Token does not exist"
}

🧾 Field Descriptions:

id (number): Token ID, passed through the URL path

  • Endpoint Name: Create Token
  • HTTP Method: POST
  • Path: /api/token/
  • Authentication: User
  • Description: Create a new API token; batch creation is supported

💡 Request Example:

const response = await fetch('https://api.4allapi.com/api/token/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer your_user_token',
'New-Api-User': 'your_user_id'
},
body: JSON.stringify({
name: "My API Token",
expired_time: 1640995200,
remain_quota: 1000000,
unlimited_quota: false,
model_limits_enabled: true,
model_limits": ["gpt-3.5-turbo", "gpt-4"],
allow_ips": "192.168.1.1,10.0.0.1",
group": "default"
})
});
const data = await response.json();

✅ Success Response Example:

{
"success": true,
"message": ""
}

❗ Failure Response Example:

{
"success": false,
"message": "Token name is too long"
}

🧾 Field Descriptions:

  • name (string): Token name, maximum length 30 characters
  • expired_time (number): Expiration timestamp, -1 means never expires
  • remain_quota (number): Remaining quota
  • unlimited_quota (boolean): Whether quota is unlimited
  • model_limits_enabled (boolean): Whether model restrictions are enabled
  • model_limits (array): List of allowed models
  • allow_ips (string): Allowed IP addresses, separated by commas
  • group (string): Associated group
  • Endpoint Name: Update Token
  • HTTP Method: PUT
  • Path: /api/token/
  • Authentication: User
  • Description: Update token configuration; supports status-only changes and full updates

💡 Request Example (full update):

const response = await fetch('https://api.4allapi.com/api/token/', {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer your_user_token',
'New-Api-User': 'your_user_id'
},
body: JSON.stringify({
id: 123,
name: "Updated Token",
expired_time: 1640995200,
remain_quota: 2000000,
unlimited_quota: false,
model_limits_enabled: true,
model_limits": ["gpt-3.5-turbo", "gpt-4"],
allow_ips": "192.168.1.1",
group": "vip"
})
});
const data = await response.json();

💡 Request Example (status update only):

const response = await fetch('https://api.4allapi.com/api/token/?status_only=true', {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer your_user_token',
'New-Api-User': 'your_user_id'
},
body: JSON.stringify({
id: 123,
status": 1
})
});
const data = await response.json();

✅ Success Response Example:

{
"success": true,
"message": "",
"data": {
"id": 123,
"name": "Updated Token",
"status": 1
}
}

❗ Failure Response Example:

{
"success": false,
"message": "The token has expired and cannot be enabled. Please update the token expiration time first, or set it to never expire"
}

🧾 Field Descriptions:

  • id (number): Token ID, required
  • status_only (query parameter): Whether to update status only
  • Other fields are the same as the Create Token endpoint and are all optional
  • Endpoint Name: Delete Token
  • HTTP Method: DELETE
  • Path: /api/token/:id
  • Authentication: User
  • Description: Delete the specified token

💡 Request Example:

const response = await fetch('https://api.4allapi.com/api/token/123', {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer your_user_token',
'New-Api-User': 'your_user_id'
}
});
const data = await response.json();

✅ Success Response Example:

{
"success": true,
"message": ""
}

❗ Failure Response Example:

{
"success": false,
"message": "Token does not exist"
}

🧾 Field Descriptions:

id (number): Token ID, passed through the URL path

  • Endpoint Name: Batch Delete Tokens
  • HTTP Method: POST
  • Path: /api/token/batch
  • Authentication: User
  • Description: Delete multiple tokens in a batch

💡 Request Example:

const response = await fetch('https://api.4allapi.com/api/token/batch', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer your_user_token',
'New-Api-User': 'your_user_id'
},
body: JSON.stringify({
ids": [1, 2, 3, 4, 5]
})
});
const data = await response.json();

✅ Success Response Example:

{
"success": true,
"message": "",
"data": 5
}

❗ Failure Response Example:

{
"success": false,
"message": "Invalid parameters"
}

🧾 Field Descriptions:

  • ids (array): List of token IDs to delete, required and cannot be empty
  • data (number): Number of tokens successfully deleted

4All API · One-stop AI large model API aggregation platform | Pricing | Contact Us

© 2025 4All API. All rights reserved.