Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Workflow:Groq Groq python Batch Processing

From Leeroopedia
Revision as of 11:03, 16 February 2026 by Admin (talk | contribs) (Auto-imported from workflows/Groq_Groq_python_Batch_Processing.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains LLMs, Batch_Inference, Data_Processing
Last Updated 2026-02-15 16:00 GMT

Overview

End-to-end process for submitting bulk chat completion requests via Groq's batch processing API.

Description

This workflow covers the procedure for processing large volumes of chat completion requests asynchronously through Groq's batch API. Instead of making individual API calls, users upload a JSONL file containing multiple request payloads, submit it as a batch job, and retrieve results when processing completes. This approach is designed for offline workloads where latency is not critical but throughput and cost efficiency matter. The batch API supports completion windows from 24 hours to 7 days.

Usage

Execute this workflow when you have a large number of chat completion requests (hundreds to thousands) that do not require real-time responses. This is appropriate for dataset annotation, bulk content generation, evaluation pipelines, data enrichment tasks, or any scenario where you can tolerate asynchronous processing in exchange for higher throughput.

Execution Steps

Step 1: Client Initialization

Instantiate the Groq client with authentication credentials. The batch and file APIs share the same client as other Groq endpoints.

Key considerations:

  • Same Groq() or AsyncGroq() client used for all API endpoints
  • File uploads may require extended timeouts for large JSONL files (up to 100 MB)

Step 2: Input File Preparation

Prepare a JSONL (JSON Lines) file where each line contains a single batch request object. Each request specifies a custom_id for tracking, the method (POST), the URL (/v1/chat/completions), and a body containing the standard chat completion parameters (model, messages, etc.).

Key considerations:

  • Each line must be a valid JSON object with custom_id, method, url, and body fields
  • The body field contains the same parameters as a regular chat completions request
  • Maximum file size is 100 MB
  • custom_id is used to match requests with results in the output

Step 3: File Upload

Upload the JSONL file to Groq's file storage using the files create endpoint with purpose set to "batch". The API returns a file object containing the file_id needed for batch creation.

Key considerations:

  • The file must be uploaded with purpose="batch"
  • The response contains an id field used as input_file_id in the next step
  • File can be provided as a Path, bytes, or (filename, content, media_type) tuple

Step 4: Batch Creation

Create a batch job by calling the batches create endpoint with the uploaded file ID, the target endpoint (/v1/chat/completions), and a completion window. The API validates the file and begins processing.

Key considerations:

  • input_file_id must reference a previously uploaded file with purpose="batch"
  • endpoint must be "/v1/chat/completions" (only supported endpoint)
  • completion_window specifies the processing deadline (24h to 7d)
  • Optional metadata dictionary can be attached for tracking

Step 5: Batch Status Polling

Monitor the batch job by periodically calling the batches retrieve endpoint with the batch ID. The response includes the current status (validating, in_progress, completed, failed, expired, cancelled) and progress counters for completed, failed, and total requests.

Key considerations:

  • Poll at reasonable intervals to avoid rate limiting
  • Status progresses through: validating, in_progress, and then a terminal state
  • The response includes request_counts with completed, failed, and total fields
  • Terminal states: completed, failed, expired, cancelled

Step 6: Results Retrieval

Once the batch reaches a terminal state, retrieve the output file using the output_file_id from the batch response. Download the file content via the files content endpoint. The output is a JSONL file where each line contains the custom_id, response status, and the chat completion result body.

Key considerations:

  • output_file_id is populated when the batch reaches a terminal state
  • error_file_id contains details of any failed requests
  • The output JSONL maps custom_id back to individual results
  • Download the binary content and parse each line as JSON

Execution Diagram

GitHub URL

Workflow Repository