Submit a toolSubmit

OpenAI Batch fails with invalid JSONL. Fix the file and purpose

OpenAI Batch fails if JSONL isn’t UTF-8, purpose isn’t batch, custom_ids repeat, or endpoints mix. Rebuild the file, upload with purpose batch, then create it. Short answer: 5 steps. 1) Confirm the error is Batch JSONL / purpose, not a model 4xx; 2) Rewrite the input as one JSON object per line; 3) Keep every line on the same endpoint; 4) Upload with purpose batch, then create; 5) If the batch still fails, read the error file.

Last updated: · This page is the decision checklist; the tools list for “Fix OpenAI Batch JSONL / purpose validation errors” is a separate URL.

The problem: OpenAI Batch fails if JSONL isn’t UTF-8, purpose isn’t batch, custom_ids repeat, or endpoints mix. Rebuild the file, upload with purpose batch, then create it.

How do I fix the file and purpose when OpenAI Batch fails with invalid JSONL?

  1. Confirm the error is Batch JSONL / purpose, not a model 4xx

    Upload errors often say the file must be .jsonl or that batch files need purpose "batch". After create, status failed means input validation failed; completed batches with failed request counts put per-line errors in error_file_id. Docs: https://developers.openai.com/api/docs/guides/batch

  2. Rewrite the input as one JSON object per line

    Each line needs custom_id (unique across the file), method "POST", url (one of the Batch-supported endpoints such as /v1/responses or /v1/chat/completions), and body with the same fields as the live endpoint. Use a single model across the file. Save as UTF-8 without a BOM, no blank lines, and keep the file under 200 MB / 50,000 requests.

  3. Keep every line on the same endpoint

    Mixing urls (for example /v1/chat/completions and /v1/embeddings in one file) is rejected. When you create the batch, set endpoint to that same path and completion_window to "24h". Reference: https://developers.openai.com/api/reference/resources/batches/methods/create

  4. Upload with purpose batch, then create

    Call Files with purpose="batch" (not assistants or fine-tune). Pass the returned file id as input_file_id to Batches create. Wrong purpose returns a 400 that batch uploads must use purpose batch — https://developers.openai.com/api/reference/resources/files/methods/create

  5. If the batch still fails, read the error file

    Poll until status is failed or completed. For failed validation, fix the JSONL and start a new batch. For completed with failed lines, download error_file_id and match custom_id (duplicate ids, bad body fields, stream:true on moderations). Don’t rely on output line order—always join on custom_id.

Which tools are best to fix OpenAI Batch JSONL / purpose validation errors?

OpenAI Batch guide

JSONL line format, supported endpoints, upload, create, status, and error_file_id.

Files API (purpose batch)

Upload input with purpose batch; Batch files must be .jsonl up to 200 MB.

Batches create

input_file_id, endpoint, completion_window 24h, and batch status fields.

OpenAI Platform

Inspect uploaded files and batch jobs in the dashboard while debugging.

All tools for “Fix OpenAI Batch JSONL / purpose validation errors” →

Related fixes

See also AI tools launched today on the daily board.