> This page is for version v1 API.
> For other versions, use one of these documentation indexes:
> - v2 API (default): https://docs.cohere.com/v2/llms.txt
> - v1 API: https://docs.cohere.com/v1/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.cohere.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.cohere.com/_mcp/server.

# Create a batch

POST https://api.cohere.com/v2/batches
Content-Type: application/json

Creates and executes a batch from an uploaded dataset of requests

Reference: https://docs.cohere.com/reference/create-batch

## Authentication

- `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer <token>`, where token is your auth token.

## Request

### Headers

- `X-Client-Name` (string, optional) — The name of the project that is making the request.

### Body (application/json)

This endpoint expects a Batch.

- `name` (string, required) — Batch name (e.g. `foobar`).
- `input_dataset_id` (string, required) — ID of the dataset the batch reads inputs from.
- `model` (string, required) — The name of the model the batch uses.
- `id` (string, optional) — read-only. Batch ID.
- `creator_id` (string, optional) — read-only. User ID of the creator.
- `org_id` (string, optional) — read-only. Organization ID.
- `status` (enum, optional, default: BATCH_STATUS_UNSPECIFIED) — read-only. Current stage in the life-cycle of the batch.
  - Allowed values: `BATCH_STATUS_UNSPECIFIED`, `BATCH_STATUS_QUEUED`, `BATCH_STATUS_IN_PROGRESS`, `BATCH_STATUS_CANCELING`, `BATCH_STATUS_COMPLETED`, `BATCH_STATUS_FAILED`, `BATCH_STATUS_CANCELED`
- `created_at` (string, optional) — read-only. Creation timestamp.
- `updated_at` (string, optional) — read-only. Latest update timestamp.
- `output_dataset_id` (string, optional)
- `input_tokens` (string, optional) — read-only. The total number of input tokens in the batch.
- `output_tokens` (string, optional) — read-only. The total number of output tokens in the batch.
- `num_records` (integer, optional) — read-only. The total number of records in the batch.
- `num_successful_records` (integer, optional) — read-only. The current number of successful records in the batch.
- `num_failed_records` (integer, optional) — read-only. The current number of failed records in the batch.
- `status_reason` (string, optional) — read-only. More details about the reason for the status of a batch job.

## Response

### 200

A successful response.

- `batch` (Batch, required) — Information about the batch.

## Errors

### 400 Bad Request Error

Bad Request

- `message` (string, optional) — A developer-facing error message.

### 401 Unauthorized Error

Unauthorized

- `message` (string, optional) — A developer-facing error message.

### 403 Forbidden Error

Forbidden

- `message` (string, optional) — A developer-facing error message.

### 404 Not Found Error

Not Found

- `message` (string, optional) — A developer-facing error message.

### 500 Internal Server Error

Internal Server Error

- `message` (string, optional) — A developer-facing error message.

### 503 Service Unavailable Error

Status Service Unavailable

- `message` (string, optional) — A developer-facing error message.

## Types

### Batch

This resource represents a batch job.

- `name` (string, required) — Batch name (e.g. `foobar`).
- `input_dataset_id` (string, required) — ID of the dataset the batch reads inputs from.
- `model` (string, required) — The name of the model the batch uses.
- `id` (string, optional) — read-only. Batch ID.
- `creator_id` (string, optional) — read-only. User ID of the creator.
- `org_id` (string, optional) — read-only. Organization ID.
- `status` (enum, optional, default: BATCH_STATUS_UNSPECIFIED) — read-only. Current stage in the life-cycle of the batch.
  - Allowed values: `BATCH_STATUS_UNSPECIFIED`, `BATCH_STATUS_QUEUED`, `BATCH_STATUS_IN_PROGRESS`, `BATCH_STATUS_CANCELING`, `BATCH_STATUS_COMPLETED`, `BATCH_STATUS_FAILED`, `BATCH_STATUS_CANCELED`
- `created_at` (string, optional) — read-only. Creation timestamp.
- `updated_at` (string, optional) — read-only. Latest update timestamp.
- `output_dataset_id` (string, optional)
- `input_tokens` (string, optional) — read-only. The total number of input tokens in the batch.
- `output_tokens` (string, optional) — read-only. The total number of output tokens in the batch.
- `num_records` (integer, optional) — read-only. The total number of records in the batch.
- `num_successful_records` (integer, optional) — read-only. The current number of successful records in the batch.
- `num_failed_records` (integer, optional) — read-only. The current number of failed records in the batch.
- `status_reason` (string, optional) — read-only. More details about the reason for the status of a batch job.

## Examples

**Request**

```json
{
  "name": "Customer Support Batch Job",
  "input_dataset_id": "ds_8f7a6b3c9d2e4f1a",
  "model": "command-xlarge-nightly"
}
```

**Response**

```json
{
  "batch": {
    "name": "Customer Support Batch Job",
    "input_dataset_id": "ds_8f7a6b3c9d2e4f1a",
    "model": "command-xlarge-nightly",
    "id": "batch_123e4567-e89b-12d3-a456-426614174000",
    "creator_id": "user_9876543210abcdef",
    "org_id": "org_abcdef1234567890",
    "status": "BATCH_STATUS_IN_PROGRESS",
    "created_at": "2024-01-15T09:30:00Z",
    "updated_at": "2024-01-15T10:00:00Z",
    "output_dataset_id": "ds_9a8b7c6d5e4f3a2b",
    "input_tokens": "150000",
    "output_tokens": "145000",
    "num_records": 5000,
    "num_successful_records": 4980,
    "num_failed_records": 20,
    "status_reason": "Batch processing is ongoing with minor failures."
  }
}
```

**SDK Code**

```python Default
import cohere

co = cohere.ClientV2()

batch_job = co.batches.create(
    name="<batch_job_name>",
    input_dataset_id="<input_dataset_id>",
    model="<model_name>",
)

```

```typescript Default
import { CohereClient } from 'cohere-ai';

const cohere = new CohereClient({});

(async () => {
  const batchJob = await cohere.batches.create({
    name: '<my_job_name>',
    inputDatasetId: '<input_dataset_id>',
    model: '<model_name>',
  });

  console.log(batchJob);
})();

```

```go Default
package main

import (
	"context"
	"log"
	"os"

	cohere "github.com/cohere-ai/cohere-go/v2"
	client "github.com/cohere-ai/cohere-go/v2/client"
)

func main() {
	co := client.NewClient(client.WithToken(os.Getenv("CO_API_KEY")))

	resp, err := co.Batches.Create(
		context.TODO(),
		&cohere.Batch{
			Name:           "<batch_job_name>",
			InputDatasetId: "<input_dataset_id>",
			Model:          "<model_name>",
		},
	)

	if err != nil {
		log.Fatal(err)
	}

	log.Printf("%+v", resp)
}

```

```java Default
/* (C)2024 */
import com.cohere.api.Cohere;
import com.cohere.api.resources.batches.types.CreateBatchResponse;
import com.cohere.api.resources.batches.types.Batch;

public class BatchPost {
  public static void main(String[] args) {
    Cohere cohere = Cohere.builder().clientName("snippet").build();

    CreateBatchResponse response =
        cohere
            .batches()
            .create(
                Batch.builder()
                    .name("<batch_job_name>")
                    .inputDatasetId("<input_dataset_id>")
                    .model("<model_name>")
                    .build());

    System.out.println(response);
  }
}

```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.cohere.com/v2/batches")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["X-Client-Name"] = 'my-cool-project'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"name\": \"Customer Support Batch Job\",\n  \"input_dataset_id\": \"ds_8f7a6b3c9d2e4f1a\",\n  \"model\": \"command-xlarge-nightly\"\n}"

response = http.request(request)
puts response.read_body
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.cohere.com/v2/batches', [
  'body' => '{
  "name": "Customer Support Batch Job",
  "input_dataset_id": "ds_8f7a6b3c9d2e4f1a",
  "model": "command-xlarge-nightly"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
    'X-Client-Name' => 'my-cool-project',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.cohere.com/v2/batches");
var request = new RestRequest(Method.POST);
request.AddHeader("X-Client-Name", "my-cool-project");
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"name\": \"Customer Support Batch Job\",\n  \"input_dataset_id\": \"ds_8f7a6b3c9d2e4f1a\",\n  \"model\": \"command-xlarge-nightly\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "X-Client-Name": "my-cool-project",
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "name": "Customer Support Batch Job",
  "input_dataset_id": "ds_8f7a6b3c9d2e4f1a",
  "model": "command-xlarge-nightly"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.cohere.com/v2/batches")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```