Overview
All routes are underhttps://api.edenai.run/v3/batches and use the same Authorization: Bearer YOUR_API_KEY header as the rest of the API.
A batch that belongs to another account, or that does not exist, answers
404.
/v3/batches is the only batch API. The V2 API has none: its /v2/{feature}/{subfeature}/batch/{name}/ route runs each line as its own separate feature call and does not use OpenAI’s batch endpoint.
A sandbox token sends nothing to OpenAI: the batch is answered at once with sample results and is not billed.
Input file
The input is a JSONL file: one JSON object per line, in UTF-8. Empty lines are ignored. Each line describes one chat request:
No other key is allowed on a line.
Rules for every line
body.modelis an OpenAI model written asopenai/<model>, with no@or:suffix. Every line of a batch names the same model.- The model must have published batch rates. Models without them, models that price long-context bands or cache writes, and models that price cached input without a cached batch rate are refused.
- Messages carry text only. A message holds
role,contentand optionallycache_control. Acontentlist may containtextparts only. max_tokensormax_completion_tokenson each line sets how much output Eden AI reserves for that line. Without either, the reservation uses the model’s maximum output. See Billing.service_tier, when present, isautoordefault.routingmay only containzero_data_retention. See Zero data retention.
stream set to true, tools, functions, function_call, prediction, fallbacks, router_candidates, pre_hooks, post_hooks, session_id, tags, extra_headers and extra_body. Fields that set the provider connection or how a call is priced, such as api_key and api_base, are refused as in any other request.
File limits
A batch holds at most 5,000 lines, and the file is at most 100 MB. A file with more than 5,000 requests is refused with400, and so is a file with no request.
Create a batch
Send the file asmultipart/form-data.
Check a batch
status is completed, failed, expired or cancelled. Request counts refresh about every five minutes, so polling faster returns the same numbers.
List batches
GET /v3/batches returns your batches, newest first.
The response holds
data (the batch objects), first_id, last_id and has_more.
Cancel a batch
POST /v3/batches/{batch_id}/cancel asks OpenAI to stop the batch. The response is the batch object, and its status reads cancelling until OpenAI has stopped it, then cancelled.
Requests that completed before the cancel are billed, and their results stay available. A batch that has already finished answers 400.
Results
GET /v3/batches/{batch_id}/results streams the results as JSONL (application/jsonl), one line per request. Results stay available for 30 days after the batch was created.
A request that succeeded carries response, with the status_code and the chat completion body. The model in the body is the Eden AI id you sent, openai/<model>. A request that failed carries error instead.
custom_id. Do not rely on the order of the lines.
400 while the batch is still running, and 409 when the batch is finished on Eden AI’s side but OpenAI has not yet ended it. Retry after a short wait.
Statuses
cost and finished_at are filled in once the batch has finished and Eden AI has settled it. That can be a few minutes after the status reaches a final value.
The 24-hour window
OpenAI runs a batch within 24 hours. If the batch has not finished 25 hours after it was created, Eden AI cancels it, bills the requests that completed and makes their results available. Cancel a batch yourself at any time before that.Billing
Batches are billed at the model’s batch rates for input tokens, output tokens and, when the model has one, cached input tokens. These rates are lower than the standard rates of the same model. The rates are in thepricing object of each OpenAI model in GET /v3/models, as input_cost_per_token_batches, output_cost_per_token_batches and cache_read_input_token_cost_batches, in US dollars per token. A model whose entry has no input and output batch rate cannot be batched.
In your usage
The batch shows in usage monitoring as cost. The launch records the reservation and the settlement adds the difference between the final cost and the reservation, so the total is what the batch was charged. The settlement is not counted as a request or as tokens.- At create. Eden AI reserves the largest amount the batch could cost and deducts it from your balance. For each line, the reservation covers the prompt tokens plus the line’s
max_tokens(ormax_completion_tokens, or the model’s maximum output when neither is set), multiplied byn. If your balance or a member budget cannot cover it, the request answers402and nothing is sent. - At the end. The batch is settled once, from the results. Each request that succeeded bills the tokens it used. A request that failed bills nothing. A request that succeeded but reports no usage, or that OpenAI counts as completed but that has no line in the results, bills an estimate: its prompt tokens, plus the output its response shows and 8,192 tokens per completion, never more output than was reserved for it. The difference between the reservation and the final cost is returned to your balance.
- When nothing completed. The batch bills nothing and the whole reservation is returned.
- When results cannot be read. Each request that may have run bills the same estimate, with no output shown. For a batch that has ended, that is as many requests as OpenAI counts as completed, the largest estimates first. Otherwise it is every request. A batch with a request that may have run is never settled at zero.
max_tokens on every line to keep the reservation close to the real cost.
Content moderation
Eden AI checks the text of every line before the batch is sent. Sampling does not apply, and thebypass_moderation setting does not skip the check.
Zero data retention
OpenAI keeps batch input and output files until they are deleted, so batches cannot honor zero data retention. A batch is refused when your organization requires zero data retention (403) or when a line sets routing.zero_data_retention (400). A region restriction (allowed_regions) that excludes OpenAI’s default region is refused with 451.
Your own OpenAI key
Batches run on Eden AI’s OpenAI account only. If your organization has added its own OpenAI key, create requests are refused with400.
Webhooks
Passwebhook_receiver at create to be notified instead of polling. Eden AI sends a signed POST to the URL once the batch has finished and settled. The signature, headers and verification steps are the ones described in Webhooks.
The notification reports success for a completed batch and fail for any other final status. It does not carry the results: read them from the results route.
The payload has the shape of every Eden AI job notification. job_id is the batch id, and feature and subfeature are llm and batch:
To fetch the results when the notification arrives, read
job_id and call the results route:
Python
Limits and what batches do not do
- A batch holds at most 5,000 lines and 100 MB.
- A batch runs one model, and that model is an OpenAI model. Other providers are not supported.
- Only chat completions are supported. Other endpoints such as embeddings and responses are not.
- Lines cannot stream.
- Lines cannot carry tools, function definitions, function calls or predicted outputs.
- Lines cannot carry images or audio. Messages are text only.
- Batches run on Eden AI’s OpenAI account. Your own provider keys are not used.
- Fallbacks, hooks, sessions and tags are not available on a line.
Errors
When OpenAI fails a create, cancel or results call, the error status OpenAI returned is passed on with its message.
Related
- Chat Completions for the request body of each line.
- Webhooks for signed callbacks.
- Plans and pricing for credits and budgets.