مفاتيح API
استرجاع مفتاح API
استخدم CometAPI GET /api/token/ لاسترجاع سجل مفتاح API واحد حسب المعرّف للحساب المصادق عليه.
GET
/
api
/
token
/
{id}
cURL
curl https://api.cometapi.com/api/token/1234 \
-H "Authorization: your-access-token"import requests
url = "https://api.cometapi.com/api/token/{id}"
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/{id}', 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/{id}",
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/{id}"
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/{id}")
.header("Authorization", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/api/token/{id}")
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": {
"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
}
}استخدم نقطة النهاية هذه لاسترجاع سجل مفتاح API واحد حسب المعرّف.
المعلمة
أنشئ personal access token من Console → Personal Settings، ثم أرسله كقيمة خام لترويسة
Authorization. لا تضف إليه البادئة Bearer.id في المسار هي معرّف المفتاح الرقمي الذي يتم إرجاعه من List API keys.
حالة مفتاح API
| Status | Meaning |
|---|---|
1 | مفعّل |
2 | معطّل |
3 | منتهي الصلاحية |
4 | مستنفد |
الحقول المُعادة
| Field | Type | Description |
|---|---|---|
id | integer | معرّف مفتاح API رقمي. استخدم هذه القيمة مع Update an API key وDelete an API key. |
key | string | قيمة مفتاح API التي تُعيدها management API. تعامل معها على أنها سر، واستخدمها بالشكل Authorization: Bearer $COMETAPI_KEY لطلبات model. |
status | integer | حالة التشغيل. فقط القيمة 1 تعني أن المفتاح مفعّل لطلبات model. |
name | string | اسم عرض مقروء للمستخدم لهذا المفتاح. |
created_time | integer | طابع زمني Unix بالثواني عند إنشاء المفتاح. |
accessed_time | integer | طابع زمني Unix بالثواني لآخر مرة استُخدم فيها المفتاح. |
expired_time | integer | طابع زمني Unix بالثواني عند انتهاء صلاحية المفتاح. تعني -1 عدم وجود انتهاء صلاحية. |
remain_quota | integer | الحصة المتبقية بوحدات الحصة الداخلية في CometAPI. |
used_quota | integer | الحصة التي استُهلكت بالفعل بواسطة هذا المفتاح بوحدات الحصة الداخلية في CometAPI. |
unlimited_quota | boolean | ما إذا كان المفتاح يتجاوز فحوصات الحصة المتبقية. |
model_limits_enabled | boolean | ما إذا كانت قيود model مفعّلة لهذا المفتاح. |
model_limits | string | model ID مفصولة بفواصل ومسموح بها لهذا المفتاح عندما تكون model_limits_enabled هي true. القيمة الفارغة تعني عدم وجود قائمة model مُعدّة. |
allow_ips | string or null | قائمة سماح IP كسلسلة واحدة مفصولة بأسطر جديدة. يمكن أن يكون كل إدخال عنوان IPv4 واحدًا، أو عنوان IPv6 واحدًا، أو IPv4 CIDR، أو IPv6 CIDR. تعني null أو "" عدم وجود قيود IP. |
group | string | تقييد مجموعة الحساب. القيمة الفارغة تعني عدم وجود تقييد صريح للمجموعة. |
cross_group_retry | boolean | ما إذا كانت إعادة المحاولة عبر المجموعات مفعّلة للتوجيه التلقائي بين المجموعات. |
التفويضات
Personal access token copied from CometAPI Console > Personal Settings. Send the raw token value; do not prefix it with Bearer.
معلمات المسار
Numeric API key ID returned by the list endpoint.
⌘I
cURL
curl https://api.cometapi.com/api/token/1234 \
-H "Authorization: your-access-token"import requests
url = "https://api.cometapi.com/api/token/{id}"
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/{id}', 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/{id}",
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/{id}"
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/{id}")
.header("Authorization", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/api/token/{id}")
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": {
"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
}
}