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

# 创建会话

> 创建新会话

<div id="permissions">
  ## 权限
</div>

需要在组织级别具备 `ManageOrgSessions` 权限的服务用户账号。

<div id="additional-permissions-for-advanced-features">
  ### 高级功能的额外权限
</div>

| 功能                  | 所需权限                     |
| ------------------- | ------------------------ |
| `create_as_user_id` | `ImpersonateOrgSessions` |

<div id="devin-mode">
  ## Devin 模式
</div>

`devin_mode` 参数用于控制会话使用哪种 Devin Agent 模式：

| 模式       | 说明                         |
| -------- | -------------------------- |
| `normal` | 默认 Agent 模式。速度快，并且擅长长周期规划。 |
| `fast`   | 速度约快 2 倍，价格贵 4 倍，智能水平相同。   |

如果省略此参数，会话将使用组织的默认模式。快速模式与 Web 应用一样，受相同的功能开关和企业版 Agent 预览限制约束。

<div id="user-impersonation">
  ## 用户模拟
</div>

`create_as_user_id` 参数允许代表其他用户创建会话。前提条件如下：

1. 服务用户必须具有 `ImpersonateOrgSessions` 权限
2. 目标用户必须是该组织的成员
3. 目标用户必须具有 `UseDevinSessions` 权限


## OpenAPI

````yaml zh/v3-openapi.yaml POST /v3/organizations/{org_id}/sessions
openapi: 3.1.0
info:
  description: 采用 Service User 身份验证和 RBAC 的 Devin v3 API
  title: Devin API v3
  version: 3.0.0
servers: []
security:
  - bearerAuth: []
paths:
  /v3/organizations/{org_id}/sessions:
    post:
      tags:
        - sessions
      summary: 创建会话
      description: 创建新会话
      operationId: handle_create_session_v3_organizations__org_id__sessions_post
      parameters:
        - description: 组织 ID（前缀：org-）
          in: path
          name: org_id
          required: true
          schema:
            anyOf:
              - type: string
              - type: 'null'
            example: org-abc123def456
            title: Org Id
        - in: query
          name: devin_id
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: Devin Id
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SessionCreateRequest'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SessionResponse'
          description: 成功响应
        '422':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
          description: 验证错误
components:
  schemas:
    SessionCreateRequest:
      properties:
        attachment_urls:
          anyOf:
            - items:
                format: uri
                maxLength: 2083
                minLength: 1
                type: string
              type: array
            - type: 'null'
          title: Attachment Urls
        bypass_approval:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Bypass Approval
        child_playbook_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Child Playbook Id
        create_as_user_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Create As User Id
        devin_mode:
          anyOf:
            - enum:
                - normal
                - fast
                - lite
                - ultra
              type: string
            - type: 'null'
          description: >-
            覆盖该会话的 Devin Agent mode。'normal' 使用默认 Agent mode，'fast' 使用 Fast
            mode，'lite' 使用 Devin Lite，'ultra' 使用 Devin Ultra。Fast、Lite 和 Ultra 与
            web app 一样，受相同的功能标记和 Enterprise Agent 预览限制。
          title: Devin Mode
        knowledge_ids:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Knowledge Ids
        max_acu_limit:
          anyOf:
            - type: integer
            - type: 'null'
          title: Max Acu Limit
        platform:
          anyOf:
            - type: string
            - type: 'null'
          description: >-
            覆盖会话的 VM 平台（例如“windows”）。如果省略（或设为“inherit”），由父级 Devin
            创建的会话会继承父级的平台；否则使用组织默认平台。该值必须与你的组织已配置的平台之一匹配（不区分大小写）；如果值无法识别，则会返回
            400，且错误响应体中会列出该组织可用的平台标签。
          title: Platform
        playbook_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Playbook Id
        prompt:
          title: Prompt
          type: string
        repos:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Repos
        resumable:
          default: true
          description: 是否在会话停止后保留其虚拟机状态，以便后续恢复会话。对于一次性会话，请将其设为 false。
          title: Resumable
          type: boolean
        secret_ids:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Secret Ids
        session_links:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Session Links
        session_secrets:
          anyOf:
            - items:
                $ref: '#/components/schemas/SessionSecretInput'
              type: array
            - type: 'null'
          title: Session Secrets
        structured_output_required:
          anyOf:
            - type: boolean
            - type: 'null'
          description: >-
            为 true 时（默认），Agent 必须在当前轮次结束前调用 provide_structured_output，且
            is_final=true。为 false 时，该工具可用但非必需——不保证会在某一轮次中被调用。
          title: Structured Output Required
        structured_output_schema:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          description: 用于验证结构化输出的 JSON Schema（Draft 7），最大 64KB。必须是自包含的（不允许外部 $ref）。
          title: Structured Output Schema
        tags:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Tags
        title:
          anyOf:
            - type: string
            - type: 'null'
          title: Title
      required:
        - prompt
      title: SessionCreateRequest
      type: object
    SessionResponse:
      properties:
        acus_consumed:
          title: Acus Consumed
          type: number
        category:
          anyOf:
            - enum:
                - bug_fixing
                - ci_cd_and_devops
                - code_quality_and_security
                - code_review
                - code_review_and_analysis
                - data_and_automation
                - documentation_and_content
                - feature_development
                - migrations_and_upgrades
                - other
                - refactoring_and_optimization
                - research_and_exploration
                - security
                - unit_test_generation
              type: string
            - type: 'null'
          description: 如果已完成分类，则为会话分配的用例类别。仅在 get/list 端点中返回。
          title: Category
        child_session_ids:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Child Session Ids
        created_at:
          title: Created At
          type: integer
        is_archived:
          default: false
          title: Is Archived
          type: boolean
        org_id:
          title: Org Id
          type: string
        origin:
          anyOf:
            - enum:
                - webapp
                - slack
                - teams
                - api
                - linear
                - jira
                - automation
                - cli
                - desktop
                - code_scan
                - other
              type: string
            - type: 'null'
          description: 该会话的创建来源。
          title: Origin
        parent_session_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Parent Session Id
        playbook_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Playbook Id
        pull_requests:
          items:
            $ref: '#/components/schemas/SessionPullRequest'
          title: Pull Requests
          type: array
        service_user_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Service User Id
        session_id:
          title: Session Id
          type: string
        status:
          enum:
            - new
            - claimed
            - running
            - exit
            - error
            - suspended
            - resuming
          title: Status
          type: string
        status_detail:
          anyOf:
            - enum:
                - working
                - waiting_for_user
                - waiting_for_approval
                - finished
                - inactivity
                - user_request
                - usage_limit_exceeded
                - out_of_credits
                - out_of_quota
                - no_quota_allocation
                - payment_declined
                - org_usage_limit_exceeded
                - total_session_limit_exceeded
                - error
              type: string
            - type: 'null'
          description: >-
            会话当前状态的附加信息。当 status
            为“running”时：可为“working”（正在处理）、“waiting_for_user”（需要用户输入）、“waiting_for_approval”（在安全模式下等待操作批准）或“finished”（任务已完成）。当
            status
            为“suspended”时：表示挂起原因，例如“inactivity”“user_request”“usage_limit_exceeded”“out_of_credits”“out_of_quota”“no_quota_allocation”“payment_declined”“org_usage_limit_exceeded”“total_session_limit_exceeded”或“error”。仅在
            get/list 端点中返回。
          title: Status Detail
        structured_output:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          description: 来自会话的已验证结构化输出。仅在 GET/LIST 端点中返回。
          title: Structured Output
        subcategory:
          anyOf:
            - type: string
            - type: 'null'
          description: 为会话分配的子类别显示名称。若已设置类别但未分配或未解析出子类别，则为“Other”。仅在 get/list 端点中返回。
          title: Subcategory
        tags:
          items:
            type: string
          title: Tags
          type: array
        title:
          anyOf:
            - type: string
            - type: 'null'
          title: Title
        updated_at:
          title: Updated At
          type: integer
        url:
          title: Url
          type: string
        user_id:
          anyOf:
            - type: string
            - type: 'null'
          title: User Id
      required:
        - session_id
        - url
        - status
        - tags
        - org_id
        - created_at
        - updated_at
        - acus_consumed
        - pull_requests
      title: SessionResponse
      type: object
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          title: Detail
          type: array
      title: HTTPValidationError
      type: object
    SessionSecretInput:
      description: 用于通过 API 提供会话密钥的输入模型。
      properties:
        key:
          maxLength: 256
          minLength: 1
          title: Key
          type: string
        sensitive:
          default: true
          title: Sensitive
          type: boolean
        value:
          maxLength: 65536
          title: Value
          type: string
      required:
        - key
        - value
      title: SessionSecretInput
      type: object
    SessionPullRequest:
      properties:
        pr_state:
          anyOf:
            - type: string
            - type: 'null'
          title: Pr State
        pr_url:
          title: Pr Url
          type: string
      required:
        - pr_url
        - pr_state
      title: SessionPullRequest
      type: object
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          title: Location
          type: array
        msg:
          title: Message
          type: string
        type:
          title: Error Type
          type: string
      required:
        - loc
        - msg
        - type
      title: ValidationError
      type: object
  securitySchemes:
    bearerAuth:
      description: 服务用户凭据（前缀：cog_）
      scheme: bearer
      type: http

````