> ## Documentation Index
> Fetch the complete documentation index at: https://www.mintlify.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# 创建代理任务 (v1)

> 已废弃：请改用 [v2 create agent job](/api/agent/v2/create-agent-job)。此操作会创建一个新的代理任务，该任务可根据提供的消息和 Git branch 信息生成并编辑文档。

<Warning>此端点已废弃。请改用 [v2 创建代理任务](/zh/api/agent/v2/create-agent-job) 端点。</Warning>

此端点会根据提供的消息和分支信息创建一个代理任务。该任务异步执行，并以流式方式返回包含执行详情与结果的响应。

如果分支不存在，代理会自动创建该分支。若代理成功编辑了文件，任务结束时会自动创建一个拉取请求。

<div id="rate-limits">
  ## 速率限制
</div>

代理 API 的限制如下：

* 每个 Mintlify 项目每小时最多可调用 100 次

<div id="suggested-usage">
  ## 建议用法
</div>

为获得最佳效果，请使用 [ai-sdk 的 useChat 钩子](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat#usechat) 来发送请求并处理响应。


## OpenAPI

````yaml zh/admin-openapi.json POST /v1/agent/{projectId}/job
openapi: 3.0.1
info:
  title: Mintlify Admin API
  description: 用于管理操作的 API，包括文档更新和代理管理。
  version: 2.0.0
servers:
  - url: https://api.mintlify.com
security:
  - bearerAuth: []
paths:
  /v1/agent/{projectId}/job:
    post:
      summary: 创建代理任务（v1）
      description: >-
        已废弃：请改用 [v2 create agent
        job](/api/agent/v2/create-agent-job)。此操作会创建一个新的代理任务，该任务可根据提供的消息和 Git
        branch 信息生成并编辑文档。
      parameters:
        - name: projectId
          in: path
          required: true
          schema:
            type: string
          description: >-
            你的项目 ID。可从你的控制台中的 [API
            keys](https://dashboard.mintlify.com/settings/organization/api-keys)
            页面复制。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - messages
              properties:
                branch:
                  type: string
                  description: 代理应处理的 Git branch 名称。如省略，代理会根据消息内容生成一个 branch 名称。
                messages:
                  type: array
                  description: 提供给代理的消息列表。系统始终会自动在前面添加一条默认的系统提示，因此通常只需包含用户消息。
                  items:
                    type: object
                    required:
                      - role
                      - content
                    properties:
                      role:
                        type: string
                        enum:
                          - system
                          - user
                          - assistant
                        description: >-
                          消息发送者的角色。对于任务说明，请使用 `user`。使用 `system`
                          添加补充说明，这些说明会附加在默认系统提示之后（不会替换默认系统提示）。使用 `assistant`
                          提供用于少样本提示的 AI 助手示例回复。
                      content:
                        type: string
                        description: 消息的 content。
                asDraft:
                  type: boolean
                  default: false
                  description: >-
                    控制拉取请求（PR；亦称“合并请求”/Merge Request）是以草稿模式还是非草稿模式创建。为 true
                    时，会创建草稿拉取请求（PR；亦称“合并请求”/Merge Request）。为 false
                    时（默认），会创建可供评审的常规拉取请求（PR；亦称“合并请求”/Merge Request）。
                model:
                  type: string
                  enum:
                    - sonnet
                    - opus
                  default: sonnet
                  description: >-
                    用于代理任务的 AI 模型。使用 `sonnet` 可获得更快、更具成本效益的处理。使用 `opus`
                    可获得能力更强但速度较慢的处理。
      responses:
        '200':
          description: 代理任务创建成功。返回 Server-Sent Events 流式响应。
          headers:
            X-Session-Id:
              schema:
                type: string
              description: 已创建的代理任务的唯一会话标识符。
            X-Branch-Name:
              schema:
                type: string
              description: 代理正在进行更改的 Git 分支名称。
          content:
            text/event-stream:
              schema:
                type: string
                description: 包含代理任务执行详情和结果的 Server-Sent Events 流。
      deprecated: true
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Authorization 头部需要 Bearer 令牌。请使用以 `mint_` 为前缀的管理员 API
        密钥。这是服务端使用的机密凭证。你可以在控制台的 [API keys
        页面](https://dashboard.mintlify.com/settings/organization/api-keys)
        中生成一个。

````

## Related topics

- [简介](/docs/zh/api/introduction.md)
- [自动化概览](/docs/zh/automations/index.md)
- [Visibility](/docs/zh/components/visibility.md)
