Skip to main content
Run many chat requests as one asynchronous batch. You upload a file with one request per line, Eden AI runs the whole batch on OpenAI within 24 hours at OpenAI’s batch rates, and you read the results when the batch has finished. Batches suit work that does not need an immediate answer, such as classifying a dataset, summarizing documents or running an evaluation.

Overview

All routes are under https://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.model is an OpenAI model written as openai/<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, content and optionally cache_control. A content list may contain text parts only.
  • max_tokens or max_completion_tokens on 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, is auto or default.
  • routing may only contain zero_data_retention. See Zero data retention.
These body fields are refused: 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 with 400, and so is a file with no request.

Create a batch

Send the file as multipart/form-data.
The response is the batch object:

Check a batch

Poll this route every few minutes until 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.
Match results to requests with custom_id. Do not rely on the order of the lines.
The results route answers 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 the pricing 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 (or max_completion_tokens, or the model’s maximum output when neither is set), multiplied by n. If your balance or a member budget cannot cover it, the request answers 402 and 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.
Set 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 the bypass_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 with 400.

Webhooks

Pass webhook_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
The URL must be public. Addresses that resolve to private networks are refused.

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.