You may want to save data produced by your tasks. Beam includes Outputs, which allow you to save files or directories that were created when running a task.

Outputs persist forever. You are not billed for file storage, so this should not pose an issue.

If you’d like to persist your data between tasks (meaning you can stop a Beam task, resume it, and your data will still exist), you should use a Volume instead.

Saving files

Outputs can be passed into your function decorators. The outputs argument accepts a list, so you can pass in multiple outputs:

from beam import App, Runtime, Output

app = App(name="my-app", runtime=Runtime())


@app.task_queue(
    outputs=[
        Output(path="results.txt"),
        Output(path="image.png"),
        Output(path="audio.wav"),
    ],
)
def handler():
    ...

Saving multiple files to a directory

You can also save directories as Outputs.

You must manually create the output path in your app code, for example:

from pathlib import Path
Path("generated_images").mkdir(parents=True, exist_ok=True) 
app.py
from beam import App, Runtime, Output

app = App(name="my-app", runtime=Runtime())


@app.task_queue(
    outputs=[Output(path="my-dir")],
)
def handler():
    ...

Retrieving task outputs

Outputs can be retrieved through the web dashboard, or via API.

Web Dashboard

In the dashboard, you’ll see all the outputs created for your app by clicking on the app detail page.

You can also view the outputs for an individual task by clicking on a task in the task list:

Task API

You can also use the /v1/task/{task_id}/status/ API to retrieve your task outputs:

curl -X GET \
  --header "Content-Type: application/json" \
  --user "{CLIENT_ID}:{CLIENT_SECRET}" \
  "https://api.beam.cloud/v1/task/{TASK_ID}/status/"

This returns a url to the generated image in the outputs object.

{
  "task_id": "edbcf7ff-e8ce-4199-8661-8e15ed880481",
  "started_at": "2022-11-04T19:43:25.668303Z",
  "ended_at": "2022-11-04T19:43:26.017401Z",
  "outputs": {
    "myimage": {
      "path": "output.png",
      "name": "myimage",
      "url": "http://data.beam.cloud/outputs/6446df99cf455a04e0335d9b/hw6hx/hw6hx-0001/edbcf7ff-e8ce-4199-8661-8e15ed880481/output.zip"
    }
  }
}

You can enter the URL in your browser which will download the output files to your local machine.