Batch Processing API

FastRouter's Batch Processing API is ideal for handling large volumes of AI tasks efficiently, such as bulk content generation or data processing.

Introduction

FastRouter's Batch Processing API feature enables you to upload a JSONL file containing multiple chat completion or embedding requests, which are then processed asynchronously across supported providers (currently OpenAI and Anthropic). Results are returned in a downloadable JSONL file once processing is complete.

Batch processing helps optimize costs and throughput by leveraging asynchronous execution. Ensure your JSONL file follows the required format, and use your FastRouter API key for authentication.


Batch File Format

Your input file must be in JSONL format (one JSON object per line). Each line represents a single request and includes fields like custom_id, provider, method, url, and body. The body should contain standard chat completion parameters, such as model and messages.

Sample Batch File (JSONL)

{"custom_id": "request-1", "provider" : "anthropic", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "anthropic/claude-4.5-sonnet", "messages": [{"role": "user", "content": "Hello world! what is 13 + 25"}],"max_tokens": 1000}}
{"custom_id": "request-2", "provider" : "anthropic","method": "POST", "url": "/v1/chat/completions", "body": {"model": "anthropic/claude-4.5-sonnet", "messages": [{"role": "user", "content": "Hello world! what comes next in series 2 ,4, 6, 8, 10, "}],"max_tokens": 1000}}
{"custom_id": "request-3", "provider" : "openai", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "openai/gpt-4.1-nano", "messages": [{"role": "system", "content": "You are a helpful assistant."},{"role": "user", "content": "Hello world! what is 13 + 25"}],"max_tokens": 1000}}
{"custom_id": "request-4", "provider" : "openai","method": "POST", "url": "/v1/chat/completions", "body": {"model": "openai/gpt-4.1", "messages": [{"role": "system", "content": "You are an unhelpful assistant."},{"role": "user", "content": "Hello world! what comes next in series 2 ,4, 6, 8, 10, "}],"max_tokens": 1000}}

Note: Save this as a .jsonl file (e.g., sample.jsonl). Each request can target different providers (OpenAI and Anthropic currently) and models for flexibility.


1. File Upload (POST Request)

Upload your JSONL file to FastRouter to initiate the batch process. This returns a file_id for use in subsequent steps.

Endpoint

Curl Example

Sample Response


2. Trigger Batch (POST Request)

Once the file is uploaded, trigger the batch processing by providing the input_file_id, endpoint, and completion window (currently, accepts only "24h" for a 24-hour processing window).

Endpoint

Curl Example

Sample Response


3. Get Status (GET Request)

Check the status of your batch job using the batch_id returned from the trigger step. Statuses include "in_progress", "completed", "failed", etc.

Endpoint

Curl Example

Sample Response


4. Download File (GET Request)

Once the batch is completed (check via status), download the output JSONL file containing responses for each request.

Endpoint

Curl Example

Sample Response (JSONL Output)


Key Takeaway

FastRouter's Batch Processing API streamlines asynchronous handling of multiple AI requests, supporting OpenAI and Anthropic for efficient, scalable operations. Upload your JSONL file, trigger the batch, monitor status, and download results — all via simple API calls. For real-time requests, see our Chat Completion Request docs.

Last updated