> ## Documentation Index
> Fetch the complete documentation index at: https://docs.orq.ai/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Orq.ai is the control plane for model and MCP traffic: one key reaches the workspace's enabled models, MCP servers, and resources. The setup depends on where the agent runs.
> Hosted assistant (ChatGPT, claude.ai, a hosted sandbox): install nothing. Tell the human to add https://my.orq.ai/v2/mcp as a remote MCP connector and finish the Orq.ai sign-in. With OAuth, send no Authorization header; otherwise send an API key as a bearer token.
> Local coding agent (Claude Code, Codex, Cursor, OpenCode): run `curl -fsSL https://cli.orq.ai/install.sh | sh`. It installs the CLI and runs `orq setup`, which signs in, writes a project-scoped key to `~/.orq/env`, and wires the detected agents through the AI Gateway. It can also add the Orq MCP server and Orq Skills, the workflows for agents, evaluations, and traces: https://docs.orq.ai/ai-studio/integrations/code-assistants/orq-skills.md. Verify with `orq status`.
> Headless or CI: read `ORQ_API_KEY` from the environment; a human creates the key at https://docs.orq.ai/ai-studio/organization/api-keys.md.
> Send model traffic to https://my.orq.ai/v3/router with `Authorization: Bearer $ORQ_API_KEY`; the Anthropic SDK uses https://my.orq.ai/v3/anthropic. New integrations go on `/v3/router`: `/v2/router` stays published for backward compatibility, and `orq.prompt` works only on `/v2/router/chat/completions`.
> Enable a model for the workspace and use its exact `provider/model` id. `POST /v2/workspace-models` enables a model, and a call fails while the workspace has neither credits nor a provider key.
> On `/chat/completions`, a reasoning model rejects `tools` with a `reasoning_effort` other than `none`; `/responses` keeps reasoning.
> On a failure, branch on `error.code` and follow `error.doc_url`; a budget rejection answers 429.

# Batches SDK Reference

> SDK reference for the Batches API, available in Node.js and Python.

## Batches

### List Batches

Lists the batches in the caller's projects, most recent first. Filter by status and endpoint, or page with `after` and `before`; the two cursors are exclusive. Results are scoped to the projects the API key can reach.

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
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)

```

```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
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();
```

**Parameters**

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
    "limit": Optional[int],
    "after": Optional[str],
    "before": Optional[str],
    "search": Optional[str],
    "status": Optional[str],
    "endpoint": Optional[str],
}
```

```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  limit?: number;
  after?: string;
  before?: string;
  search?: string;
  status?: string;
  endpoint?: string;
}
```

**Response**

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
    "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,
}
```

```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  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 is `batch`. 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](https://docs.orq.ai/ai-gateway/features/batches.md) for input file format, supported endpoints, and result files.

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
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)

```

```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
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();
```

**Parameters**

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
    "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
    },
}
```

```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  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
  };
}
```

**Response**

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
    "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,
    },
}
```

```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  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.

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
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)

```

```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
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();
```

**Parameters**

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
    "batch_id": str,  # required
}
```

```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  batchId: string;  // required
}
```

**Response**

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
    "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,
    },
}
```

```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  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 is `cancelled`.

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
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)

```

```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
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();
```

**Parameters**

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
    "batch_id": str,  # required
}
```

```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  batchId: string;  // required
}
```

**Response**

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
    "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,
    },
}
```

```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  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.

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
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)

```

```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
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();
```

**Parameters**

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
    "batch_id": str,  # required
    "file": Optional[Literal["output", "errors"]],
}
```

```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  batchId: string;  // required
  file?: "output" | "errors";
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.