> ## 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.

> 上传文件供 Devin 在会话期间使用。支持多种文件类型，包括代码、数据和文档文件。

# 上传附件

此端点会将文件上传到我们的服务器，并返回一个可在 Devin 会话中引用的 URL。文件不会自动添加到任何会话中——你需要在提示中包含该 URL。

<div id="how-to-use-uploaded-files">
  ## 如何使用已上传的文件
</div>

<Warning>
  Devin 只有在附件被严格写成 `ATTACHMENT:"{file_url}"` 这一精确格式时才会识别（单数 `ATTACHMENT`，全部大写）。`ATTACHMENT:` 必须单独占据提示词中的一行，并且 URL 必须用双引号包裹。

  仅仅直接包含原始 URL 而不采用该格式将无法生效。像 `ATTACHMENTS:`（复数）这样的变体同样不会被识别。
</Warning>

在 Devin 会话中引用已上传的文件：

1. **上传文件**，使用此 endpoint 获取一个 URL
2. **在提示词中包含该 URL**，在创建会话或发送消息时使用
3. **正确书写该 URL 的格式**，在提示词中单独一行写上 `ATTACHMENT:"{file_url}"`

<div id="complete-example">
  ## 完整示例
</div>

```python theme={null}
import os
import requests

DEVIN_API_KEY = os.getenv("DEVIN_API_KEY")

# 步骤 1：上传文件
with open("data.csv", "rb") as f:
    response = requests.post(
        "https://api.devin.ai/v1/attachments",
        headers={"Authorization": f"Bearer {DEVIN_API_KEY}"},
        files={"file": f}
    )
file_url = response.text

# 步骤 2：创建引用已上传文件的会话
session_response = requests.post(
    "https://api.devin.ai/v1/sessions",
    headers={"Authorization": f"Bearer {DEVIN_API_KEY}"},
    json={
        "prompt": f"""请分析附件中的 CSV 文件数据并生成摘要报告。
重点关注趋势和关键洞察。

ATTACHMENT:"{file_url}"
"""
    }
)

print(session_response.json())
```

**重要提示：** `ATTACHMENT:` 前缀必须在提示中单独占一行，且 URL 必须用双引号括起来，格式须与上方示例完全一致：`ATTACHMENT:"{url}"`。如需附加多个文件，请为每个文件各添加一行 `ATTACHMENT:"{file_url}"`。


## OpenAPI

````yaml zh/v1-openapi.yaml POST /v1/attachments
openapi: 3.1.0
info:
  description: Devin v1 API：个人 API key 与服务 API key
  title: Devin API v1
  version: 1.0.0
servers: []
security:
  - bearerAuth: []
paths:
  /v1/attachments:
    post:
      summary: 上传附件
      description: 上传一个可在 Devin 会话中使用的附件文件，并以字符串形式返回已上传附件的 URL。
      operationId: upload_attachment_customer_endpoint_v1_attachments_post
      requestBody:
        content:
          multipart/form-data:
            schema:
              $ref: >-
                #/components/schemas/Body_upload_attachment_customer_endpoint_v1_attachments_post
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                title: >-
                  Response Upload Attachment Customer Endpoint V1 Attachments
                  Post
                type: string
          description: 成功响应
        '422':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
          description: 验证错误
components:
  schemas:
    Body_upload_attachment_customer_endpoint_v1_attachments_post:
      properties:
        file:
          format: binary
          title: File
          type: string
      required:
        - file
      title: Body_upload_attachment_customer_endpoint_v1_attachments_post
      type: object
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          title: Detail
          type: array
      title: HTTPValidationError
      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: 个人 API Key（apk_user_\*）或服务 API Key（apk_\*）
      scheme: bearer
      type: http

````