# Retrieve a batch (/docs/api-reference/log-drains/get-log-drain-batch)

One batch of the drain, with every HTTP attempt.

`GET https://api.coss.com/v1/log_drains/{id}/batches/{batch_id}`

Authenticate with your API key as a bearer token (`Authorization: Bearer coss_test_…`). Responses are JSON with snake_case fields; errors are `{ error: { type, code, message, param?, issues?, request_id } }` (https://coss.com/docs/api-reference/errors.md).

## Path parameters

- `id` (string, required): The log drain's id.
- `batch_id` (string, required): The batch's id.

## Example request

TypeScript (the `coss` package):

```ts
import { Coss } from "coss";

const coss = new Coss({
  apiKey: process.env.COSS_API_KEY,
  baseUrl: "https://api.coss.com",
});

const { data, error } = await coss.logDrains.batches.get("drain_01k7c8m4q2f3e9v6t5r1n0p8yz", "drainbat_01k7c8n2b5d7f9h1k3m5p7r9tv");
```

HTTP:

```sh
curl -X GET "https://api.coss.com/v1/log_drains/drain_01k7c8m4q2f3e9v6t5r1n0p8yz/batches/drainbat_01k7c8n2b5d7f9h1k3m5p7r9tv" \
  -H "Authorization: Bearer $COSS_API_KEY"
```

Python:

```python
from coss import Coss

client = Coss()  # api_key= or COSS_API_KEY

client.log_drains.batches.get(
    id="drain_01k7c8m4q2f3e9v6t5r1n0p8yz",
    batch_id="drainbat_01k7c8n2b5d7f9h1k3m5p7r9tv",
)
```

Go:

```go
import (
	"context"

	cossclient "github.com/cosscom/coss-go/client"
	logdrains "github.com/cosscom/coss-go/logdrains"
)

client := cossclient.NewClient() // option.WithAPIKey(…) or COSS_API_KEY

request := &logdrains.GetBatchesRequest{
    ID: "drain_01k7c8m4q2f3e9v6t5r1n0p8yz",
    BatchID: "drainbat_01k7c8n2b5d7f9h1k3m5p7r9tv",
}
client.LogDrains.Batches.Get(
    context.TODO(),
    request,
)
```

Ruby:

```ruby
require "coss"

client = Coss::Client.new # api_key: or COSS_API_KEY

client.log_drains.batches.get(
  id: "drain_01k7c8m4q2f3e9v6t5r1n0p8yz",
  batch_id: "drainbat_01k7c8n2b5d7f9h1k3m5p7r9tv"
)
```

PHP:

```php
<?php

use Coss\Coss;

$client = new Coss(); // apiKey: or COSS_API_KEY

$client->logDrains->batches->get(
    'drain_01k7c8m4q2f3e9v6t5r1n0p8yz',
    'drainbat_01k7c8n2b5d7f9h1k3m5p7r9tv',
);
```

Java:

```java
import com.coss.Coss;
import com.coss.resources.logdrains.batches.requests.GetBatchesRequest;

Coss client = Coss.builder().build(); // .apiKey(…) or COSS_API_KEY

client.logDrains().batches().get(
    "drain_01k7c8m4q2f3e9v6t5r1n0p8yz",
    "drainbat_01k7c8n2b5d7f9h1k3m5p7r9tv",
    GetBatchesRequest
        .builder()
        .build()
);
```

.NET:

```csharp
using Coss;
using Coss.LogDrains;

var client = new CossClient(); // apiKey: or COSS_API_KEY

await client.LogDrains.Batches.GetAsync(
    new GetBatchesRequest
    {
        Id = "drain_01k7c8m4q2f3e9v6t5r1n0p8yz",
        BatchId = "drainbat_01k7c8n2b5d7f9h1k3m5p7r9tv",
    }
);
```

## Response 200

The batch.

- `object` ("log_drain_batch", required)
- `id` (string, required): The batch's id: the `webhook-id` header, the same on every attempt.
- `drain_id` (string, required): The id of the drain it's posted to.
- `status` ("pending" | "succeeded" | "failed", required): `pending`: waiting for its next attempt. `succeeded`: the drain answered with a 2xx status. `failed`: every attempt failed, or the drain was disabled.
- `line_count` (integer, required): Lines in the batch.
- `byte_size` (integer, required): Size of the request body in bytes.
- `attempt_count` (integer, required): How many attempts were made so far.
- `next_attempt_at` (string | null, required, date-time): When the next attempt is due; `null` once the batch is finished.
- `last_status_code` (integer | null, required): The drain's HTTP status on the latest attempt. `null`: no response arrived, or no attempt yet.
- `last_error` (string | null, required): Why the latest attempt failed. `null`: it didn't, or no attempt yet.
- `attempts` (object[], required): Every HTTP attempt of this batch, oldest first.
  - `object` ("log_drain_attempt", required)
  - `id` (string, required)
  - `attempted_at` (string, required, date-time): When the attempt ran.
  - `status_code` (integer | null, required): The drain's HTTP status; `null` when no response arrived.
  - `duration_ms` (integer, required): How long it took, in milliseconds.
  - `error` (string | null, required): Why the attempt failed (e.g. `HTTP 500`, a timeout); `null` on success.
  - `response_excerpt` (string | null, required): At most 1 KB of the response body, as text.
- `created_at` (string, required, date-time)
- `updated_at` (string, required, date-time)

Example:

```json
{
  "object": "log_drain_batch",
  "id": "drainbat_01k7c8n2b5d7f9h1k3m5p7r9tv",
  "drain_id": "drain_01k7c8m4q2f3e9v6t5r1n0p8yz",
  "status": "succeeded",
  "line_count": 42,
  "byte_size": 31870,
  "attempt_count": 1,
  "next_attempt_at": null,
  "last_status_code": 200,
  "last_error": null,
  "attempts": [
    {
      "object": "log_drain_attempt",
      "id": "drainatt_01k7c8n2c9e1g3j5l7n9q1s3uw",
      "attempted_at": "2026-01-15T09:30:01.000Z",
      "status_code": 200,
      "duration_ms": 182,
      "error": null,
      "response_excerpt": "ok"
    }
  ],
  "created_at": "2026-01-15T09:30:00.000Z",
  "updated_at": "2026-01-15T09:30:01.000Z"
}
```

## Errors

- `400`: The `Coss-Version` header names an unknown API version (`invalid_api_version`).
- `401`: The API key is missing, invalid, revoked or expired (`authentication_error`).
- `403`: The API key lacks the permission this endpoint needs (`permission_error`), or its organization is suspended (`organization_suspended`).
- `404`: No log drain with this id exists in the API key's environment, or the drain has no batch with this id (`not_found`).
- `429`: Too many requests with this API key (`rate_limited`), or too many requests with invalid keys from this address (`too_many_failed_authentications`). Retry after `Retry-After` seconds. Successful responses carry `RateLimit-Limit`, `RateLimit-Remaining` and `RateLimit-Reset` (seconds until the limit is fully restored).
- `500`: Unexpected server error (`api_error` / `internal_error`).
- `503`: The API key could not be verified right now; retry (`service_unavailable`).