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.
How do I fix the file and purpose when OpenAI Batch fails with invalid JSONL?
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
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.
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
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
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.
Open: 1 spot per week
One labeled sponsor for this topic each week; this week's spot is open. See open weeks →
All tools for “Fix OpenAI Batch JSONL / purpose validation errors” →
Related fixes
- Stop a Cursor agent loopHow to fix a Cursor agent loop (same edit, or work after Stop)Fix →
- Claude Code vs Codex vs Cursor ~$20 plansClaude Code vs Codex vs Cursor $20 plan limits: how to pick without burning the weekFix →
- Scan a vibe-coded app for leaked API keysCheck a vibe-coded app for leaked API keys before you share itFix →
- Add an MCP server to Claude Code, Cursor, or CodexHow to add an MCP server to Claude Code, Cursor, or CodexFix →
See also AI tools launched today on the daily board.
NewAIToolsToday Daily
Top 3 AI launches, one model or news item that matters, and one simple fix. A 5-minute read, every weekday.