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.
- Baseten CLI
- Python
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
Files as output
Save model output to a local file
- Baseten CLI
- Python
To save the JSON response:Run the prediction and inspect the saved file: