Skip to content

Files & outputs

Cog models take files in (audio, images, video) and often produce files. Turion’s clients handle both directions.

File inputs are uploaded to Turion storage before the prediction is created:

  • CLI: -i key=@path

    Terminal window
    turion run acme/whisper -i audio=@sample.wav
  • Python SDK: a pathlib.Path, an open file object, or a string that names an existing local file, anywhere in the input dict or list:

    client.run("acme/whisper", input={"audio": "sample.wav"}) # str path
    client.run("acme/whisper", input={"audio": Path("sample.wav")}) # Path
    client.run("acme/whisper", input={"audio": open("sample.wav", "rb")})

Over REST this is two calls: POST /v1/uploads returns a presigned upload_url and an input_ref (a turion://… reference); PUT the bytes to the URL and pass the input_ref as the input value. See the REST API reference for the shapes. Upload URLs expire at expires_at, so upload shortly before you submit.

Nothing is uploaded. @file inputs are inlined into the request as base64 data: URIs and sent straight to the container on your machine.

A prediction’s output is JSON. Files appear inside it as URLs or data URIs, depending on where the model ran:

File outputs are stored by Turion and returned as signed HTTPS URLs inside the output JSON. The URLs expire 24 hours after the run, so download what you want to keep rather than storing the links. turion run -o DIR saves every output file as DIR/{prediction_id}/{key}.{ext} when the run finishes:

Terminal window
turion run acme/sdxl -i prompt="a lighthouse" -o outputs/
turion prediction get <prediction-id> # output contains https://… links
curl -o out.png "https://…"

turion cog predict receives file outputs as data: URIs and writes them to your working directory as output.0.png, output.1.wav, … (extension from the MIME type). The printed JSON has the file paths in place of the base64:

Terminal window
turion cog predict sdxl-demo:latest -i prompt="a lighthouse"
{
"image": "output.0.png"
}
  • Prefer @file uploads to base64 in key=value strings: uploads go straight to storage instead of through the prediction request body.
  • Model weights do not belong in inputs. Bake them into the image or download them in setup(); see Cog on Turion.