API 密钥
获取当前 API 密钥
使用 CometAPI GET /api/usage/token 检索 bearer API 密钥的配额、用量、过期时间和模型限制详情。
GET
/
api
/
usage
/
token
cURL
curl https://api.cometapi.com/api/usage/token \
-H "Authorization: Bearer $COMETAPI_KEY"import requests
url = "https://api.cometapi.com/api/usage/token"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.cometapi.com/api/usage/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/usage/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: Bearer <token>"
],
]);
$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/usage/token"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
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/usage/token")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/api/usage/token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"code": true,
"message": "ok",
"data": {
"object": "token_usage",
"name": "production",
"total_granted": 150000,
"total_used": 50000,
"total_available": 100000,
"unlimited_quota": false,
"model_limits": {
"gpt-4.1": true
},
"model_limits_enabled": true,
"expires_at": 0
}
}使用此端点可检查请求中使用的 CometAPI API 密钥。它返回的是该 bearer 密钥的用量和配额字段,而不是账户级别的所有密钥列表。
此端点使用 CometAPI API 密钥:
Authorization: Bearer $COMETAPI_KEY。API 密钥管理端点使用单独的个人访问令牌。返回字段
| Field | Type | Description |
|---|---|---|
name | string | API 密钥的显示名称。 |
total_granted | integer | 分配给此密钥的总配额,以 CometAPI 内部配额单位计。 |
total_used | integer | 此密钥已消耗的配额,以 CometAPI 内部配额单位计。 |
total_available | integer | 此密钥剩余可用的配额,以 CometAPI 内部配额单位计。 |
unlimited_quota | boolean | 此密钥是否绕过剩余配额检查。 |
model_limits | object | 此密钥的模型限制,以 model ID 为键。未配置模型限制时为空。 |
model_limits_enabled | boolean | 此密钥的模型限制是否处于启用状态。 |
expires_at | integer | 此密钥过期时的 Unix 时间戳(秒)。在此用量响应中,0 表示不过期。 |
⌘I
cURL
curl https://api.cometapi.com/api/usage/token \
-H "Authorization: Bearer $COMETAPI_KEY"import requests
url = "https://api.cometapi.com/api/usage/token"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.cometapi.com/api/usage/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/usage/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: Bearer <token>"
],
]);
$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/usage/token"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
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/usage/token")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/api/usage/token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"code": true,
"message": "ok",
"data": {
"object": "token_usage",
"name": "production",
"total_granted": 150000,
"total_used": 50000,
"total_available": 100000,
"unlimited_quota": false,
"model_limits": {
"gpt-4.1": true
},
"model_limits_enabled": true,
"expires_at": 0
}
}