创建 Webhook 端点
curl --request POST \
--url https://api.tokenlab.sh/v1/management/webhooks \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"url": "<string>",
"events": [],
"description": "<string>"
}
'import requests
url = "https://api.tokenlab.sh/v1/management/webhooks"
payload = {
"url": "<string>",
"events": [],
"description": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({url: '<string>', events: [], description: '<string>'})
};
fetch('https://api.tokenlab.sh/v1/management/webhooks', 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.tokenlab.sh/v1/management/webhooks",
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([
'url' => '<string>',
'events' => [
],
'description' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"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.tokenlab.sh/v1/management/webhooks"
payload := strings.NewReader("{\n \"url\": \"<string>\",\n \"events\": [],\n \"description\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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.tokenlab.sh/v1/management/webhooks")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"url\": \"<string>\",\n \"events\": [],\n \"description\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.tokenlab.sh/v1/management/webhooks")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"url\": \"<string>\",\n \"events\": [],\n \"description\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"object": "webhook_endpoint",
"url": "<string>",
"events": [
"task.completed"
],
"is_active": true,
"description": "<string>",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"last_delivered_at": "2023-11-07T05:31:56Z",
"failure_count": 123,
"secret": "<string>"
}{
"error": {
"message": "model: Model is required",
"type": "invalid_request_error",
"param": "model"
},
"validation_errors": [
{
"field": "model",
"message": "Model is required"
}
]
}{
"error": {
"message": "Invalid API key provided",
"type": "invalid_api_key"
}
}{
"error": {
"message": "Organization is not active",
"type": "invalid_request_error"
}
}{
"error": {
"message": "<string>",
"type": "unauthorized",
"code": "<string>",
"param": "<string>",
"model": "<string>",
"did_you_mean": "<string>",
"suggestions": [
{
"id": "<string>"
}
],
"alternatives": [
{
"id": "<string>",
"status": "<string>",
"tags": [
"<string>"
]
}
],
"hint": "<string>",
"retry_after": 123,
"retryable": true,
"balance_usd": 123,
"estimated_cost_usd": 123,
"supported_operations": [
"<string>"
],
"supported_parameters": [
"<string>"
],
"required_selectors": [
"<string>"
],
"optional_selectors": [
"<string>"
],
"allowed_resolutions": [
"<string>"
],
"allowed_durations": [
"<string>"
],
"allowed_aspect_ratios": [
"<string>"
],
"prompt_max_characters": 123,
"recommended_request": {},
"request_endpoint": "<string>",
"request_shape_mode": "<string>",
"status_mode": "<string>",
"request_id": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "unauthorized",
"code": "<string>",
"param": "<string>",
"model": "<string>",
"did_you_mean": "<string>",
"suggestions": [
{
"id": "<string>"
}
],
"alternatives": [
{
"id": "<string>",
"status": "<string>",
"tags": [
"<string>"
]
}
],
"hint": "<string>",
"retry_after": 123,
"retryable": true,
"balance_usd": 123,
"estimated_cost_usd": 123,
"supported_operations": [
"<string>"
],
"supported_parameters": [
"<string>"
],
"required_selectors": [
"<string>"
],
"optional_selectors": [
"<string>"
],
"allowed_resolutions": [
"<string>"
],
"allowed_durations": [
"<string>"
],
"allowed_aspect_ratios": [
"<string>"
],
"prompt_max_characters": 123,
"recommended_request": {},
"request_endpoint": "<string>",
"request_shape_mode": "<string>",
"status_mode": "<string>",
"request_id": "<string>"
}
}管理
创建 Webhook
需要工作区 Management Token (mt-…),可在 Dashboard > API > Management Tokens 中创建。发送 Authorization: Bearer mt-…。不支持 Inference API keys (sk-…) 和 Webhook 签名密钥 (whsec_…)。仅可访问该 token 所属的工作区。完整的 whsec_ 签名密钥仅在创建或轮换时返回。请妥善存储;GET/list 操作不会返回该密钥。轮换对新的投递立即生效;已在传输中的投递仍可使用之前的密钥。每个工作区最多支持 10 个端点。订阅涵盖未来的终端异步任务事件;不会重放现有任务。
POST
/
v1
/
management
/
webhooks
创建 Webhook 端点
curl --request POST \
--url https://api.tokenlab.sh/v1/management/webhooks \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"url": "<string>",
"events": [],
"description": "<string>"
}
'import requests
url = "https://api.tokenlab.sh/v1/management/webhooks"
payload = {
"url": "<string>",
"events": [],
"description": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({url: '<string>', events: [], description: '<string>'})
};
fetch('https://api.tokenlab.sh/v1/management/webhooks', 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.tokenlab.sh/v1/management/webhooks",
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([
'url' => '<string>',
'events' => [
],
'description' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"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.tokenlab.sh/v1/management/webhooks"
payload := strings.NewReader("{\n \"url\": \"<string>\",\n \"events\": [],\n \"description\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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.tokenlab.sh/v1/management/webhooks")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"url\": \"<string>\",\n \"events\": [],\n \"description\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.tokenlab.sh/v1/management/webhooks")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"url\": \"<string>\",\n \"events\": [],\n \"description\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"object": "webhook_endpoint",
"url": "<string>",
"events": [
"task.completed"
],
"is_active": true,
"description": "<string>",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"last_delivered_at": "2023-11-07T05:31:56Z",
"failure_count": 123,
"secret": "<string>"
}{
"error": {
"message": "model: Model is required",
"type": "invalid_request_error",
"param": "model"
},
"validation_errors": [
{
"field": "model",
"message": "Model is required"
}
]
}{
"error": {
"message": "Invalid API key provided",
"type": "invalid_api_key"
}
}{
"error": {
"message": "Organization is not active",
"type": "invalid_request_error"
}
}{
"error": {
"message": "<string>",
"type": "unauthorized",
"code": "<string>",
"param": "<string>",
"model": "<string>",
"did_you_mean": "<string>",
"suggestions": [
{
"id": "<string>"
}
],
"alternatives": [
{
"id": "<string>",
"status": "<string>",
"tags": [
"<string>"
]
}
],
"hint": "<string>",
"retry_after": 123,
"retryable": true,
"balance_usd": 123,
"estimated_cost_usd": 123,
"supported_operations": [
"<string>"
],
"supported_parameters": [
"<string>"
],
"required_selectors": [
"<string>"
],
"optional_selectors": [
"<string>"
],
"allowed_resolutions": [
"<string>"
],
"allowed_durations": [
"<string>"
],
"allowed_aspect_ratios": [
"<string>"
],
"prompt_max_characters": 123,
"recommended_request": {},
"request_endpoint": "<string>",
"request_shape_mode": "<string>",
"status_mode": "<string>",
"request_id": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "unauthorized",
"code": "<string>",
"param": "<string>",
"model": "<string>",
"did_you_mean": "<string>",
"suggestions": [
{
"id": "<string>"
}
],
"alternatives": [
{
"id": "<string>",
"status": "<string>",
"tags": [
"<string>"
]
}
],
"hint": "<string>",
"retry_after": 123,
"retryable": true,
"balance_usd": 123,
"estimated_cost_usd": 123,
"supported_operations": [
"<string>"
],
"supported_parameters": [
"<string>"
],
"required_selectors": [
"<string>"
],
"optional_selectors": [
"<string>"
],
"allowed_resolutions": [
"<string>"
],
"allowed_durations": [
"<string>"
],
"allowed_aspect_ratios": [
"<string>"
],
"prompt_max_characters": 123,
"recommended_request": {},
"request_endpoint": "<string>",
"request_shape_mode": "<string>",
"status_mode": "<string>",
"request_id": "<string>"
}
}使用工作区管理令牌
mt-…,不是模型调用 Key sk-…,也不是签名密钥 whsec_…。在 Dashboard → API → Management Tokens 创建,以 Authorization: Bearer mt-… 发送。只能操作该工作区。
接入、事件、验签与失败处理见 Webhook 管理 API 文档。授权
管理令牌身份验证。在 Dashboard > API > Management Tokens 中创建或管理管理令牌。
请求体
application/json
响应
创建 Webhook 端点结果
可用选项:
webhook_endpoint 可用选项:
task.completed, task.failed, task.timeout