在交互会话中执行代码
curl --request POST \
--url https://api.firecrawl.dev/v2/interact/{sessionId}/execute \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"code": "<string>",
"language": "node",
"timeout": 150
}
'import requests
url = "https://api.firecrawl.dev/v2/interact/{sessionId}/execute"
payload = {
"code": "<string>",
"language": "node",
"timeout": 150
}
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({code: '<string>', language: 'node', timeout: 150})
};
fetch('https://api.firecrawl.dev/v2/interact/{sessionId}/execute', 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.firecrawl.dev/v2/interact/{sessionId}/execute",
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([
'code' => '<string>',
'language' => 'node',
'timeout' => 150
]),
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.firecrawl.dev/v2/interact/{sessionId}/execute"
payload := strings.NewReader("{\n \"code\": \"<string>\",\n \"language\": \"node\",\n \"timeout\": 150\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.firecrawl.dev/v2/interact/{sessionId}/execute")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"code\": \"<string>\",\n \"language\": \"node\",\n \"timeout\": 150\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.firecrawl.dev/v2/interact/{sessionId}/execute")
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 \"code\": \"<string>\",\n \"language\": \"node\",\n \"timeout\": 150\n}"
response = http.request(request)
puts response.read_body{
"error": "<string>",
"exitCode": 123,
"killed": true,
"result": "<string>",
"stderr": "<string>",
"stdout": "<string>",
"success": true
}{
"error": "Payment required to access this resource."
}交互端点
在会话中执行代码
在独立的 Interact 会话中执行 Playwright 或 agent-browser 代码。
POST
/
interact
/
{sessionId}
/
execute
在交互会话中执行代码
curl --request POST \
--url https://api.firecrawl.dev/v2/interact/{sessionId}/execute \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"code": "<string>",
"language": "node",
"timeout": 150
}
'import requests
url = "https://api.firecrawl.dev/v2/interact/{sessionId}/execute"
payload = {
"code": "<string>",
"language": "node",
"timeout": 150
}
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({code: '<string>', language: 'node', timeout: 150})
};
fetch('https://api.firecrawl.dev/v2/interact/{sessionId}/execute', 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.firecrawl.dev/v2/interact/{sessionId}/execute",
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([
'code' => '<string>',
'language' => 'node',
'timeout' => 150
]),
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.firecrawl.dev/v2/interact/{sessionId}/execute"
payload := strings.NewReader("{\n \"code\": \"<string>\",\n \"language\": \"node\",\n \"timeout\": 150\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.firecrawl.dev/v2/interact/{sessionId}/execute")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"code\": \"<string>\",\n \"language\": \"node\",\n \"timeout\": 150\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.firecrawl.dev/v2/interact/{sessionId}/execute")
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 \"code\": \"<string>\",\n \"language\": \"node\",\n \"timeout\": 150\n}"
response = http.request(request)
puts response.read_body{
"error": "<string>",
"exitCode": 123,
"killed": true,
"result": "<string>",
"stderr": "<string>",
"stdout": "<string>",
"success": true
}{
"error": "Payment required to access this resource."
}请求头
| 请求头字段 | 值 |
|---|---|
Authorization | Bearer <API_KEY> |
Content-Type | application/json |
请求体
| 参数 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
code | string | 是 | - | 要执行的代码(1-100,000 个字符) |
language | string | 否 | "node" | 代码语言:"python"、"node" 或 "bash"(用于 agent-browser CLI 命令) |
timeout | number | 否 | - | 执行超时时间(单位:秒,范围 1-300) |
响应
| 字段 | 类型 | 描述 |
|---|---|---|
success | boolean | 代码是否执行成功 |
stdout | string | 代码执行产生的标准输出 |
result | string | 代码执行产生的标准输出 |
stderr | string | 代码执行产生的标准错误输出 |
exitCode | number | 已执行进程的退出码 |
killed | boolean | 进程是否因超时被终止 |
error | string | 执行失败时的错误信息(仅在失败时存在) |
请求示例
curl -X POST "https://api.firecrawl.dev/v2/interact/550e8400-e29b-41d4-a716-446655440000/execute" \
-H "Authorization: Bearer $FIRECRAWL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"code": "await page.goto(\"https://example.com\")\ntitle = await page.title()\nprint(title)",
"language": "python"
}'
示例响应(成功)
{
"success": true,
"result": "Example Domain"
}
示例响应 (错误情况)
{
"success": true,
"error": "TimeoutError: page.goto: Timeout 30000ms exceeded."
}
你是需要 Firecrawl API 密钥的 AI 代理吗?请参阅 firecrawl.dev/agent-onboarding/SKILL.md 了解自动化接入说明。
授权
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
路径参数
交互会话 ID
请求体
application/json
⌘I

