cURL
curl -N --request POST \
--url 'https://{api_base_url}/workflows/run' \
--header 'Authorization: Bearer {api_key}' \
--header 'Content-Type: application/json' \
--data '{"inputs": {"query": "Summarize this text: The quick brown fox jumps over the lazy dog."}, "response_mode": "streaming", "user": "{user}"}'import requests
url = "https://{api_base_url}/workflows/run"
payload = {
"inputs": { "query": "Summarize this text: The quick brown fox jumps over the lazy dog." },
"response_mode": "streaming",
"user": "user_workflow_123"
}
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({
inputs: {query: 'Summarize this text: The quick brown fox jumps over the lazy dog.'},
response_mode: 'streaming',
user: 'user_workflow_123'
})
};
fetch('https://{api_base_url}/workflows/run', 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_base_url}/workflows/run",
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([
'inputs' => [
'query' => 'Summarize this text: The quick brown fox jumps over the lazy dog.'
],
'response_mode' => 'streaming',
'user' => 'user_workflow_123'
]),
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_base_url}/workflows/run"
payload := strings.NewReader("{\n \"inputs\": {\n \"query\": \"Summarize this text: The quick brown fox jumps over the lazy dog.\"\n },\n \"response_mode\": \"streaming\",\n \"user\": \"user_workflow_123\"\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_base_url}/workflows/run")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"inputs\": {\n \"query\": \"Summarize this text: The quick brown fox jumps over the lazy dog.\"\n },\n \"response_mode\": \"streaming\",\n \"user\": \"user_workflow_123\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{api_base_url}/workflows/run")
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 \"inputs\": {\n \"query\": \"Summarize this text: The quick brown fox jumps over the lazy dog.\"\n },\n \"response_mode\": \"streaming\",\n \"user\": \"user_workflow_123\"\n}"
response = http.request(request)
puts response.read_body{
"task_id": "c3800678-a077-43df-a102-53f23ed20b88",
"workflow_run_id": "fb47b2e6-5e43-4f90-be01-d5c5a088d156",
"data": {
"id": "fb47b2e6-5e43-4f90-be01-d5c5a088d156",
"workflow_id": "7c3e33d4-2a8b-4e5f-9b1a-d3c6e8f12345",
"status": "succeeded",
"outputs": {
"result": "Bonjour le monde"
},
"error": null,
"elapsed_time": 1.23,
"total_tokens": 150,
"total_steps": 3,
"created_at": 1705407629,
"finished_at": 1705407630
}
}工作流运行
执行工作流
适用于:Workflow。
运行应用已发布的工作流并返回其输出,可以是单次 blocking 响应,也可以是 streaming 的 Server-Sent Events 流。需要已发布的工作流。
POST
/
workflows
/
run
cURL
curl -N --request POST \
--url 'https://{api_base_url}/workflows/run' \
--header 'Authorization: Bearer {api_key}' \
--header 'Content-Type: application/json' \
--data '{"inputs": {"query": "Summarize this text: The quick brown fox jumps over the lazy dog."}, "response_mode": "streaming", "user": "{user}"}'import requests
url = "https://{api_base_url}/workflows/run"
payload = {
"inputs": { "query": "Summarize this text: The quick brown fox jumps over the lazy dog." },
"response_mode": "streaming",
"user": "user_workflow_123"
}
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({
inputs: {query: 'Summarize this text: The quick brown fox jumps over the lazy dog.'},
response_mode: 'streaming',
user: 'user_workflow_123'
})
};
fetch('https://{api_base_url}/workflows/run', 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_base_url}/workflows/run",
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([
'inputs' => [
'query' => 'Summarize this text: The quick brown fox jumps over the lazy dog.'
],
'response_mode' => 'streaming',
'user' => 'user_workflow_123'
]),
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_base_url}/workflows/run"
payload := strings.NewReader("{\n \"inputs\": {\n \"query\": \"Summarize this text: The quick brown fox jumps over the lazy dog.\"\n },\n \"response_mode\": \"streaming\",\n \"user\": \"user_workflow_123\"\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_base_url}/workflows/run")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"inputs\": {\n \"query\": \"Summarize this text: The quick brown fox jumps over the lazy dog.\"\n },\n \"response_mode\": \"streaming\",\n \"user\": \"user_workflow_123\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{api_base_url}/workflows/run")
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 \"inputs\": {\n \"query\": \"Summarize this text: The quick brown fox jumps over the lazy dog.\"\n },\n \"response_mode\": \"streaming\",\n \"user\": \"user_workflow_123\"\n}"
response = http.request(request)
puts response.read_body{
"task_id": "c3800678-a077-43df-a102-53f23ed20b88",
"workflow_run_id": "fb47b2e6-5e43-4f90-be01-d5c5a088d156",
"data": {
"id": "fb47b2e6-5e43-4f90-be01-d5c5a088d156",
"workflow_id": "7c3e33d4-2a8b-4e5f-9b1a-d3c6e8f12345",
"status": "succeeded",
"outputs": {
"result": "Bonjour le monde"
},
"error": null,
"elapsed_time": 1.23,
"total_tokens": 150,
"total_steps": 3,
"created_at": 1705407629,
"finished_at": 1705407630
}
}授权
请求体
application/json
响应模式。使用 blocking 获取同步响应(Cloudflare 超时时间为 100 s),使用 streaming 获取服务器发送事件。未指定时默认为阻塞模式。
可用选项:
streaming, blocking 响应
请求成功。内容类型和结构取决于请求中的 response_mode 参数。
- 如果
response_mode为blocking,返回application/json和WorkflowBlockingResponse对象。 - 如果
response_mode为streaming,返回text/event-stream和ChunkWorkflowEvent对象流。
⌘I