Batches
List Batches
Lists the batches in the caller’s projects, most recent first. Filter by status and endpoint, or page withafter and before; the two cursors are exclusive. Results are scoped to the projects the API key can reach.
from orq_ai_sdk import Orq
import os
with Orq(
api_key=os.getenv("ORQ_API_KEY"),
) as orq:
res = orq.batches.list()
# Handle response
print(res)
import { Orq } from "@orq-ai/node";
const orq = new Orq({
apiKey: process.env["ORQ_API_KEY"] ?? "",
});
async function run() {
const result = await orq.batches.list();
console.log(result);
}
run();
Show Parameters
Show Parameters
{
"limit": Optional[int],
"after": Optional[str],
"before": Optional[str],
"search": Optional[str],
"status": Optional[str],
"endpoint": Optional[str],
}
{
limit?: number;
after?: string;
before?: string;
search?: string;
status?: string;
endpoint?: string;
}
Show Response
Show Response
{
"data": [{
"cancelled_at": Optional[int],
"cancelling_at": Optional[int],
"completed_at": Optional[int],
"completion_window": str,
"created_at": int,
"endpoint": str,
"error_file_id": Optional[str],
"errors": { # optional
"data": [{
"code": str,
"line": Optional[int],
"message": str,
"param": Optional[str],
}],
"object": str,
},
"expired_at": Optional[int],
"expires_at": Optional[int],
"failed_at": Optional[int],
"finalizing_at": Optional[int],
"id": str,
"in_progress_at": Optional[int],
"input_file_id": str,
"metadata": Dict[str, str], # optional
"model": Optional[str],
"object": str,
"output_file_id": Optional[str],
"request_counts": {
"completed": int,
"failed": int,
"total": int,
},
"status": Literal["validating", "in_progress", "finalizing", "completed", "failed", "expired", "cancelling", "cancelled"],
"usage": { # optional
"input_tokens": int,
"input_tokens_details": {
"cached_tokens": int,
},
"output_tokens": int,
"output_tokens_details": {
"reasoning_tokens": int,
},
"total_tokens": int,
},
}],
"first_id": Optional[str],
"has_more": bool,
"last_id": Optional[str],
"object": str,
}
{
data: {
cancelledAt?: number;
cancellingAt?: number;
completedAt?: number;
completionWindow: string;
createdAt: number;
endpoint: string;
errorFileId?: string;
errors?: {
data: {
code: string;
line?: number;
message: string;
param?: string;
}[];
object: string;
};
expiredAt?: number;
expiresAt?: number;
failedAt?: number;
finalizingAt?: number;
id: string;
inProgressAt?: number;
inputFileId: string;
metadata?: Record<string, string>;
model?: string;
object: string;
outputFileId?: string;
requestCounts: {
completed: number;
failed: number;
total: number;
};
status: "validating" | "in_progress" | "finalizing" | "completed" | "failed" | "expired" | "cancelling" | "cancelled";
usage?: {
inputTokens: number;
inputTokensDetails: {
cachedTokens: number;
};
outputTokens: number;
outputTokensDetails: {
reasoningTokens: number;
};
totalTokens: number;
};
}[];
firstId?: string;
hasMore: boolean;
lastId?: string;
object: string;
}
Create a Batche
Creates a batch from an uploaded JSONL file whose purpose isbatch. Each line is sent to endpoint with its own request body, without the throughput limits of real-time traffic. Provider batches run through the provider’s batch service at its batch rates; /v3/router/decisions batches run on the deployment’s workers. See the Batches guide for input file format, supported endpoints, and result files.
from orq_ai_sdk import Orq
import os
with Orq(
api_key=os.getenv("ORQ_API_KEY"),
) as orq:
res = orq.batches.create(completion_window="24h", endpoint="/v1/chat/completions", input_file_id="file-abc123", metadata={
"job": "nightly-eval",
})
# Handle response
print(res)
import { Orq } from "@orq-ai/node";
const orq = new Orq({
apiKey: process.env["ORQ_API_KEY"] ?? "",
});
async function run() {
const result = await orq.batches.create({
completionWindow: "24h",
endpoint: "/v1/chat/completions",
inputFileId: "file-abc123",
metadata: {
"job": "nightly-eval",
},
});
console.log(result);
}
run();
Show Parameters
Show Parameters
{
"completion_window": Literal["24h"], # required
"endpoint": Literal["/v1/responses", "/v1/chat/completions", "/v1/embeddings", "/v1/completions", "/v1/moderations", "/v3/router/decisions"], # required
"input_file_id": str, # required
"metadata": Dict[str, str], # optional
"output_expires_after": { # optional
"anchor": Optional[Literal["created_at"]],
"seconds": int, # required
},
}
{
completionWindow: "24h"; // required
endpoint: "/v1/responses" | "/v1/chat/completions" | "/v1/embeddings" | "/v1/completions" | "/v1/moderations" | "/v3/router/decisions"; // required
inputFileId: string; // required
metadata?: Record<string, string>;
outputExpiresAfter?: {
anchor?: "created_at";
seconds: number; // required
};
}
Show Response
Show Response
{
"cancelled_at": Optional[int],
"cancelling_at": Optional[int],
"completed_at": Optional[int],
"completion_window": str,
"created_at": int,
"endpoint": str,
"error_file_id": Optional[str],
"errors": { # optional
"data": [{
"code": str,
"line": Optional[int],
"message": str,
"param": Optional[str],
}],
"object": str,
},
"expired_at": Optional[int],
"expires_at": Optional[int],
"failed_at": Optional[int],
"finalizing_at": Optional[int],
"id": str,
"in_progress_at": Optional[int],
"input_file_id": str,
"metadata": Dict[str, str], # optional
"model": Optional[str],
"object": str,
"output_file_id": Optional[str],
"request_counts": {
"completed": int,
"failed": int,
"total": int,
},
"status": Literal["validating", "in_progress", "finalizing", "completed", "failed", "expired", "cancelling", "cancelled"],
"usage": { # optional
"input_tokens": int,
"input_tokens_details": {
"cached_tokens": int,
},
"output_tokens": int,
"output_tokens_details": {
"reasoning_tokens": int,
},
"total_tokens": int,
},
}
{
cancelledAt?: number;
cancellingAt?: number;
completedAt?: number;
completionWindow: string;
createdAt: number;
endpoint: string;
errorFileId?: string;
errors?: {
data: {
code: string;
line?: number;
message: string;
param?: string;
}[];
object: string;
};
expiredAt?: number;
expiresAt?: number;
failedAt?: number;
finalizingAt?: number;
id: string;
inProgressAt?: number;
inputFileId: string;
metadata?: Record<string, string>;
model?: string;
object: string;
outputFileId?: string;
requestCounts: {
completed: number;
failed: number;
total: number;
};
status: "validating" | "in_progress" | "finalizing" | "completed" | "failed" | "expired" | "cancelling" | "cancelled";
usage?: {
inputTokens: number;
inputTokensDetails: {
cachedTokens: number;
};
outputTokens: number;
outputTokensDetails: {
reasoningTokens: number;
};
totalTokens: number;
};
}
Retrieve a Batche
Retrieves one batch, including its status, per-line request counts, and the output and error file IDs once they exist.from orq_ai_sdk import Orq
import os
with Orq(
api_key=os.getenv("ORQ_API_KEY"),
) as orq:
res = orq.batches.retrieve(batch_id="<id>")
# Handle response
print(res)
import { Orq } from "@orq-ai/node";
const orq = new Orq({
apiKey: process.env["ORQ_API_KEY"] ?? "",
});
async function run() {
const result = await orq.batches.retrieve({
batchId: "<id>",
});
console.log(result);
}
run();
Show Parameters
Show Parameters
{
"batch_id": str, # required
}
{
batchId: string; // required
}
Show Response
Show Response
{
"cancelled_at": Optional[int],
"cancelling_at": Optional[int],
"completed_at": Optional[int],
"completion_window": str,
"created_at": int,
"endpoint": str,
"error_file_id": Optional[str],
"errors": { # optional
"data": [{
"code": str,
"line": Optional[int],
"message": str,
"param": Optional[str],
}],
"object": str,
},
"expired_at": Optional[int],
"expires_at": Optional[int],
"failed_at": Optional[int],
"finalizing_at": Optional[int],
"id": str,
"in_progress_at": Optional[int],
"input_file_id": str,
"metadata": Dict[str, str], # optional
"model": Optional[str],
"object": str,
"output_file_id": Optional[str],
"request_counts": {
"completed": int,
"failed": int,
"total": int,
},
"status": Literal["validating", "in_progress", "finalizing", "completed", "failed", "expired", "cancelling", "cancelled"],
"usage": { # optional
"input_tokens": int,
"input_tokens_details": {
"cached_tokens": int,
},
"output_tokens": int,
"output_tokens_details": {
"reasoning_tokens": int,
},
"total_tokens": int,
},
}
{
cancelledAt?: number;
cancellingAt?: number;
completedAt?: number;
completionWindow: string;
createdAt: number;
endpoint: string;
errorFileId?: string;
errors?: {
data: {
code: string;
line?: number;
message: string;
param?: string;
}[];
object: string;
};
expiredAt?: number;
expiresAt?: number;
failedAt?: number;
finalizingAt?: number;
id: string;
inProgressAt?: number;
inputFileId: string;
metadata?: Record<string, string>;
model?: string;
object: string;
outputFileId?: string;
requestCounts: {
completed: number;
failed: number;
total: number;
};
status: "validating" | "in_progress" | "finalizing" | "completed" | "failed" | "expired" | "cancelling" | "cancelled";
usage?: {
inputTokens: number;
inputTokensDetails: {
cachedTokens: number;
};
outputTokens: number;
outputTokensDetails: {
reasoningTokens: number;
};
totalTokens: number;
};
}
Cancel a Batche
Requests cancellation of a running batch and returns it with the status it holds at that moment. A batch that already reached a terminal status is returned unchanged. Poll the batch until the status iscancelled.
from orq_ai_sdk import Orq
import os
with Orq(
api_key=os.getenv("ORQ_API_KEY"),
) as orq:
res = orq.batches.cancel(batch_id="<id>")
# Handle response
print(res)
import { Orq } from "@orq-ai/node";
const orq = new Orq({
apiKey: process.env["ORQ_API_KEY"] ?? "",
});
async function run() {
const result = await orq.batches.cancel({
batchId: "<id>",
});
console.log(result);
}
run();
Show Parameters
Show Parameters
{
"batch_id": str, # required
}
{
batchId: string; // required
}
Show Response
Show Response
{
"cancelled_at": Optional[int],
"cancelling_at": Optional[int],
"completed_at": Optional[int],
"completion_window": str,
"created_at": int,
"endpoint": str,
"error_file_id": Optional[str],
"errors": { # optional
"data": [{
"code": str,
"line": Optional[int],
"message": str,
"param": Optional[str],
}],
"object": str,
},
"expired_at": Optional[int],
"expires_at": Optional[int],
"failed_at": Optional[int],
"finalizing_at": Optional[int],
"id": str,
"in_progress_at": Optional[int],
"input_file_id": str,
"metadata": Dict[str, str], # optional
"model": Optional[str],
"object": str,
"output_file_id": Optional[str],
"request_counts": {
"completed": int,
"failed": int,
"total": int,
},
"status": Literal["validating", "in_progress", "finalizing", "completed", "failed", "expired", "cancelling", "cancelled"],
"usage": { # optional
"input_tokens": int,
"input_tokens_details": {
"cached_tokens": int,
},
"output_tokens": int,
"output_tokens_details": {
"reasoning_tokens": int,
},
"total_tokens": int,
},
}
{
cancelledAt?: number;
cancellingAt?: number;
completedAt?: number;
completionWindow: string;
createdAt: number;
endpoint: string;
errorFileId?: string;
errors?: {
data: {
code: string;
line?: number;
message: string;
param?: string;
}[];
object: string;
};
expiredAt?: number;
expiresAt?: number;
failedAt?: number;
finalizingAt?: number;
id: string;
inProgressAt?: number;
inputFileId: string;
metadata?: Record<string, string>;
model?: string;
object: string;
outputFileId?: string;
requestCounts: {
completed: number;
failed: number;
total: number;
};
status: "validating" | "in_progress" | "finalizing" | "completed" | "failed" | "expired" | "cancelling" | "cancelled";
usage?: {
inputTokens: number;
inputTokensDetails: {
cachedTokens: number;
};
outputTokens: number;
outputTokensDetails: {
reasoningTokens: number;
};
totalTokens: number;
};
}
Download Results
Downloads the JSONL result file of a batch that reached a terminal status.file=output returns the successful responses, file=errors the per-line failures that have an error file. Each line follows the OpenAI batch result format.
from orq_ai_sdk import Orq
import os
with Orq(
api_key=os.getenv("ORQ_API_KEY"),
) as orq:
res = orq.batches.download_results(batch_id="<id>")
# Handle response
print(res)
import { Orq } from "@orq-ai/node";
const orq = new Orq({
apiKey: process.env["ORQ_API_KEY"] ?? "",
});
async function run() {
const result = await orq.batches.downloadResults({
batchId: "<id>",
});
console.log(result);
}
run();
Show Parameters
Show Parameters
{
"batch_id": str, # required
"file": Optional[Literal["output", "errors"]],
}
{
batchId: string; // required
file?: "output" | "errors";
}