# Get an upload URL for each file of a session's input.

`POST /o/{org}/files`

Name each file and its type, then `PUT` its bytes to the `upload_url` that comes back,
straight to storage and in parallel if you like, with the same `Content-Type` as its
`mime_type`. There is no size field and no size limit here: one `PUT` takes a file up to
5 GB. An `upload_url` is good for an hour. Pass each id as a
`{"type": "file", "source": {"type": "file", "file_id": id}}` block in a session's or a
follow-up's `input`. When the session starts, each file's bytes are checked against its
type and its size is read from storage; a file never uploaded is refused there with
`409 ATTACHMENT_NOT_UPLOADED`. At most 50 files per call. Rate-limited to 30 calls a minute
per caller.

## Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `org` | path | string | yes | The org's slug or id. A caller with no role in the org gets `404`. |

## Request body

- `files` (array of object, required)
  - `name` (string, required): The file name in the sandbox. No `/`, `\`, `..`, leading `.`, or control characters.
  - `mime_type` (string, required): The file's media type. Send it as the `Content-Type` of the `PUT`.

## Example: example

```bash
curl -X POST "https://api.phoenix.so/o/$RUSH_ORG/files" \
  -H "Authorization: Bearer $RUSH_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "files": [
      {
        "name": "demo.mp4",
        "mime_type": "video/mp4"
      },
      {
        "name": "spec.pdf",
        "mime_type": "application/pdf"
      }
    ]
  }'
```

```typescript
const org = process.env.RUSH_ORG;

const res = await fetch(`https://api.phoenix.so/o/${org}/files`, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.RUSH_TOKEN}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    files: [
      {
        name: "demo.mp4",
        mime_type: "video/mp4",
      },
      {
        name: "spec.pdf",
        mime_type: "application/pdf",
      },
    ],
  }),
});

console.log(res.status, await res.json());
```

```python
import os

import requests

org = os.environ["RUSH_ORG"]

res = requests.post(
    f"https://api.phoenix.so/o/{org}/files",
    headers={"Authorization": f"Bearer {os.environ['RUSH_TOKEN']}"},
    json={
        "files": [
            {
                "name": "demo.mp4",
                "mime_type": "video/mp4",
            },
            {
                "name": "spec.pdf",
                "mime_type": "application/pdf",
            },
        ],
    },
)

print(res.status_code, res.json())
```

## Responses

### 201

An upload URL per file, in the order asked for.

- `files` (array of object, required)
  - `id` (string, required)
  - `name` (string, required)
  - `mime_type` (string, required)
  - `upload_url` (string, required): A signed URL to `PUT` the file to, with `Content-Type: <mime_type>`.
  - `upload_expires_at` (string, required)

### 400

Not the JSON shape above, a `multipart/form-data` body or a `size` field (`INVALID_BODY`, naming the shape), an invalid name or type, or more than 50 files (`TOO_MANY_FILES`).

### 401

No bearer, an unknown, revoked or expired one, or an API key on a route keys cannot call.

### 404

No such resource for the caller, including one in an org the caller is not in or a Project that is private to someone else.

### 429

Upload rate limit exceeded, or the account is over its 1,800-a-minute request budget. `Retry-After` is set.

## Example response (201)

```json
{
  "files": [
    {
      "id": "3f0c8b2e-5d14-4a7f-9b63-1e2d7c9a0f48",
      "name": "demo.mp4",
      "mime_type": "video/mp4",
      "upload_url": "https://uploads.example.com/attachments/3f0c8b2e…?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Expires=3600&X-Amz-Signature=5e0a…",
      "upload_expires_at": "2026-10-06T16:01:47.312Z"
    },
    {
      "id": "7a91d4c6-0e2b-4f85-a3d7-6b1c9e5f2a03",
      "name": "spec.pdf",
      "mime_type": "application/pdf",
      "upload_url": "https://uploads.example.com/attachments/7a91d4c6…?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Expires=3600&X-Amz-Signature=c38d…",
      "upload_expires_at": "2026-10-06T16:01:47.312Z"
    }
  ]
}
```
