跳转到主要内容
POST
/
agent
/
{projectId}
/
job
创建代理作业
curl --request POST \
  --url https://api.mintlify.com/v1/agent/{projectId}/job \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "branch": "<string>",
  "messages": [
    {
      "content": "<string>"
    }
  ],
  "asDraft": true,
  "model": "sonnet"
}
'
import requests

url = "https://api.mintlify.com/v1/agent/{projectId}/job"

payload = {
"branch": "<string>",
"messages": [{ "content": "<string>" }],
"asDraft": True,
"model": "sonnet"
}
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({
branch: '<string>',
messages: [{content: '<string>'}],
asDraft: true,
model: 'sonnet'
})
};

fetch('https://api.mintlify.com/v1/agent/{projectId}/job', 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.mintlify.com/v1/agent/{projectId}/job",
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([
'branch' => '<string>',
'messages' => [
[
'content' => '<string>'
]
],
'asDraft' => true,
'model' => 'sonnet'
]),
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.mintlify.com/v1/agent/{projectId}/job"

payload := strings.NewReader("{\n \"branch\": \"<string>\",\n \"messages\": [\n {\n \"content\": \"<string>\"\n }\n ],\n \"asDraft\": true,\n \"model\": \"sonnet\"\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.mintlify.com/v1/agent/{projectId}/job")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"branch\": \"<string>\",\n \"messages\": [\n {\n \"content\": \"<string>\"\n }\n ],\n \"asDraft\": true,\n \"model\": \"sonnet\"\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.mintlify.com/v1/agent/{projectId}/job")

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 \"branch\": \"<string>\",\n \"messages\": [\n {\n \"content\": \"<string>\"\n }\n ],\n \"asDraft\": true,\n \"model\": \"sonnet\"\n}"

response = http.request(request)
puts response.read_body
"<string>"
此端点会根据提供的消息和 branch 信息创建一个代理任务。该任务异步执行,并以流式方式返回包含执行详情与结果的响应。 如果 branch 不存在,代理会自动创建该 branch。若文件编辑成功,任务结束时会自动创建一个拉取请求(PR;亦称“合并请求”/Merge Request)。

速率限制

代理 API 的限制如下:
  • 每个 Mintlify 项目每小时最多可调用 100 次

建议用法

为获得最佳效果,请使用 ai-sdk 的 useChat 钩子 来发送请求并处理响应。

授权

Authorization
string
header
必填

Authorization 请求头需要使用 Bearer token。请在此处创建一个 Admin API Key(管理员 API 密钥)

路径参数

projectId
string
必填

你的项目 ID。可在控制台的 API keys 页面中复制。

请求体

application/json
branch
string
必填

代理应处理的 Git branch 名称,若该 branch 不存在,将会自动创建

messages
object[]
必填

要提供给代理的消息列表。系统会始终在最前面自动添加一个默认的系统提示词,因此通常只需要包含用户消息即可。

asDraft
boolean
默认值:true

控制是否以草稿模式或非草稿模式创建拉取请求(PR;亦称“合并请求”/Merge Request)。为 true 时,将创建草稿拉取请求;为 false 时,将创建常规(非草稿)拉取请求,供审核使用。

model
enum<string>
默认值:sonnet

用于该智能体任务的 AI 模型。使用 sonnet 可获得更快捷、成本更低的处理。使用 opus 可获得更强大但速度更慢的处理。

可用选项:
sonnet,
opus

响应

200 - text/plain

代理任务已成功创建(流式响应)。X-Session-Id 头会随响应一同返回

包含代理任务执行详情和结果的流式响应。