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

# Files and report artifacts

> Where screenshots, traces and other files live, who can open their links, and how scripts download them

Empirical keeps two kinds of files for a project:

* **Project files**: screenshots, videos, documents and HTML pages that you or Empirical's agents
  upload. Each one has a handle like `file@6526` and a link on `empirical.run/files/`.
* **Report artifacts**: what a test run produces, such as the Playwright report (`summary.json`),
  `trace.zip`, screenshots and videos. Their links are on report hosts: `reports-us.empirical.run`,
  `reports-in.empirical.run` and `reports-r2.empirical.run`.

Both kinds of link open only for people and API keys with access to the project.

## Who can open a link

| Request | Result |
| - | - |
| Browser signed in to Empirical, member of the project | The file opens |
| Browser signed in, not a member of the project | `403` for a project file, `401` for a report artifact |
| Browser not signed in, project file link | The Empirical sign-in page, then the file |
| Browser not signed in, report link | `401` "Sign in to view this file". Sign in at `empirical.run` and open the link again |
| `Authorization: Bearer <project API key>` | The file, when the key belongs to the file's project. `403` for another project |
| No credentials: `curl`, an image embedded in GitHub or Google Docs, a link preview | `401` |
| Project file link with a valid `share` token | The file, for anyone, until the link expires |

Empirical's agents read file and report links with their session's credentials. Pass links to a
session as they are.

## Download files from a script

To download files in CI or a script, send a project API key as a Bearer token. Create a key under
[Settings → API keys](https://empirical.run/settings/api-keys). A key reads only its own project's
files and report artifacts.

Get a run's report link from the API, then download it with the same key:

```sh theme={null}
REPORT_URL=$(curl -s "https://api.empirical.run/api/test-runs/<TEST_RUN_ID>" \
  -H "Authorization: Bearer $EMPIRICALRUN_KEY" \
  | jq -r '.data.test_run.testRun.summary_url')

curl -sf -H "Authorization: Bearer $EMPIRICALRUN_KEY" "$REPORT_URL" -o summary.json
```

Attachment paths in `summary.json` (traces, screenshots, videos) are full links, so download them
with the same header. Range requests work too, for tools that read part of a `trace.zip`.
[Code coverage](https://empirical.run/docs/features/code-coverage.md) downloads every coverage attachment of a run this way.

## Download files with the CLI

After `empirical login`, the CLI sends your sign-in. It takes a handle, a file link or a report link:

```sh theme={null}
empirical files download file@6526
empirical files download "https://reports-us.empirical.run/<path>/trace.zip" -o trace.zip
```

Add `-o -` to write to stdout. Run `empirical files download --help` for every option.

## Upload a project file

With the CLI, `empirical files upload <path>` uploads a file and prints its link. Add `--json` to
print the whole file record, including its ID.

With the API, an upload takes three requests:

1. Create the file with `POST /api/files`, sending `name`, `mime_type` and `size_bytes`. The
   response has the file record and an `upload_url` that is valid for 1 hour.
2. `PUT` the file body to `upload_url`, with a `Content-Type` header equal to `mime_type`.
3. Confirm the upload with `PATCH /api/files/{id}` and `{"status": "uploaded"}`.

See [Create a file](https://empirical.run/docs/api-reference/files/create-a-file.md) in the API reference.

## Share a file outside Empirical

To embed a file where a sign-in can't be sent, such as an image in a Google Doc, create a share
link. Anyone with the link can open the file for up to 1 hour.

```sh theme={null}
empirical files share file@6526 --expires 30m
```

The API equivalent is `POST /api/files/{id}/share-link` with `expires_in` in seconds, from 60 to
3600\. Share links can't be revoked, so create one only for a link you send or embed outside
Empirical.

Share links work for project files only. To share a report screenshot, download it and upload it
as a project file:

```sh theme={null}
empirical files download "<report screenshot link>" -o shot.png
empirical files upload shot.png --share
```

## Troubleshooting

| Response | Cause | Fix |
| - | - | - |
| `401` | No credentials, an expired or invalid API key, or an expired share link | Sign in, send `Authorization: Bearer <project API key>`, or create a new share link |
| `403` | The credentials don't have access to the file's project | Use a key from the file's project, or ask a project admin to add you |
| `404` | The file doesn't exist, or the link has no project path (for example `/favicon.ico` on a report host) | Check the link |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.