Batch Api
Get Started with Batch API
Introduction
The Batch API is designed for asynchronous processing of long-running API tasks by offloading execution and storing results for later retrieval. This architecture is ideal for workloads such as media processing, transcription, translation, and other time-intensive operations that benefit from deferred, non-blocking execution.
Design Note:
Currently, our Batch API is designed for simplicity by submitting each file as a separate request, with the backend processing them asynchronously. To upload multiple files, we suggest using a loop to submit them individually. We're open to feedback and may consider expanding functionality, including multi-file support, based on user needs and usage patterns.
Clients submit requests synchronously over HTTP, specifying a target endpoint_id and path that define the backend service and API route. The server then processes these requests asynchronously in the background. Clients can check request status at any time and retrieve results once processing is complete. The system is fully endpoint-agnostic, allowing it to seamlessly route and support a wide range of backend services across Fireworks.AI's infrastructure.
For more information on Batch API parameters, including endpoint_id, path, and others, please refer to the link below:
This notebook gives examples of:
- Submit multiple files from a local directory for asynchronous batch processing;
- Track submissions and their statuses using a CSV file;
- Check the processing status of each submitted request and retrieve results once they are completed;
- Parse the body field of the response based on its content_type to access the final output.
Install dependencies
1. Prepare audio Samples
In this example, we'll download multiple pre-recorded audio files into a local directory. These files will be individually submitted to the Batch API for asynchronous transcription processing.
2. Set up API credentials
To use the Fireworks Batch API, you'll need your API key. For security reasons, we'll get it from environment variables.
You can set your API key in the notebook by running:
3. Submitting a Batch Processing Request
This section demonstrates how to submit multiple requests to the Batch API for asynchronous batch processing.
Files are loaded from a local directory, and submission results are recorded in a CSV file for later tracking.
When constructing your request, you’ll need to specify the following key parameters:
-
endpoint_id: Identifies the target backend service or model to handle the request (e.g.,"audio-prod","audio-turbo"). This must be compatible with the selected operation or model type. You can refer to the official documentation for a complete list of supportedendpoint_ids and their corresponding services. -
path: The relative route of the target API operation (e.g.,"v1/audio/transcriptions","v1/audio/translations"). This should correspond to a valid route supported by the backend service. -
payload: Contains the input data and configuration specific to the selected API route. Its structure should match the schema expected by the corresponding synchronous API.
The following example demonstrates how to submit multiple files individually to the transcription service for asynchronous batch processing.
View the submission statuses saved in batch_submission_status.csv:
4. Check Batch Processing Status and Retrieve Results
After submission, you can check whether each file has completed processing by querying the Batch API using the recorded account_id and batch_id. Completed results are updated back into the CSV file for later parsing.
-
account_id: This can be found on your Fireworks AI account homepage, it was also returned in the response when you initially submitted the batch request. -
batch_id: This was returned in the response when you initially submitted the batch request.
If the batch job has completed, the response includes a body and a content_type.
View the updated submission statuses saved in batch_submission_status.csv:
5. Parse and Display Completed Batch Responses
After the batch jobs have completed, you can parse the body field of each completed entry based on its content_type.
Parse the body according to its content_type, such as application/json for structured data (e.g., json, verbose_json), or text/plain; charset=utf-8 for plain text formats (e.g., text, srt, vtt), to reconstruct the original response from the backend service.
Conclusion
In this notebook, you learned how to use the Fireworks.AI Batch API to asynchronously process long-running requests by submitting multiple files individually.
We covered how to prepare files from a local directory, submit each file as a separate batch request, track submission statuses in a CSV file, check processing status, retrieve results once completed, and parse the response body based on its content type.
This approach is especially useful for workloads such as transcription, translation, and other media-related tasks that benefit from asynchronous, scalable processing.
For more information, see:
Explore the community or reach out to us in discord.