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

# Read Attachment

> Download the bytes of a file attached to an inbound or outbound message.

Every file attached to a message — one your agent sent, or one that arrived
in an inbound email — is stored and addressable by its `att_...` id. Message
detail (`GET /v1/messages/{id}`) and thread responses include an `attachments`
array with each file's `id`, `filename`, `contentType`, and `sizeBytes`.

Use this endpoint to read the actual file: parse a received CSV, archive a
signed PDF, or inspect a document your agent was sent.

### Path parameters

<ParamField path="id" type="string" required>
  The attachment ID (`att_...`) from a message's `attachments` array.
</ParamField>

### Query parameters

<ParamField query="inline" type="boolean" default="false">
  Set `inline=1` to render in a browser tab instead of downloading. Only
  honoured for types that are safe to render (`image/png`, `image/jpeg`,
  `image/gif`, `image/webp`, `application/pdf`, `text/plain`); every other
  type is always served as a download so hostile HTML/SVG can never run on
  your origin.
</ParamField>

### Response

The raw file bytes with `Content-Type`, `Content-Length`, and
`Content-Disposition` headers. Tenancy is enforced: an attachment belonging to
another organization returns `404`, and an inbox-scoped key can only read files
on messages in its own inbox (`403 inbox_access_denied` otherwise).

If the record exists but the stored file was already removed by the plan's
retention policy, the API returns `410 attachment_bytes_missing`.

<RequestExample>
  ```bash cURL theme={null}
  # Download to a file
  curl -H "Authorization: Bearer gork_live_YOUR_API_KEY" \
    https://api.gork.email/v1/attachments/att_9c1f2ab7d3 \
    --output report.pdf
  ```

  ```typescript TypeScript theme={null}
  import { GorkClient } from "@gork/sdk"

  const client = new GorkClient({ apiKey: process.env.GORK_API_KEY })

  // Metadata comes from the message
  const message = await client.messages.get("msg_90e38dfb4a2c")
  const [file] = message.attachments ?? []

  if (file) {
    // Bytes
    const bytes = await client.attachments.download(file.id)

    // Or decode a text-like file (txt / csv / json) straight to a string
    const text = await client.attachments.downloadText(file.id)
    console.log(text)
  }
  ```

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

  res = requests.get(
      "https://api.gork.email/v1/attachments/att_9c1f2ab7d3",
      headers={"Authorization": f"Bearer {os.getenv('GORK_API_KEY')}"},
  )
  res.raise_for_status()
  open("report.pdf", "wb").write(res.content)
  ```
</RequestExample>

<ResponseExample>
  ```http 200 OK theme={null}
  Content-Type: application/pdf
  Content-Length: 48213
  Content-Disposition: attachment; filename="report.pdf"; filename*=UTF-8''report.pdf
  X-Content-Type-Options: nosniff

  <binary file bytes>
  ```
</ResponseExample>

## Reading attachments from an agent (MCP)

Claude Code, Cursor, and other MCP clients get this through the
`gork_read_attachment` tool: text files are returned decoded, binary files come
back base64-encoded (files over 2MB return metadata only, with a pointer to the
endpoint). See [Connect your AI](/connect) for the setup.
