Skip to main content
Send file content in the format your model accepts: JSON values, base64-encoded bytes, or a URL that your model downloads. Your Truss defines the payload fields and output format. You need an active deployment, its model ID in BASETEN_MODEL_ID, and a Baseten API key in BASETEN_API_KEY. The JSON and base64 examples use an identity Truss that returns its input unchanged. Install requests with pip install requests for the Python clients.

Files as input

Send a file with JSON-serializable content

Save {"prompt": "Hello, world!"} as input.json, then choose a client.
To send JSON from a file:Run the following command:

Send a file with non-serializable content

The CLI’s --file option reads JSON. For audio, images, or other bytes, base64-encode the file if your model expects a base64 field. Use Binary I/O when your Truss accepts MessagePack instead. To round-trip file bytes through JSON: Run the following script against the identity Truss. It creates a UTF-8 file, sends it in a base64 field, and saves the returned bytes. Replace file with the field expected by your model:

Download files inside your model

To implement an input such as {"url": "https://example.com/recording.wav"}, download the file in preprocess(). The following methods belong in an existing Whisper Truss that already loads self._model; they illustrate the model implementation rather than a complete deployment. Add requests to the model’s requirements:
model/model.py
Flushing the file makes the written bytes visible before Whisper opens its path. The temporary file is removed after transcription. Deploy the changed Truss before sending URL inputs. For a complete transcription workflow that uploads a local file, use the speech quickstart.

Files as output

Save model output to a local file

To save the JSON response:Run the prediction and inspect the saved file:
Decode base64 output before writing image or audio bytes, as in the round-trip example above. For more information, see the image generation example.