Khóa API
Liệt kê API key
Sử dụng CometAPI GET /api/token/ để liệt kê các API key của tài khoản đã xác thực với phân trang.
GET
/
api
/
token
/
cURL
curl "https://api.cometapi.com/api/token/?p=1&page_size=20" \
-H "Authorization: your-access-token"import requests
url = "https://api.cometapi.com/api/token/"
headers = {"Authorization": "<api-key>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: '<api-key>'}};
fetch('https://api.cometapi.com/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.cometapi.com/api/token/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.cometapi.com/api/token/"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "<api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.cometapi.com/api/token/")
.header("Authorization", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/api/token/")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = '<api-key>'
response = http.request(request)
puts response.read_body{
"success": true,
"message": "",
"data": {
"page": 1,
"page_size": 20,
"total": 1,
"items": [
{
"id": 1234,
"user_id": 5678,
"key": "$COMETAPI_KEY",
"status": 1,
"name": "production",
"created_time": 1766102400,
"accessed_time": 1766102400,
"expired_time": -1,
"remain_quota": 100000,
"unlimited_quota": false,
"model_limits_enabled": false,
"model_limits": "",
"allow_ips": null,
"used_quota": 0,
"group": "",
"cross_group_retry": false
}
]
}
}Sử dụng endpoint này để liệt kê các API key thuộc về tài khoản CometAPI đã xác thực. Các key mới nhất sẽ được trả về trước.
Tạo personal access token tại Console → Personal Settings, sau đó gửi nó dưới dạng giá trị thô của header
Authorization. Không thêm tiền tố Bearer.Phân trang
| Query parameter | Mô tả |
|---|---|
p | Số trang. Mặc định là 1. |
page_size | Số mục trên mỗi trang. Giá trị lớn hơn 100 sẽ bị giới hạn ở 100. |
Trạng thái API key
| Status | Ý nghĩa |
|---|---|
1 | Đã bật |
2 | Đã tắt |
3 | Đã hết hạn |
4 | Đã dùng hết |
Các trường được trả về
| Field | Type | Mô tả |
|---|---|---|
id | integer | ID API key dạng số. Sử dụng giá trị này với Lấy một API key, Cập nhật một API key, và Xóa một API key. |
key | string | Giá trị API key được trả về bởi management API. Hãy coi đây là thông tin bí mật và sử dụng nó dưới dạng Authorization: Bearer $COMETAPI_KEY cho các request model. |
status | integer | Trạng thái hoạt động. Chỉ 1 nghĩa là key được bật cho các request model. |
name | string | Tên hiển thị dễ đọc dành cho key. |
created_time | integer | Unix timestamp tính bằng giây tại thời điểm key được tạo. |
accessed_time | integer | Unix timestamp tính bằng giây tại thời điểm key được sử dụng lần cuối. |
expired_time | integer | Unix timestamp tính bằng giây tại thời điểm key hết hạn. -1 nghĩa là không hết hạn. |
remain_quota | integer | Hạn mức còn lại theo đơn vị hạn mức nội bộ của CometAPI. |
used_quota | integer | Hạn mức đã được key này tiêu thụ theo đơn vị hạn mức nội bộ của CometAPI. |
unlimited_quota | boolean | Key có bỏ qua kiểm tra hạn mức còn lại hay không. |
model_limits_enabled | boolean | Các hạn chế model có đang được áp dụng cho key này hay không. |
model_limits | string | Các model ID được phép dùng bởi key này, phân tách bằng dấu phẩy khi model_limits_enabled là true. Để trống nghĩa là không có danh sách model nào được cấu hình. |
allow_ips | string or null | Danh sách IP được phép dưới dạng một chuỗi phân tách bằng ký tự xuống dòng. Mỗi mục có thể là một địa chỉ IPv4 đơn, một địa chỉ IPv6 đơn, IPv4 CIDR hoặc IPv6 CIDR. null hoặc "" nghĩa là không có giới hạn IP. |
group | string | Giới hạn theo nhóm tài khoản. Để trống nghĩa là không có giới hạn nhóm cụ thể. |
cross_group_retry | boolean | Có bật retry liên nhóm để định tuyến nhóm tự động hay không. |
Ủy quyền
Personal access token copied from CometAPI Console > Personal Settings. Send the raw token value; do not prefix it with Bearer.
Tham số truy vấn
Page number to return. Defaults to 1.
Phạm vi bắt buộc:
x >= 1Number of keys per page. Values above 100 are capped at 100 by the backend.
Phạm vi bắt buộc:
1 <= x <= 100⌘I
cURL
curl "https://api.cometapi.com/api/token/?p=1&page_size=20" \
-H "Authorization: your-access-token"import requests
url = "https://api.cometapi.com/api/token/"
headers = {"Authorization": "<api-key>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: '<api-key>'}};
fetch('https://api.cometapi.com/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.cometapi.com/api/token/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.cometapi.com/api/token/"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "<api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.cometapi.com/api/token/")
.header("Authorization", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/api/token/")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = '<api-key>'
response = http.request(request)
puts response.read_body{
"success": true,
"message": "",
"data": {
"page": 1,
"page_size": 20,
"total": 1,
"items": [
{
"id": 1234,
"user_id": 5678,
"key": "$COMETAPI_KEY",
"status": 1,
"name": "production",
"created_time": 1766102400,
"accessed_time": 1766102400,
"expired_time": -1,
"remain_quota": 100000,
"unlimited_quota": false,
"model_limits_enabled": false,
"model_limits": "",
"allow_ips": null,
"used_quota": 0,
"group": "",
"cross_group_retry": false
}
]
}
}