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
}
}