https://api.morphllm.com/v1.
Available on morph-glm53flash, morph-dsv4flash, morph-glm53-744b, and morph-kimik3. Per-token rates are on the pricing page.
When to use it
Batch fits work where nobody is waiting on an individual response: eval runs, dataset generation, nightly summarization, re-indexing, backfills. You trade latency for price. Results land within 24 hours, usually much sooner, and there is no per-request rate limit to work around. For work that needs a response now, use the synchronous endpoint. For background traffic that still needs each answer within seconds, use Standby instead.Quick Start
Write one request per line in a JSONL file. Each line names acustom_id you choose, the endpoint, and the same body you would send synchronously.
requests.jsonl
- Python
- TypeScript
- cURL
Input file format
One JSON object per line. Blank lines are not allowed.
Every line in a batch must name the same
model. A file that mixes models, repeats a custom_id, or targets another endpoint fails validation and the batch goes to failed with the reasons in errors.
Output file format
One line per request the model answered, in completion order rather than input order. Join back to your requests oncustom_id.
response.body is the full Chat Completions response, usage included. error is always null in this file.
Error file format
One line per request that never got a model response.response is always null here.
Lines in the error file are not billed.
Statuses
Poll
GET /v1/batches/{batch_id} every 30 to 60 seconds. There is no webhook.
Cancel and expiry
- Cancel with
POST /v1/batches/{batch_id}/cancelwhile the batch isvalidatingorin_progress. It moves tocancelling, thencancelledonce in-flight requests drain. Cancelling a terminal batch returns 400; cancelling one alreadycancellingis a no-op. - Expiry happens when the 24-hour
completion_windowcloses. The batch moves toexpired. - In both cases partial output is kept. Whatever completed is in the output file and billed. Whatever did not run is in the error file and not billed. OpenAI discards results on cancel; Morph keeps them.
Limits
Pricing
Every request that completes is billed at 50% of the model’s synchronous rate, input and output alike. Requests in the error file are free. Cancel and expiry do not refund requests that already completed. Rates per model are on the pricing page.Retention
- Input files, output files, and error files are deleted 30 days after they are written. Download what you need before then, or set a shorter window with
expires_afteron upload andoutput_expires_afteron batch creation (1 hour to 30 days, anchored to when the file is created). - Zero-data-retention accounts: files and outputs are deleted after 24 hours. Poll and download promptly.
DELETE /v1/files/{file_id}removes a file immediately.
Pitfalls
Output file has fewer lines than my input
Output file has fewer lines than my input
Check the error file too. The two files together cover every
custom_id. If the batch is expired or cancelled, the missing lines are in the error file as batch_expired or batch_cancelled.A line has status_code 400 in the output file
A line has status_code 400 in the output file
That is the model rejecting that one request (a bad parameter, an oversized prompt). Read
response.body for the reason, fix the line, and resubmit it in a new batch. The rest of the batch is unaffected.SDK auto-pagination fails on list endpoints
SDK auto-pagination fails on list endpoints
after on GET /v1/files and GET /v1/batches is an integer offset, not an object id, so the SDK’s auto-paginator (which passes the last id) gets a 400. Pass after and limit yourself and increment after by limit.Output lines are in a different order than my input
Output lines are in a different order than my input
Expected: lines are written as requests complete. Join on
custom_id.See Also
- Standby Requests for background traffic that still needs answers in seconds
- Prompt Caching for repeated prefixes across requests
- Open Source Models for model ids and context windows
- API Reference: Batch for every field on every endpoint