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

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

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

Same input as [`POST /compress/question-specific/`](/docs/api-reference/compress-qs), but the response is a Server-Sent Events stream instead of a single JSON envelope. Start forwarding compressed tokens to your LLM before the full output is ready.

## Request body

Identical to the [non-streaming endpoint](/docs/api-reference/compress-qs). `latte_v2` accepts every parameter `latte_v1` accepts, plus the three `latte_v2`-only `dynamic*` knobs (rejected on `latte_v1` with `422`).

### Shared parameters (both models)

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `context` | string | yes | The text to compress. |
| `query` | string | yes | The question or topic to preserve relevance for. |
| `compression_model_name` | "latte_v1" \| "latte_v2" | yes | Routes the call. 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 (faster, less precise). |
| `heuristic_chunking` | boolean | no | Pre-chunk with structure-aware heuristics. |
| `disable_placeholders` | boolean | no | Drop the `[...]` markers between kept spans. |

### `latte_v2`-only parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `dynamic` | boolean | no | Picks the compression ratio per-input; overrides `target_compression_ratio` when `true`. 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`. |

## Response

The response uses `Content-Type: text/event-stream`. Each event carries a JSON object:

| Field | Type | Description |
| --- | --- | --- |
| `content` | string | The next chunk of compressed text. Concatenate chunks in order. |
| `done` | boolean | true on the final chunk. The stream closes after it. |
| `error` | string \| null | Set when the stream aborts mid-flight. content is empty in that case. |

## Status codes

| Status | Description |
| --- | --- |
| 200 | Stream opened. Body is `text/event-stream`. |
| 401 | Missing or invalid `X-API-Key`. |
| 422 | Field validation failure. |
| 429 | Rate limit hit. |
| 500 | Upstream error. Stream may include an `error` chunk before closing. |
| 503 | Upstream error. Stream may include an `error` chunk before closing. |

> The streaming endpoint returns events, not the standard `{ success, data, error }` envelope. Handle each chunk's `error` field rather than HTTP status once the stream is open.

```python
import os
from compresr import CompressionClient

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

stream = client.compress_stream(
    context="...long context...",
    query="What is the diameter of JWST's primary mirror?",
    compression_model_name="{{DEFAULT_MODEL}}",
)

buffer = []
for chunk in stream:
    if chunk.error:
        raise RuntimeError(chunk.error)
    buffer.append(chunk.content)
    if chunk.done:
        break

print("".join(buffer))
```

**TypeScript**

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

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

const stream = await client.compressStream({
  context: '...long context...',
  query: "What is the diameter of JWST's primary mirror?",
  compressionModelName: '{{DEFAULT_MODEL}}',
});

const buffer: string[] = [];
for await (const chunk of stream) {
  if (chunk.error) throw new Error(chunk.error);
  buffer.push(chunk.content);
  if (chunk.done) break;
}

console.log(buffer.join(''));
```

**cURL**

```bash
curl -N -X POST https://api.compresr.ai/api/compress/question-specific/stream \
  -H "X-API-Key: $COMPRESR_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Accept: text/event-stream" \
  -d '{
    "context": "...long context...",
    "query": "What is the diameter of JWST'"'"'s primary mirror?",
    "compression_model_name": "{{DEFAULT_MODEL}}"
  }'
```

  response={

```text
data: {"content": "The 6.5-metre", "done": false}

data: {"content": " primary mirror", "done": false}

data: {"content": "", "done": true}
```
