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

# Batch

> Submit, list, poll, and delete asynchronous batches of inference requests. See https://openrouter.ai/docs/batch-quickstart.

## Overview

Submit, list, poll, and delete asynchronous batches of inference requests. See [https://openrouter.ai/docs/batch-quickstart](https://openrouter.ai/docs/batch-quickstart).

### Available Operations

* [List](#list) - List batches
* [CreateBatches](#createbatches) - Create a batch
* [Delete](#delete) - Delete a batch
* [GetBatches](#getbatches) - Get a batch

## List

Lists batches in the workspace of the authenticating API key, newest first. To fetch the next page, pass the previous page's `last_id` as `after`. List items omit `results`. Use `GET /batches/{id}` to get them. See the [Batch API Quickstart](https://openrouter.ai/docs/batch-quickstart).

### Example Usage

```go theme={null}
package main

import(
	"context"
	"os"
	openrouter "github.com/OpenRouterTeam/go-sdk"
	"log"
)

func main() {
    ctx := context.Background()

    s := openrouter.New(
        openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
    )

    res, err := s.Batch.List(ctx, nil)
    if err != nil {
        log.Fatal(err)
    }
    if res != nil {
        for {
            // handle items

            res, err = res.Next()

            if err != nil {
                // handle error
            }

            if res == nil {
                break
            }
        }
    }
}
```

### Parameters

| Parameter | Type | Required | Description |
| - | - | - | - |
| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy\_check\_mark: | The context to use for the request. |
| `request` | [operations.ListBatchesRequest](../../models/operations/listbatchesrequest.mdx) | :heavy\_check\_mark: | The request object to use for the request. |
| `opts` | \[][operations.Option](../../models/operations/option.mdx) | :heavy\_minus\_sign: | The options for this request. |

### Response

**[\*operations.ListBatchesResponse](../../models/operations/listbatchesresponse.mdx), error**

### Errors

| Error Type | Status Code | Content Type |
| - | - | - |
| sdkerrors.BatchErrorResponse | 400, 401, 429 | application/json |
| sdkerrors.BatchErrorResponse | 500, 502 | application/json |
| sdkerrors.APIError | 4XX, 5XX | \*/\* |

## CreateBatches

Creates a batch of requests that run asynchronously against a single endpoint (`/v1/chat/completions`, `/v1/responses`, `/v1/messages`, `/v1/embeddings`). Returns `202` with `status: "validating"`. Poll `GET /batches/{id}` for progress and results. See the [Batch API Quickstart](https://openrouter.ai/docs/batch-quickstart).

### Example Usage: chatCompletions

```go theme={null}
package main

import(
	"context"
	"os"
	openrouter "github.com/OpenRouterTeam/go-sdk"
	"github.com/OpenRouterTeam/go-sdk/models/components"
	"log"
)

func main() {
    ctx := context.Background()

    s := openrouter.New(
        openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
    )

    res, err := s.Batch.CreateBatches(ctx, components.BatchSubmitBody{
        Endpoint: components.EndpointRootV1ChatCompletions,
        Model: "openai/gpt-4o",
        Requests: []components.Request{
            components.Request{
                Body: map[string]any{
                    "messages": []any{
                        map[string]any{
                            "content": "Summarize ...",
                            "role": "user",
                        },
                    },
                    "model": "openai/gpt-4o",
                },
                CustomID: "req-0001",
            },
        },
    })
    if err != nil {
        log.Fatal(err)
    }
    if res != nil {
        // handle response
    }
}
```

### Example Usage: messages

```go theme={null}
package main

import(
	"context"
	"os"
	openrouter "github.com/OpenRouterTeam/go-sdk"
	"github.com/OpenRouterTeam/go-sdk/models/components"
	"log"
)

func main() {
    ctx := context.Background()

    s := openrouter.New(
        openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
    )

    res, err := s.Batch.CreateBatches(ctx, components.BatchSubmitBody{
        Endpoint: components.EndpointRootV1Messages,
        Model: "openai/gpt-5-nano",
        Requests: []components.Request{
            components.Request{
                Body: map[string]any{
                    "max_tokens": 1024,
                    "messages": []any{
                        map[string]any{
                            "content": "Summarize ...",
                            "role": "user",
                        },
                    },
                    "model": "openai/gpt-5-nano",
                },
                CustomID: "req-0001",
            },
        },
    })
    if err != nil {
        log.Fatal(err)
    }
    if res != nil {
        // handle response
    }
}
```

### Example Usage: providerPinned

```go theme={null}
package main

import(
	"context"
	"os"
	openrouter "github.com/OpenRouterTeam/go-sdk"
	"github.com/OpenRouterTeam/go-sdk/models/components"
	"log"
)

func main() {
    ctx := context.Background()

    s := openrouter.New(
        openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
    )

    res, err := s.Batch.CreateBatches(ctx, components.BatchSubmitBody{
        Endpoint: components.EndpointRootV1ChatCompletions,
        Model: "google/gemini-3.6-flash",
        Requests: []components.Request{
            components.Request{
                Body: map[string]any{
                    "messages": []any{
                        map[string]any{
                            "content": "Summarize ...",
                            "role": "user",
                        },
                    },
                    "model": "google/gemini-3.6-flash",
                },
                CustomID: "req-0001",
            },
        },
    })
    if err != nil {
        log.Fatal(err)
    }
    if res != nil {
        // handle response
    }
}
```

### Example Usage: responses

```go theme={null}
package main

import(
	"context"
	"os"
	openrouter "github.com/OpenRouterTeam/go-sdk"
	"github.com/OpenRouterTeam/go-sdk/models/components"
	"log"
)

func main() {
    ctx := context.Background()

    s := openrouter.New(
        openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
    )

    res, err := s.Batch.CreateBatches(ctx, components.BatchSubmitBody{
        Endpoint: components.EndpointRootV1Responses,
        Model: "openai/gpt-4o",
        Requests: []components.Request{
            components.Request{
                Body: map[string]any{
                    "input": []any{
                        map[string]any{
                            "content": []any{
                                map[string]any{
                                    "text": "Summarize ...",
                                    "type": "input_text",
                                },
                            },
                            "role": "user",
                        },
                    },
                    "model": "openai/gpt-4o",
                },
                CustomID: "req-0001",
            },
        },
    })
    if err != nil {
        log.Fatal(err)
    }
    if res != nil {
        // handle response
    }
}
```

### Parameters

| Parameter | Type | Required | Description |
| - | - | - | - |
| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy\_check\_mark: | The context to use for the request. |
| `request` | [components.BatchSubmitBody](../../models/components/batchsubmitbody.mdx) | :heavy\_check\_mark: | The request object to use for the request. |
| `opts` | \[][operations.Option](../../models/operations/option.mdx) | :heavy\_minus\_sign: | The options for this request. |

### Response

**[\*components.BatchObject](../../models/components/batchobject.mdx), error**

### Errors

| Error Type | Status Code | Content Type |
| - | - | - |
| sdkerrors.BatchErrorResponse | 400, 401, 402, 403, 404, 413, 422, 429 | application/json |
| sdkerrors.BatchErrorResponse | 500, 502 | application/json |
| sdkerrors.APIError | 4XX, 5XX | \*/\* |

## Delete

Deletes a batch in a terminal status (`completed`, `failed`, `expired`, or `cancelled`) and its stored requests and results. Batches still in progress return `409`. Billing and usage records are kept. See the [Batch API Quickstart](https://openrouter.ai/docs/batch-quickstart).

### Example Usage

```go theme={null}
package main

import(
	"context"
	"os"
	openrouter "github.com/OpenRouterTeam/go-sdk"
	"log"
)

func main() {
    ctx := context.Background()

    s := openrouter.New(
        openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
    )

    res, err := s.Batch.Delete(ctx, "batch_abc123")
    if err != nil {
        log.Fatal(err)
    }
    if res != nil {
        // handle response
    }
}
```

### Parameters

| Parameter | Type | Required | Description | Example |
| - | - | - | - | - |
| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy\_check\_mark: | The context to use for the request. | |
| `id` | `string` | :heavy\_check\_mark: | The batch job id returned from submit. | batch\_abc123 |
| `opts` | \[][operations.Option](../../models/operations/option.mdx) | :heavy\_minus\_sign: | The options for this request. | |

### Response

**[\*components.BatchDeletedObject](../../models/components/batchdeletedobject.mdx), error**

### Errors

| Error Type | Status Code | Content Type |
| - | - | - |
| sdkerrors.BatchErrorResponse | 401, 404, 409, 429 | application/json |
| sdkerrors.BatchErrorResponse | 500, 502 | application/json |
| sdkerrors.APIError | 4XX, 5XX | \*/\* |

## GetBatches

Returns a batch with its status and request counts. Batches in a terminal status include `results`. Failed batches report the reason in `error.message`. See the [Batch API Quickstart](https://openrouter.ai/docs/batch-quickstart).

### Example Usage

```go theme={null}
package main

import(
	"context"
	"os"
	openrouter "github.com/OpenRouterTeam/go-sdk"
	"log"
)

func main() {
    ctx := context.Background()

    s := openrouter.New(
        openrouter.WithSecurity(os.Getenv("OPENROUTER_API_KEY")),
    )

    res, err := s.Batch.GetBatches(ctx, "batch_abc123")
    if err != nil {
        log.Fatal(err)
    }
    if res != nil {
        // handle response
    }
}
```

### Parameters

| Parameter | Type | Required | Description | Example |
| - | - | - | - | - |
| `ctx` | [context.Context](https://pkg.go.dev/context#Context) | :heavy\_check\_mark: | The context to use for the request. | |
| `id` | `string` | :heavy\_check\_mark: | The batch job id returned from submit. | batch\_abc123 |
| `opts` | \[][operations.Option](../../models/operations/option.mdx) | :heavy\_minus\_sign: | The options for this request. | |

### Response

**[\*components.BatchObject](../../models/components/batchobject.mdx), error**

### Errors

| Error Type | Status Code | Content Type |
| - | - | - |
| sdkerrors.BatchPaymentRequiredResponseError | 402 | application/json |
| sdkerrors.BatchErrorResponse | 401, 404, 429 | application/json |
| sdkerrors.BatchErrorResponse | 500, 502 | application/json |
| sdkerrors.APIError | 4XX, 5XX | \*/\* |
