# https://compresr.ai/docs/api-reference/compress-qs-batch

> Human-readable page: https://compresr.ai/docs/api-reference/compress-qs-batch

`POST /api/compress/question-specific/batch`

Each input has its own `context` and `query`, so you can run a batch where every row is a different document scored against a different question. Useful for RAG pipelines where you compress one chunk per retrieved document.

## Request body

All compression knobs are request-level — they apply to every row in `inputs`. `latte_v2` accepts every parameter `latte_v1` accepts, plus the three `latte_v2`-only `dynamic*` knobs (rejected on `latte_v1` with `422`). See [Models](/docs/api-reference/models) for the canonical reference.

### Shared parameters (both models)

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `inputs` | Array<{context, query}> | yes | Between 1 and 100 items. Each item has a context (string, nullable) and a non-empty query. |
| `compression_model_name` | "latte_v1" \| "latte_v2" | yes | Routes the call. Applies to every row. See [Models](/docs/api-reference/models). |
| `target_compression_ratio` | number | no | Compression strength. See [Models › target_compression_ratio](/docs/api-reference/models#target_compression_ratio). Ignored on `latte_v2` when `dynamic=true`. |
| `coarse` | boolean | no | Paragraph-level compression. Applies to every row. |

### `latte_v2`-only parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `dynamic` | boolean | no | Picks the compression ratio per-input; overrides `target_compression_ratio` when `true`. Applies to every row. Rejected on `latte_v1` with `422`. |
| `dynamic_min_ratio` | number | no | Floor on the chosen Nx ratio when `dynamic=true`. Must be `≥ 1.0`. |
| `dynamic_max_ratio` | number | no | Ceiling on the chosen Nx ratio when `dynamic=true`. Must be `≥ 1.0`. |

Items with `context: null` or `context: ""` return an empty result and are not billed.

> The Python and TypeScript SDKs flatten this into parallel `contexts` and `queries` arrays. See [Python SDK § Batch](/docs/sdks/python#5-batch) and [TypeScript SDK § Batch](/docs/sdks/typescript#5-batch). The REST shape shown above is what goes on the wire when you hit the endpoint directly with cURL or fetch.

## Response

| Field | Type | Description |
| --- | --- | --- |
| `success` | boolean | true when the batch was accepted and processed. |
| `data` | object |  |
| `data.results` | array | Per-row results, in input order. Each entry has the same shape as the single-compression response data. |
| `data.results.original_context` | string |  |
| `data.results.compressed_context` | string |  |
| `data.results.original_tokens` | integer |  |
| `data.results.compressed_tokens` | integer |  |
| `data.results.tokens_saved` | integer |  |
| `data.results.target_compression_ratio` | number \| null |  |
| `data.results.actual_compression_ratio` | number |  |
| `data.results.duration_ms` | integer |  |
| `data.total_original_tokens` | integer | Sum across all rows. |
| `data.total_compressed_tokens` | integer | Sum across all rows. |
| `data.total_tokens_saved` | integer | Sum across all rows. |
| `data.average_compression_ratio` | number | Mean actual_compression_ratio across all rows. |
| `data.count` | integer | Number of rows processed. |

## Status codes

| Status | Description |
| --- | --- |
| 200 | Batch processed. Inspect each row in `data.results`. |
| 401 | Missing or invalid `X-API-Key`. |
| 422 | Validation failed (empty `inputs`, more than 100 rows, empty `query` on a row, ratio out of range). |
| 429 | Rate limit hit. Batch usage counts as one request but full token-volume. |
| 500 | Upstream error. |
| 503 | Upstream error. |

```python
import os
from compresr import CompressionClient

client = CompressionClient(api_key=os.environ["COMPRESR_API_KEY"])

# The Python SDK takes parallel `contexts` and `queries` arrays (not
# REST-style `inputs=[{context, query}, ...]`). The SDK pairs them
# row-by-row internally before hitting this endpoint.
batch = client.compress_batch(
    contexts=[
        "JWST has a 6.5-metre mirror...",
        "Hubble was launched in 1990...",
    ],
    queries=["Mirror size?", "Launch year?"],
    compression_model_name="{{DEFAULT_MODEL}}",
    target_compression_ratio=0.5,
)

for i, row in enumerate(batch.data.results):
    print(f"row {i}: {row.original_tokens} -> {row.compressed_tokens}")
```

**TypeScript**

```typescript
import { CompressionClient } from '@compresr/sdk';

const client = new CompressionClient({
  apiKey: process.env.COMPRESR_API_KEY!,
});

// The TS SDK takes parallel `contexts` and `queries` arrays (not
// REST-style `inputs=[{context, query}, ...]`). The SDK pairs them
// row-by-row internally before hitting this endpoint.
const batch = await client.compressBatch({
  contexts: [
    'JWST has a 6.5-metre mirror...',
    'Hubble was launched in 1990...',
  ],
  queries: ['Mirror size?', 'Launch year?'],
  compressionModelName: '{{DEFAULT_MODEL}}',
  targetCompressionRatio: 0.5,
});

batch.data.results.forEach((row, i) => {
  console.log(`row ${i}: ${row.original_tokens} -> ${row.compressed_tokens}`);
});
```

**cURL**

```bash
curl -X POST https://api.compresr.ai/api/compress/question-specific/batch \
  -H "X-API-Key: $COMPRESR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "inputs": [
      {"context": "JWST has a 6.5-metre mirror...", "query": "Mirror size?"},
      {"context": "Hubble was launched in 1990...", "query": "Launch year?"}
    ],
    "compression_model_name": "{{DEFAULT_MODEL}}",
    "target_compression_ratio": 0.5
  }'
```

  response={

```json
{
  "success": true,
  "data": {
    "results": [
      {
        "original_context": "JWST has a 6.5-metre mirror...",
        "compressed_context": "JWST has a 6.5-metre mirror",
        "original_tokens": 8,
        "compressed_tokens": 6,
        "tokens_saved": 2,
        "target_compression_ratio": 0.5,
        "actual_compression_ratio": 0.25,
        "duration_ms": 188
      }
    ],
    "total_original_tokens": 18,
    "total_compressed_tokens": 11,
    "total_tokens_saved": 7,
    "average_compression_ratio": 0.39,
    "count": 2
  }
}
```
