Core CLI
opod batch
Run an OpenAI batch input file against any OpenAI-compatible URL at bounded concurrency, resumably, never sending a line twice.
In short
opod batch run sends an OpenAI batch file (JSONL, one request per line) to any OpenAI-compatible URL at bounded concurrency. It keeps its progress in a work directory, so a stopped run resumes on the same directory and never sends a line twice. It needs no leader and no store.
export OPOD_API_KEY=sk-orc-<your-key>
opod batch run --input requests.jsonl --base-url http://leader:8080 --dir ./run1{"progress": {"total": 1000, "completed": 420, "failed": 3}}
{"batch": {"total": 1000, "completed": 997, "failed": 3, "interrupted": 0, "state": "completed", "output": "run1/output.jsonl", "errors": "run1/errors.jsonl"}}Usage
opod batch run (--input FILE|URL | --input-url PRESIGNED_URL) --base-url URL --dir WORKDIR [options]opod batch run is a generic OpenAI batch client. It reads a file in OpenAI's batch line format (one JSON object per line with custom_id, method, url, body), sends each line to an OpenAI-compatible server, and writes OpenAI's batch output shape. It needs no leader and no store: point it at an opod leader or any other server.
Flags
| Flag | Default | Effect |
|---|---|---|
--input FILE|URL | — | The input: a JSONL path, or an http(s) URL read with the key (for example an OpenAI files content URL). |
--input-url URL | $OPOD_BATCH_INPUT_URL | The input as a URL that carries its own authorization (a presigned GET). Read without the key. Give --input or --input-url, not both. |
--base-url URL | $OPOD_BASE_URL | The server, with or without /v1. Required. |
--dir DIR | — | Work directory: the progress record and the result files. Required. |
--concurrency N | 8 | Requests in flight at once. |
--file-order | off | Send lines in file order. By default lines that share a leading prompt are sent together, so the engine's prefix cache reuses it. |
--model-map a=b[,c=d] | — | Rewrite a line's model. Other models are sent as written. |
--ca FILE | $OPOD_LEADER_CA | PEM certificate an https base URL must be signed by. |
--timeout D | 10m | Per-request timeout. |
--ready-timeout D | 0 | Wait up to this long for GET /v1/models to accept the key before the first line. 0 does not wait. |
--drain D | 20s | After a stop, how long in-flight requests may finish. |
--status-url URL | — | An OpenAI batch object (…/v1/batches/<id>), read with the key on SIGTERM. |
--output-url URL | $OPOD_BATCH_OUTPUT_URL | PUT output.jsonl here when the run ends. A URL that carries its own authorization. |
--error-url URL | $OPOD_BATCH_ERROR_URL | PUT errors.jsonl here when the run ends. |
--progress-every D | 5s | How often a progress line is printed. 0 = never. |
The key comes from OPOD_API_KEY, else OPENAI_API_KEY, and is sent as Authorization: Bearer. With neither set, requests go out with no key. --base-url may end in /v1 or not; a line's url of /v1/chat/completions is joined to it without doubling the /v1.
export OPOD_API_KEY=sk-orc-<your-key>
opod batch run --input requests.jsonl --base-url http://leader:8080 --dir ./run1
opod batch run --input requests.jsonl --base-url http://leader:8080/v1 --dir ./run2 \
--concurrency 32 --model-map gpt-4o-mini=llama-3.2-3bMore flags, one per line:
opod batch run --input requests.jsonl --base-url https://leader.example.com --dir ./run3 \
--ca /etc/opod/ca.crt \
--file-order \
--timeout 2m \
--ready-timeout 10m \
--drain 1m \
--progress-every 30s
# A managed job: presigned input and result URLs, and the batch's status URL for SIGTERM
opod batch run --input-url "$OPOD_BATCH_INPUT_URL" --base-url http://leader:8080 --dir /work \
--output-url "https://bucket.example.com/out.jsonl?X-Amz-Signature=…" \
--error-url "https://bucket.example.com/err.jsonl?X-Amz-Signature=…" \
--status-url http://batch-api.example.com/v1/batches/batch_abcInput lines
Each non-blank line is one request in OpenAI's batch format:
{"custom_id": "q-1", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "llama-3.2-3b", "messages": [{"role": "user", "content": "hi"}]}}Blank lines are skipped and not counted; line numbers stay the input's. A line longer than 64 MiB fails the whole run before anything is sent. A line that cannot be sent is not sent, and goes to errors.jsonl with code invalid_request and one of these messages:
| Message | Cause |
|---|---|
the line is not a JSON object: … | Not JSON. |
custom_id is required | No custom_id. |
method must be POST | A method other than POST (an empty method is taken as POST). |
url must be a path such as /v1/chat/completions | url does not start with /. |
body must be a JSON object | body missing or not an object. |
--model-map rewrites body.model before the line is sent; a bad map is refused at start: error: --model-map "x": want alias=id[,alias=id].
An http(s) --input (or --input-url) is downloaded once into the work directory as input.jsonl (temporary file, then rename), so a resume never reads a file that changed underneath it. --input sends the key with the download; --input-url does not, because a presigned URL is its own credential.
The work directory
The directory is the whole progress record. Run the same command on the same directory to resume.
| File | Holds |
|---|---|
sent.jsonl | One {"line":N} per input line, written and synced before that line's request leaves. |
output.jsonl | One OpenAI output object per answered line (2xx). |
errors.jsonl | One object per failed line: a non-2xx answer, a transport error, a malformed line, or a line in flight at a kill. |
Every result's id is batch_req_<line>. One result line looks like this:
{"id": "batch_req_0", "custom_id": "q-1", "response": {"status_code": 200, "request_id": "…", "body": {…}}, "error": null}
{"id": "batch_req_7", "custom_id": "q-8", "response": null, "error": {"code": "request_failed", "message": "…"}}A non-2xx answer keeps the server's own status and body in response. The runner's own error codes are invalid_request (a malformed line), request_failed (a transport error or the per-request timeout), interrupted (in flight at a kill) and cancelled (cut off by a cancel). When a resume finds input.jsonl already in the directory, it uses it as is.
At most once. A line recorded as sent but with no result was in flight when the previous run died. It is not sent again: it goes to errors.jsonl with code interrupted. Collect those custom_ids and submit them again if you want them retried. A lost work directory starts again from line 0.
Output
Progress lines and the final summary are JSON on stdout:
{"progress": {"total": 1000, "completed": 420, "failed": 3}}
{"batch": {"total": 1000, "completed": 997, "failed": 3, "interrupted": 0, "state": "completed", "output": "run1/output.jsonl", "errors": "run1/errors.jsonl"}}state is completed, cancelled or interrupted. With --output-url or --error-url, the summary also carries written. The results are uploaded even after a stop, so a stopped batch still returns what it finished.
Signals and exit codes
SIGINT(Ctrl-C) cancels: no new line is sent, in-flight requests get--drain.SIGTERMcancels only when the batch at--status-urlis no longervalidatingorin_progress, or answers401,403or404(the batch is gone). Otherwise — including with no--status-url, or a status URL that does not answer — the run stops as interrupted and exits75, so a supervisor resumes it. A Kubernetes Job counts exit0as finished and never runs it again;75keeps it retrying.
Uploads with --output-url and --error-url are one plain PUT each, with the body's length stated and no Authorization header (the URL is the credential). An empty result file is not uploaded; written says which were: {"output": true, "errors": false}. The upload has 10 minutes, even after a stop. A resumed run uploads again and replaces what an earlier attempt wrote.
| Code | Meaning |
|---|---|
0 | Completed or cancelled. |
1 | The run or the upload failed. |
2 | Usage error: no input, both --input and --input-url (error: give --input or --input-url, not both), no --dir or no --base-url, a bad --model-map, or an unreadable --ca file. |
75 | Interrupted; run again on the same --dir. |
From core v0.4.6, every message starts with opod: (not error:) and names what is missing (batch run needs --dir, the work directory it resumes from). A run in which some lines failed still exits 0 — it completed, as an OpenAI batch does, and a Job would run it again on any other code — but stderr says N of M line(s) failed — see <dir>/errors.jsonl. A resumed run logs resuming with the lines done and the lines left. A --ready-timeout that runs out says which it was: no server answering at … — check --base-url, … did not accept the key (401 …) — set OPOD_API_KEY (or OPENAI_API_KEY), or the status it answered.
Last updated · Source: content/docs/core-cli/batch.mdx · View as Markdown