Skip to main content
Baseten supports file-based input and output during inference, whether the file is local or remote and whether you handle it in the Truss or in your client code.

Files as input

Send a file with JSON-serializable content

The Truss CLI has a -f flag to pass file input. If you’re using the API endpoint from Python, get file contents with the standard f.read() function.

Send a file with non-serializable content

The -f flag for truss predict only applies to JSON-serializable content. For other files, like the audio files required by MusicGen Melody, base64-encode the file content before you send it:
call_model.py

Send a URL to a public file

Rather than encoding and serializing a file to send in the HTTP request, write a Truss that takes a URL as input and loads the content in the preprocess() function. Here’s an example from Whisper in the model library:
model/model.py

Files as output

Save model output to a local file

Saving model output to a local file needs no Baseten-specific code. Use the standard > operator in bash or the file.write() function in Python:
Output for some models, like image and audio generation models, may need to be decoded before you save it. See our image generation example for how to parse base64 output.