---
title: "How does Coolhand handle cancelled or abandoned streaming responses?"
answer: "Coolhand logs cut-off streams with stream_incomplete set to true and preserves the partial response body. Because aborted streams skew benchmarks, Coolhand records latency_ms as null. Token metrics and costs are also set to null unless the stream progressed far enough to receive the provider's terminal usage chunk before disconnection."
category: "Logs \u0026 API"
tags: ["streaming","logs","api","latency","tokens","monitoring"]
published: 2026-11-30T05:46:23Z
updated: 2026-11-29T14:36:27Z
canonical_url: https://coolhandlabs.com/help/how-does-coolhand-handle-cancelled-or-abandoned-streaming-responses
index_url: https://coolhandlabs.com/help.md
---

# How does Coolhand handle cancelled or abandoned streaming responses?

Coolhand logs cut-off streams with stream_incomplete set to true and preserves the partial response body. Because aborted streams skew benchmarks, Coolhand records latency_ms as null. Token metrics and costs are also set to null unless the stream progressed far enough to receive the provider's terminal usage chunk before disconnection.

When an application streams responses from an LLM provider, the client may stop reading the stream before generation finishes. Common scenarios include:

- Breaking out of an iteration loop once sufficient tokens have been received.
- Triggering a client-side abort signal.
- Explicitly closing the response stream or cancelling an async generator task.
- Experiencing a mid-stream network drop, reset, or client timeout.
- SDK behavior that breaks at a completion delimiter (such as `data: [DONE]`) without draining the underlying network socket.

In older monitoring setups, abandoned streams were either silently dropped or recorded with incomplete information that corrupted aggregate metrics. Coolhand instead logs whatever partial output was received, marks the request as incomplete, and adjusts performance and billing figures to protect analytics integrity.

---

## What happens when a stream is abandoned

When your application code stops consuming a stream early, the Coolhand SDK captures the partial response body received up to the moment of cancellation. The captured log entry is flagged with:

```json
"stream_incomplete": true
```

The partial text returned so far is preserved in the log's `output` field (as well as inside `raw_request`). This ensures you maintain full visibility into what the model generated before the stream was halted, which is critical for debugging cancellations and analyzing user experience.

If a stream completes naturally and the iterator is exhausted, the log is recorded with `stream_incomplete: false` (or omitted in older payload versions).

---

## Why latency and token metrics are set to null

Incomplete streams are not comparable to normally completed requests. To prevent distorted statistics across dashboards and API rollups, Coolhand overrides specific metrics during ingestion:

### 1. Latency is set to `null`
The duration of an abandoned stream reflects how long your application chose to wait before cutting the connection, not how long the model required to complete its generation. If an application cuts off a request after 400 ms, recording 400 ms as the request's `latency_ms` would artificially drag down your p50, p95, and p99 latency figures. Coolhand explicitly records `latency_ms` as `null` for all incomplete streams.

### 2. Token counts and costs are set to `null`
Most LLM providers emit cumulative usage statistics only in the final terminal chunk of a stream. Intermediate chunks contain partial text deltas rather than billable counts.

If a connection drops midway, any partial token count (such as Anthropic's initial `message_start` input count or incremental Gemini chunks) does not reflect what the provider ultimately billed for the turn. Rather than recording a misleading partial count that under-reports token consumption, Coolhand sets token fields to `null`:

- `input_tokens`
- `output_tokens`
- `cached_input_tokens`
- `cache_creation_input_tokens` (including 5-minute and 1-hour tiers)
- `reasoning_tokens`
- `audio_input_tokens`

Because the token fields are `null`, the calculated `cost` for the request log is also recorded as `null`.

---

## The exception: terminal usage chunks

The only circumstance under which token counts survive an incomplete stream is when the stream progressed far enough to receive the provider's final usage frame before the connection was severed.

For example, when using OpenAI or OpenAI-compatible endpoints with streaming usage options:

```python
response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Write a short summary."}],
    stream=True,
    stream_options={"include_usage": True}
)
```

If the stream receives the final chunk containing the provider's `usage` payload before the client terminates the connection, Coolhand extracts those usage numbers. The log retains its verified token figures and calculates the corresponding `cost`. However, `latency_ms` remains `null` because the full turn lifecycle was interrupted.

---

## Impact on templates and evaluations

To prevent incomplete streams from skewing operational benchmarks:

- **Template performance rollups:** Aggregations of completed requests and cache-miss metrics exclude incomplete streams so that average latency and average token usage represent completed generations.
- **Automated evaluations:** Coolhand's automated evaluation system assesses prompt outputs for quality and sentiment. Evals are never scheduled on incomplete streams, ensuring judges do not penalize prompts for cut-off or partial text resulting from client-side cancellation.

---

## How to tell abandoned streams apart from model truncation

An abandoned stream is different from an output truncated by the model:

| Characteristic | Abandoned Stream (`stream_incomplete: true`) | Truncated Output (`truncated: true`) |
|---|---|---|
| **Initiator** | Client aborted or connection dropped | Model reached `max_tokens` or output limit |
| **Status** | `stream_incomplete: true` | `stream_incomplete: false` |
| **Finish Signal** | Missing or interrupted | Provider `finish_reason` is `"length"` or `"max_tokens"` |
| **Latency** | Recorded as `null` | Recorded with actual request duration |
| **Tokens & Cost** | `null` (unless terminal chunk arrived) | Fully captured and priced |

For details on model-level truncation, see [How to tell if a model's response was truncated](https://coolhandlabs.com/help/how-to-tell-if-a-model-response-was-truncated.md).

---

## Inspecting incomplete streams in the API

You can inspect the `stream_incomplete` status on log entries returned by `GET /api/v2/llm_request_logs` or `GET /api/v2/llm_request_logs/{id}`. The list endpoint returns log metadata and metric fields without output content. To inspect the partial text generated before cancellation, fetch the individual log with `GET /api/v2/llm_request_logs/{id}`, which returns the generated text in the `output` field.

### Example API response (`GET /api/v2/llm_request_logs/{id}`)

```json
{
  "id": "log_a1b2c3d4",
  "source_api": "openai",
  "model": "gpt-4o",
  "source_api_result": "success",
  "stream_incomplete": true,
  "latency_ms": null,
  "input_tokens": null,
  "output_tokens": null,
  "cost": null,
  "output": "Here is the beginning of the requested outline:\n1. Introduction\n2. First phase",
  "created_at": "2026-11-20T14:22:10Z"
}
```

For more details on the fields available on log records, see [What every field on an LLM request log means](https://coolhandlabs.com/help/llm-request-log-fields.md).

---

Related:
- [How to tell if a model's response was truncated](https://coolhandlabs.com/help/how-to-tell-if-a-model-response-was-truncated.md)
- [What every field on an LLM request log means](https://coolhandlabs.com/help/llm-request-log-fields.md)
- [What is a workload?](https://coolhandlabs.com/help/what-is-a-workload.md)
- [What does the 'aliased model' label mean on my LLM request logs?](https://coolhandlabs.com/help/what-does-the-aliased-model-label-mean.md)

[← All help articles](https://coolhandlabs.com/help.md) · [Logs & API](https://coolhandlabs.com/help/category/logs-and-api.md)
