資源
創建 API 密鑰
創建一個用於程序化訪問的新 API 密鑰。
POST
/
api
/
v1
/
keys
創建 API 密鑰
curl --request POST \
--url https://api.example.com/api/v1/keys \
--header 'Content-Type: application/json' \
--data '
{
"name": "<string>",
"scopes": [
"<string>"
],
"scope": {},
"org_id": "<string>"
}
'import requests
url = "https://api.example.com/api/v1/keys"
payload = {
"name": "<string>",
"scopes": ["<string>"],
"scope": {},
"org_id": "<string>"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({name: '<string>', scopes: ['<string>'], scope: {}, org_id: '<string>'})
};
fetch('https://api.example.com/api/v1/keys', 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/api/v1/keys",
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>',
'scopes' => [
'<string>'
],
'scope' => [
],
'org_id' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"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/api/v1/keys"
payload := strings.NewReader("{\n \"name\": \"<string>\",\n \"scopes\": [\n \"<string>\"\n ],\n \"scope\": {},\n \"org_id\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
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/api/v1/keys")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"<string>\",\n \"scopes\": [\n \"<string>\"\n ],\n \"scope\": {},\n \"org_id\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/v1/keys")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"<string>\",\n \"scopes\": [\n \"<string>\"\n ],\n \"scope\": {},\n \"org_id\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body創建一個新的 API 密鑰。完整的密鑰值僅在創建時返回一次。
團隊共享密鑰(指定特定組織):
身份驗證
需要提供 Bearer 令牌。參見身份驗證。請求體
string
便於識別的標籤(例如
"Production Server"、"Development")。string[]
該密鑰的權限範圍(例如
["completions", "skills"])。默認為全部範圍。'personal' | 'org'
聲明新密鑰是個人憑證(僅你可見)還是團隊憑證(與所屬組織的所有成員共享)。
"personal"— 創建個人密鑰。不得提供org_id。即使你擁有管理團隊密鑰的權限,服務器也永遠不會自動關聯你當前所在的團隊。"org"— 創建團隊共享密鑰。可提供org_id指定特定組織,或省略以回退到你當前的活動團隊上下文。
scope,服務器會自動推斷該值:若提供了 org_id 則為 "org",否則為 "personal"。string
用於限定密鑰所屬範圍的組織 UUID。當
scope 為 "org" 且調用方沒有活動團隊上下文時為必填項;當 scope 為 "personal" 時禁止提供。調用方必須擁有目標組織的 manageApiKeys 權限。請求示例
個人密鑰(顯式指定):curl -X POST https://www.hitheo.ai/api/v1/keys \
-H "Authorization: Bearer $THEO_API_KEY" \
-H "Content-Type: application/json" \
-d '{"name": "Production Server", "scope": "personal"}'
curl -X POST https://www.hitheo.ai/api/v1/keys \
-H "Authorization: Bearer $THEO_API_KEY" \
-H "Content-Type: application/json" \
-d '{"name": "CI pipeline", "scope": "org", "org_id": "org_123"}'
響應
返回創建的密鑰對象。完整的 API 密鑰字符串僅在此響應中包含一次——請妥善保存。完整的密鑰值僅在創建時顯示一次,之後將無法再次獲取。
端點
POST /api/v1/keys
需要通過 Bearer 令牌進行身份驗證。參見身份驗證。這個頁面有幫助嗎?
創建 API 密鑰
curl --request POST \
--url https://api.example.com/api/v1/keys \
--header 'Content-Type: application/json' \
--data '
{
"name": "<string>",
"scopes": [
"<string>"
],
"scope": {},
"org_id": "<string>"
}
'import requests
url = "https://api.example.com/api/v1/keys"
payload = {
"name": "<string>",
"scopes": ["<string>"],
"scope": {},
"org_id": "<string>"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({name: '<string>', scopes: ['<string>'], scope: {}, org_id: '<string>'})
};
fetch('https://api.example.com/api/v1/keys', 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/api/v1/keys",
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>',
'scopes' => [
'<string>'
],
'scope' => [
],
'org_id' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"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/api/v1/keys"
payload := strings.NewReader("{\n \"name\": \"<string>\",\n \"scopes\": [\n \"<string>\"\n ],\n \"scope\": {},\n \"org_id\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
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/api/v1/keys")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"<string>\",\n \"scopes\": [\n \"<string>\"\n ],\n \"scope\": {},\n \"org_id\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/v1/keys")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"<string>\",\n \"scopes\": [\n \"<string>\"\n ],\n \"scope\": {},\n \"org_id\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body