创建令牌
curl --request POST \
--url 'https://api.example.com/{{llmApiOrigin}}/api/token/' \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "<string>",
"remain_quota": 123,
"expired_time": 123,
"unlimited_quota": true,
"model_limits_enabled": true,
"model_limits": [
{}
],
"allow_ips": "<string>",
"group": "<string>"
}
'import requests
url = "https://api.example.com/{{llmApiOrigin}}/api/token/"
payload = {
"name": "<string>",
"remain_quota": 123,
"expired_time": 123,
"unlimited_quota": True,
"model_limits_enabled": True,
"model_limits": [{}],
"allow_ips": "<string>",
"group": "<string>"
}
headers = {
"Authorization": "<authorization>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<authorization>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: '<string>',
remain_quota: 123,
expired_time: 123,
unlimited_quota: true,
model_limits_enabled: true,
model_limits: [{}],
allow_ips: '<string>',
group: '<string>'
})
};
fetch('https://api.example.com/{{llmApiOrigin}}/api/token/', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/{{llmApiOrigin}}/api/token/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => '<string>',
'remain_quota' => 123,
'expired_time' => 123,
'unlimited_quota' => true,
'model_limits_enabled' => true,
'model_limits' => [
[
]
],
'allow_ips' => '<string>',
'group' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/{{llmApiOrigin}}/api/token/"
payload := strings.NewReader("{\n \"name\": \"<string>\",\n \"remain_quota\": 123,\n \"expired_time\": 123,\n \"unlimited_quota\": true,\n \"model_limits_enabled\": true,\n \"model_limits\": [\n {}\n ],\n \"allow_ips\": \"<string>\",\n \"group\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<authorization>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/{{llmApiOrigin}}/api/token/")
.header("Authorization", "<authorization>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"<string>\",\n \"remain_quota\": 123,\n \"expired_time\": 123,\n \"unlimited_quota\": true,\n \"model_limits_enabled\": true,\n \"model_limits\": [\n {}\n ],\n \"allow_ips\": \"<string>\",\n \"group\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/{{llmApiOrigin}}/api/token/")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<authorization>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"<string>\",\n \"remain_quota\": 123,\n \"expired_time\": 123,\n \"unlimited_quota\": true,\n \"model_limits_enabled\": true,\n \"model_limits\": [\n {}\n ],\n \"allow_ips\": \"<string>\",\n \"group\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"message": "",
"data": {
"id": 1,
"name": "my-token",
"key": "sk-xxxxxxxxxxxxxxxx",
"status": 1,
"remain_quota": 1000000,
"expired_time": 1767225600,
"unlimited_quota": false
}
}
令牌管理
创建令牌
POST
{llmApiOrigin}
/
api
/
token
/
创建令牌
curl --request POST \
--url 'https://api.example.com/{{llmApiOrigin}}/api/token/' \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "<string>",
"remain_quota": 123,
"expired_time": 123,
"unlimited_quota": true,
"model_limits_enabled": true,
"model_limits": [
{}
],
"allow_ips": "<string>",
"group": "<string>"
}
'import requests
url = "https://api.example.com/{{llmApiOrigin}}/api/token/"
payload = {
"name": "<string>",
"remain_quota": 123,
"expired_time": 123,
"unlimited_quota": True,
"model_limits_enabled": True,
"model_limits": [{}],
"allow_ips": "<string>",
"group": "<string>"
}
headers = {
"Authorization": "<authorization>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<authorization>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: '<string>',
remain_quota: 123,
expired_time: 123,
unlimited_quota: true,
model_limits_enabled: true,
model_limits: [{}],
allow_ips: '<string>',
group: '<string>'
})
};
fetch('https://api.example.com/{{llmApiOrigin}}/api/token/', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/{{llmApiOrigin}}/api/token/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => '<string>',
'remain_quota' => 123,
'expired_time' => 123,
'unlimited_quota' => true,
'model_limits_enabled' => true,
'model_limits' => [
[
]
],
'allow_ips' => '<string>',
'group' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/{{llmApiOrigin}}/api/token/"
payload := strings.NewReader("{\n \"name\": \"<string>\",\n \"remain_quota\": 123,\n \"expired_time\": 123,\n \"unlimited_quota\": true,\n \"model_limits_enabled\": true,\n \"model_limits\": [\n {}\n ],\n \"allow_ips\": \"<string>\",\n \"group\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<authorization>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/{{llmApiOrigin}}/api/token/")
.header("Authorization", "<authorization>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"<string>\",\n \"remain_quota\": 123,\n \"expired_time\": 123,\n \"unlimited_quota\": true,\n \"model_limits_enabled\": true,\n \"model_limits\": [\n {}\n ],\n \"allow_ips\": \"<string>\",\n \"group\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/{{llmApiOrigin}}/api/token/")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<authorization>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"<string>\",\n \"remain_quota\": 123,\n \"expired_time\": 123,\n \"unlimited_quota\": true,\n \"model_limits_enabled\": true,\n \"model_limits\": [\n {}\n ],\n \"allow_ips\": \"<string>\",\n \"group\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"message": "",
"data": {
"id": 1,
"name": "my-token",
"key": "sk-xxxxxxxxxxxxxxxx",
"status": 1,
"remain_quota": 1000000,
"expired_time": 1767225600,
"unlimited_quota": false
}
}
简介
创建新的 API 令牌。此接口需要登录(User 权限)后调用。认证
string
必填
Bearer Token,如
Bearer sk-xxxxxxxxxx请求参数
string
必填
令牌名称,用于标识该令牌的用途。
number
令牌剩余额度,不传则默认不限额度。
integer
令牌过期时间(Unix 时间戳,秒),不传则永不过期。
boolean
默认值:"true"
是否不限额度。
boolean
是否启用模型限制。
array
模型限制列表,当
model_limits_enabled 为 true 时生效。string
允许访问的 IP 列表,多个 IP 用逗号分隔。
string
令牌所属分组。
代码示例
- cURL
- Python
- Node.js
curl -X POST "https://api-test.shengmoai.com/api/token/" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-xxxxxxxxxx" \
-d '{
"name": "my-token",
"remain_quota": 1000000,
"expired_time": 1767225600,
"unlimited_quota": false
}'
import requests
url = "https://api-test.shengmoai.com/api/token/"
headers = {
"Authorization": "Bearer sk-xxxxxxxxxx",
"Content-Type": "application/json"
}
data = {
"name": "my-token",
"remain_quota": 1000000,
"expired_time": 1767225600,
"unlimited_quota": False
}
response = requests.post(url, headers=headers, json=data)
print(response.json())
const axios = require('axios');
const response = await axios.post(
'https://api-test.shengmoai.com/api/token/',
{
name: 'my-token',
remain_quota: 1000000,
expired_time: 1767225600,
unlimited_quota: false
},
{
headers: {
'Authorization': 'Bearer sk-xxxxxxxxxx',
'Content-Type': 'application/json'
}
}
);
console.log(response.data);
响应示例
{
"success": true,
"message": "",
"data": {
"id": 1,
"name": "my-token",
"key": "sk-xxxxxxxxxxxxxxxx",
"status": 1,
"remain_quota": 1000000,
"expired_time": 1767225600,
"unlimited_quota": false
}
}
HTTP 状态码
| 状态码 | 说明 |
|---|---|
| 200 | 请求成功 |
| 401 | 未登录或令牌无效 |
| 400 | 请求参数错误 |
注意事项
- 创建令牌会直接授予 API 访问权限,请妥善保管返回的
key字段 - 令牌创建后
key仅在创建响应中完整返回,请及时保存
