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

# Files

> Upload, list, fetch, and delete files scoped to your workspace.

The files endpoints store documents for reuse across chat requests. Files are scoped to the workspace that uploaded them; another workspace's file id returns `404`.

| Method | Path                     | Purpose                       |
| ------ | ------------------------ | ----------------------------- |
| POST   | `/v1/files`              | Upload, `multipart/form-data` |
| GET    | `/v1/files`              | List the workspace's files    |
| GET    | `/v1/files/{id}`         | File metadata                 |
| GET    | `/v1/files/{id}/content` | Download the bytes            |
| DELETE | `/v1/files/{id}`         | Delete                        |

## Upload

<CodeGroup>
  ```bash curl theme={null}
  curl --fail-with-body https://api.pre.dev/v1/files \
    -H "Authorization: Bearer $PREDEV_API_KEY" \
    -F "purpose=user_data" \
    -F "file=@contract.pdf"
  ```

  ```typescript Node.js theme={null}
  import fs from 'node:fs';
  import OpenAI from 'openai';

  const client = new OpenAI({ baseURL: 'https://api.pre.dev/v1', apiKey: process.env.PREDEV_API_KEY! });

  const file = await client.files.create({
    file: fs.createReadStream('contract.pdf'),
    purpose: 'user_data',
  });
  console.log(file.id);
  ```

  ```python Python theme={null}
  import os
  from openai import OpenAI

  client = OpenAI(base_url="https://api.pre.dev/v1", api_key=os.environ["PREDEV_API_KEY"])

  with open("contract.pdf", "rb") as handle:
      uploaded = client.files.create(file=handle, purpose="user_data")
  print(uploaded.id)
  ```
</CodeGroup>

The upload takes the bytes in a `file` part and a `purpose` string (`user_data` for documents you will reference from chat messages) and returns the stored file object, including the `id` used in later requests.

## List, fetch, download, delete

```bash theme={null}
curl --fail-with-body https://api.pre.dev/v1/files \
  -H "Authorization: Bearer $PREDEV_API_KEY"

curl --fail-with-body "https://api.pre.dev/v1/files/$FILE_ID" \
  -H "Authorization: Bearer $PREDEV_API_KEY"

curl --fail-with-body "https://api.pre.dev/v1/files/$FILE_ID/content" \
  -H "Authorization: Bearer $PREDEV_API_KEY" -o contract.pdf

curl --fail-with-body -X DELETE "https://api.pre.dev/v1/files/$FILE_ID" \
  -H "Authorization: Bearer $PREDEV_API_KEY"
```

In the SDKs these are `client.files.list()`, `client.files.retrieve(id)`, `client.files.content(id)`, and `client.files.delete(id)` (Node `client.files.del(id)` on older versions).

## Use a file in a request

Reference the uploaded file from a chat message as a `file` content part, and add the `file-parser` plugin so models without native document input can read it. See [multimodal](/ai-gateway/multimodal).
