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.

Implementation:Groq Groq python JSONL Construction

From Leeroopedia
Knowledge Sources
Domains Batch_Processing, Data_Preparation
Last Updated 2026-02-15 16:00 GMT

Overview

User-defined pattern for constructing JSONL batch input files for the Groq batch processing API.

Description

This is a Pattern Doc — there is no library API for this step. Users construct the JSONL file themselves using Python's built-in json module. Each line must conform to the batch request schema with custom_id, method, url, and body fields.

Usage

Construct the JSONL file before uploading via client.files.create(). Ensure each line is valid JSON and the file is under 100 MB.

Interface Specification

# Required schema for each JSONL line
{
    "custom_id": str,              # Unique identifier for this request
    "method": "POST",             # HTTP method (always POST for completions)
    "url": "/v1/chat/completions", # API endpoint path
    "body": {
        "model": str,             # Model identifier
        "messages": [             # Chat messages array
            {"role": str, "content": str},
            ...
        ],
        # Optional: temperature, max_tokens, etc.
    }
}

I/O Contract

Inputs

Name Type Required Description
data List[dict] Yes List of request specifications to batch

Outputs

Name Type Description
(file) .jsonl file One JSON object per line, up to 100 MB

Usage Examples

import json

requests = [
    {
        "custom_id": "req-1",
        "method": "POST",
        "url": "/v1/chat/completions",
        "body": {
            "model": "llama-3.3-70b-versatile",
            "messages": [
                {"role": "user", "content": "Summarize quantum computing"}
            ]
        }
    },
    {
        "custom_id": "req-2",
        "method": "POST",
        "url": "/v1/chat/completions",
        "body": {
            "model": "llama-3.3-70b-versatile",
            "messages": [
                {"role": "user", "content": "Explain machine learning"}
            ]
        }
    },
]

with open("batch_input.jsonl", "w") as f:
    for req in requests:
        f.write(json.dumps(req) + "\n")

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment