OpenAI-compatible REST API for batch inference. Base URL: http://<host>:<port> (default port 10900).
| Method | Path | Description |
|---|---|---|
| GET | /v1/models |
List available models |
| GET | /v1/models/{model_id} |
Get model metadata |
| POST | /v1/files |
Upload input file |
| GET | /v1/files |
List files |
| GET | /v1/files/{file_id} |
Get file metadata |
| DELETE | /v1/files/{file_id} |
Delete file |
| GET | /v1/files/{file_id}/content |
Download file content |
| POST | /v1/batches |
Create batch job |
| GET | /v1/batches |
List batches |
| GET | /v1/batches/{batch_id} |
Get batch status |
| POST | /v1/batches/{batch_id}/cancel |
Cancel batch |
| POST | /v1/sessions |
Open an agent session |
| POST | /v1/sessions/{session_id}/close |
Close a session (end of session / trajectory) |
| POST | /v1/sessions/{session_id}/abort |
Abort a session and its in-flight turn |
| POST | /v1/turns |
Run one chat-completions turn of a session |
| POST | /v1/workers/restart |
Restart the GPU worker pool (see Server Flags) |
| GET | /v1/admin/debug-state |
The server's current debug state (see Server Flags) |
| POST | /v1/admin/debug-state |
Set or clear server-level debug switches |
| GET | /v1/workers/status |
Worker-pool state and restart status |
| GET | /health |
Health check |
On a multi-node server, send every /v1/files, /v1/batches, /v1/turns and
/v1/sessions request to node 0. Any other node answers 409 naming node 0.
List the model currently loaded on the server.
curl http://localhost:10900/v1/modelsResponse: ListModelsResponse
{
"object": "list",
"data": [
{
"id": "Kimi-K2.5",
"object": "model",
"created": 1711234567,
"owned_by": "batchgen",
"max_context_length": 262144
}
]
}Retrieve metadata for a specific model.
curl http://localhost:10900/v1/models/Kimi-K2.5Response: ModelObject
| Field | Type | Description |
|---|---|---|
id |
string | Model name (last component of model path) |
object |
string | Always "model" |
created |
integer | Unix timestamp when server started |
owned_by |
string | Always "batchgen" |
max_context_length |
integer | Maximum context length in tokens (prompt + completion) |
Error: Returns 404 if model_id does not match the loaded model.
Upload a JSONL input file for batch processing.
Request: multipart/form-data
| Field | Type | Required | Description |
|---|---|---|---|
file |
file | Yes | The JSONL file to upload |
purpose |
string | Yes | Must be "batch" |
Response: FileObject
{
"id": "file-abc123",
"object": "file",
"bytes": 1024,
"created_at": 1710000000,
"filename": "requests.jsonl",
"purpose": "batch",
"status": "uploaded",
"checksum": "sha256:..."
}List uploaded files.
Query Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
purpose |
string | None | Filter by purpose |
limit |
int | 10000 | Max results (1-10000) |
order |
string | desc |
Sort order (asc or desc) |
after |
string | None | Cursor for pagination |
Response: ListFilesResponse
{
"data": [ ...FileObjects... ],
"has_more": false
}Get metadata for a specific file.
Response: FileObject (same schema as upload response)
Delete a file.
Response:
{
"id": "file-abc123",
"deleted": true,
"object": "file"
}Download file content (input or output JSONL).
Response: Raw file bytes with Content-Disposition: attachment header.
Create a batch job from an uploaded input file.
Request: application/json
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
input_file_id |
string | Yes | - | ID of uploaded JSONL file |
endpoint |
string | No | /v1/chat/completions |
Target endpoint (/v1/chat/completions or /v1/completions) |
completion_window |
string | No | 24h |
Completion time window |
metadata |
object | No | None | Arbitrary metadata |
max_decoding_length |
int | No | None | Batch-level fallback max output tokens (see Input Format) |
max_context_length |
int | No | None | Deprecated and ignored (logged as a warning). The deployment max_model_len (GET /v1/models) bounds prompt + completion for every request; limit decode length with max_tokens / max_completion_tokens per request or max_decoding_length per batch. |
temperature |
float | No | None | Default sampling temperature. Per-request values override. |
top_p |
float | No | None | Default nucleus sampling threshold. Per-request values override. |
top_k |
int | No | None | Default top-k filtering. Per-request values override. |
batchgen_debug |
object | No | None | Not accepted. Debug switches belong to the server, not to a batch: set them with POST /v1/admin/debug-state before submitting. A batch that carries a non-empty batchgen_debug is refused with 400. |
POST /v1/batches answers 503 with Retry-After: 30 while the worker pool
is not serving (during a worker-pool restart or after the pool went down), and
429 with Retry-After: 30 when the intake pool is near capacity.
Response: BatchObject
{
"id": "batch_abc123",
"object": "batch",
"endpoint": "/v1/chat/completions",
"input_file_id": "file-abc123",
"output_file_id": null,
"completion_window": "24h",
"status": "validating",
"created_at": 1710000000,
"expires_at": 1710086400,
"started_at": null,
"completed_at": null,
"cancelled_at": null,
"cancelling_at": null,
"error": null,
"request_counts": {"total": 0, "completed": 0, "failed": 0},
"metadata": null,
"max_decoding_length": 1024,
"temperature": null,
"top_p": null,
"top_k": null
}List batch jobs.
Query Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
limit |
int | 20 | Max results (1-100) |
after |
string | None | Cursor for pagination |
Response:
{
"data": [ ...BatchObjects... ],
"has_more": false
}Get current status of a batch job. Use this endpoint to poll for completion.
Response: BatchObject (same schema as create response, with updated status and timestamps)
request_counts follows the OpenAI Batch object. total is the number of
requests in the input file, set once the file is validated (0 before that,
and for a batch that fails validation). Each request is counted once, when its
result is written to the output file: completed if the output item has a
response, failed if it has an error (for example a prompt rejected at
admission or a request the worker failed). completed + failed <= total, and
the two sum to total when the batch is completed. While the batch runs the
counts are live; a batch that ends failed (including one failed by a server
restart) keeps the counts it had reached. Failed requests stay in the single
output file (output_file_id); there is no separate error file.
Cancel a batch in validating or in_progress state (other states return an error). The batch is marked cancelled immediately; cancelling_at and cancelled_at are set to the same timestamp. A cancelled batch that has not started yet is skipped by the scheduler; sequences already executing are not interrupted.
Response: BatchObject with status: "cancelled"
validating → in_progress → completed
→ failed
→ cancelled
| Status | Description |
|---|---|
validating |
Input file is being parsed and validated |
in_progress |
Sequences are being processed |
completed |
All sequences finished. output_file_id is set. |
failed |
Processing failed. error field has details. |
cancelling |
Reserved. Defined in the API schema but currently never emitted — cancel sets cancelled directly. |
cancelled |
Batch was cancelled. cancelled_at is set. |
Timestamps: started_at, completed_at, cancelled_at, cancelling_at are set as the batch transitions through states.
For an offline agent harness that sends one model turn at a time: a turn is answered in its own HTTP response, with no file upload and no batch polling. Each turn carries its trajectory and session identity in-band; the session lifecycle is signalled out of band. Turns share the IntakePool and the workers with running batches. Like the batch routes, these are served by node 0 only.
| Term | Meaning |
|---|---|
traj_id |
One agent task (item); shared by its sub-agents |
session_id |
One model context inside a trajectory; not reused (see below) |
parent_session_id |
The session that spawned this one (optional; same trajectory) |
Session states: open → (turn) turn_in_flight → (answered or failed) idle
→ (turn) … ; open/idle → closed; open/idle/turn_in_flight →
aborted. closed and aborted are terminal. A session must be opened
explicitly: a turn for an unknown session gets 404 session_not_found, and
there is no implicit open. A session has at most one turn in flight.
A closed or aborted session is kept as a tombstone that blocks reuse of
its id until terminal_ttl_s (default 3600) seconds after it ended, or until
max_terminal (default 65536) later sessions have ended, whichever comes
first. After that the server forgets it: a turn for that id
gets 404 session_not_found and the id can be opened again. Clients should
still use ids that are unique per run (e.g. <traj_id>/<name>).
{"traj_id": "traj-17", "session_id": "traj-17/main", "parent_session_id": null}Response: the session (state: "open"). 409 session_exists if the id is
live or still held as a tombstone; 404 parent_session_not_found / 400 parent_session_other_trajectory
for a bad parent.
{"reason": "end_of_session"}The id is the rest of the path and may contain /
(POST /v1/sessions/traj-17/main/close); the same holds for /abort.
reason is end_of_session (this session) or end_of_trajectory (every live
session of the same traj_id). All-or-nothing: 409 turn_in_flight if any of
them has a turn running. Response: {"object": "session.close", "reason": …, "closed": [sessions]}.
Optional body {"reason": "tool_crash"}. Marks the session aborted and
cancels its in-flight turn, whose caller gets 409 turn_aborted. A turn still
queued is removed before it reaches a worker (cancelled_turn: "dequeued"); a
turn already running on a worker runs to completion there and its result is
discarded (cancelled_turn: "detached") — the same limit as batch cancel.
A turn is finished once the server routes its worker completion, even before
its HTTP response is written. An abort that arrives in that window gets
409 already_completed and changes nothing: the turn returns its answer and
the session goes idle. Abort again after the turn has returned to end the
session.
An OpenAI chat-completions body (model, messages, tools, max_tokens or
max_completion_tokens (required), sampling parameters, reasoning_effort, …)
plus a session object. Debug switches are not accepted on a turn (see
Debug state). The prompt is
rendered exactly as for a /v1/batches chat request. n must be 1.
{
"model": "gpt-oss-120b",
"messages": [{"role": "user", "content": "List the files."}],
"tools": [{"type": "function", "function": {"name": "ls", "parameters": {"type": "object"}}}],
"max_tokens": 1024,
"temperature": 0.6,
"session": {"traj_id": "traj-17", "session_id": "traj-17/main"}
}Response: a chat.completion object with
usage.prompt_tokens_details.cached_tokens and a batchgen extension
(values below are illustrative):
{
"id": "chatcmpl-…", "object": "chat.completion", "model": "gpt-oss-120b",
"choices": [{"index": 0, "message": {"role": "assistant", "content": "…"}, "finish_reason": "stop"}],
"usage": {"prompt_tokens": 812, "completion_tokens": 95, "total_tokens": 907,
"prompt_tokens_details": {"cached_tokens": 0}},
"batchgen": {
"turn_id": "turn_3f…",
"session": {"traj_id": "traj-17", "session_id": "traj-17/main", "parent_session_id": null},
"cached_tokens": 0,
"computed_tokens": 812,
"timing": {
"http_received_at": 1761650000.101, "intake_submitted_at": 1761650000.104,
"admit_sent_at": 1761650000.104, "worker_admitted_at": 1761650000.121,
"worker_completed_at": 1761650003.470, "completion_routed_at": 1761650003.471,
"http_responded_at": 1761650003.472,
"receipt_to_submit_ms": 3.0, "submit_to_admit_sent_ms": 0.2,
"admit_sent_to_worker_admit_ms": 17.0, "submit_to_worker_admit_ms": 17.2,
"worker_admit_to_complete_ms": 3349.0, "worker_complete_to_routed_ms": 1.0,
"routed_to_response_ms": 1.0, "worker_complete_to_response_ms": 2.0,
"overhead_ms": 22.0
}
}
}cached_tokens / computed_tokens are the prompt tokens the sequence's last
prefill took from the prefix cache / computed. Timestamps are wall-clock seconds
(server and worker rank 0 share node 0's clock); overhead_ms is everything but
the worker's admit-to-complete time. Each turn also logs one [TURN] … done
line on the server and [SESSION] admit / [SESSION] complete lines on the
worker rank that owns the sequence.
Limits (checked before the session is touched; detail is
{"code", "message"}):
| Limit | Value | Error |
|---|---|---|
| Request body | 32 MiB (declared Content-Length and bytes received) |
413 request_body_too_large |
max_tokens, max_completion_tokens |
the model context length (max_context_length of GET /v1/models) |
400 max_tokens_exceeds_context |
messages |
8192 entries | 400 too_many_messages |
tools |
1024 entries | 400 too_many_tools |
batchgen_debug |
absent or empty; debug switches are set on the server | 400 batchgen_debug_not_accepted |
The batch path has no request-size limit of its own; prompt plus output
beyond the context is still rejected per request by the worker
(400 context_length_exceeded).
Errors: 503 when the worker pool is not serving and 429 under intake
pressure (same gates and Retry-After as POST /v1/batches); 404 / 409 /
400 from the session checks; 422 for a malformed body; 400/413 for the
limits above; 400 with the worker's code for a request the worker rejects
(context_length_exceeded, host_kv_capacity_exceeded); 409 turn_aborted;
503 worker_fatal when the worker pool fails while the turn is pending, and
for every new turn after that until the pool has restarted.
Returns server health status.
Response (healthy): 200 OK
{
"status": "healthy"
}Response (unhealthy): 503 Service Unavailable
POST /v1/inference is disabled. It always returns 410 Gone with
detail.code = "legacy_inference_deprecated" and detail.use_instead = "/v1/batches";
the route is kept only so callers get that explanation instead of a 404. The worker-side
path behind it has been deleted. Use the batch API (/v1/files + /v1/batches) for every
workload.
The BatchGenHttpClient class wraps these REST endpoints. See Client API Reference for full documentation.
| Client Method | REST Endpoint |
|---|---|
upload_file() |
POST /v1/files |
get_file() |
GET /v1/files/{file_id} |
download_file_content() |
GET /v1/files/{file_id}/content |
create_batch() |
POST /v1/batches |
get_batch() |
GET /v1/batches/{batch_id} |
wait_for_batch() |
Polls GET /v1/batches/{batch_id} |
submit_batch() |
Upload → Create → Wait → Download (convenience) |
health_check() |
GET /health |
Quick example:
from batchgen.batchgen_client import BatchGenHttpClient
client = BatchGenHttpClient(base_url="http://localhost:10900")
# One-liner: upload, run, wait, download
batch = client.submit_batch(
input_file_path="requests.jsonl",
output_file_path="results.jsonl",
max_decoding_length=1024,
)
print(f"Done: {batch['status']}, output: {batch['output_file_id']}")
client.close()- Client API Reference — Python client methods and parameters
- Input Format — JSONL input file structure and sampling parameters
- Output Format — Result JSONL structure
- Server Flags — Server configuration options