资源
创建 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