> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apiyi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Why do DeepSeek batch summarization requests time out?

> With deepseek-v4.1-flash, medium reasoning can consume over 90% of output tokens during batch summarization. Learn how to diagnose it and tune reasoning, streaming, timeouts, and batch size.

## Short answer

When `deepseek-v4.1-flash` uses `reasoning.effort = "medium"` for batch summarization or structured screening through `/v1/responses`, **hidden reasoning tokens can far exceed the final JSON output**. A non-streaming call returns only after both reasoning and visible output finish, so even a short JSON response can hit a 60-second client timeout.

Check `usage.output_tokens_details.reasoning_tokens` first. If reasoning accounts for most output tokens, try `low`, or `none` when quality permits, and combine that with streaming and a sufficient overall timeout. Do not rely solely on shortening the JSON or retrying immediately.

## An anonymized production example

A batch literature-screening workload submitted about 20 abstracts per request and asked for a JSON array containing one decision per paper. Its request shape was:

* Model: `deepseek-v4.1-flash`;
* Endpoint: `POST /v1/responses`;
* Parameter: `reasoning.effort = "medium"`;
* Non-streaming response with a 60-second overall client timeout.

Server-side analysis of a set of requests that reached 60 seconds produced the following results:

| Metric | Anonymized sample result |
| - | -: |
| Average total output tokens | About 13,500–14,500 |
| Reasoning share of output tokens | **91%–92%** |
| Non-reasoning output tokens (mainly JSON) | About 1,100–1,200 on average |
| Server-side total duration | 60–122 seconds |
| Weighted generation rate in two concentrated timeout windows | About 175 tok/s in both |

The data shows that **the requests were slow neither because the JSON was long nor because generation suddenly slowed during the incident windows. Hidden reasoning consumed most of the generation time.**

> [!NOTE]
>
> In the Responses API, `output_tokens` includes both reasoning tokens and final output. Do not estimate latency or cost from visible text alone. OpenAI uses the same accounting in its general guidance for reasoning models on Responses: `developers.openai.com/api/docs/guides/reasoning`.

## Confirm the issue in three steps

**1. Step 1: compare total output and reasoning tokens**

Inspect the final response:

```json theme={null}
{
  "usage": {
    "output_tokens": 13873,
    "output_tokens_details": {
      "reasoning_tokens": 12714
    }
  }
}
```

In this example, reasoning accounts for about 92% of output, while the visible answer is relatively small. If your distribution looks similar, reduce reasoning before compressing the input abstracts further.

**2. Step 2: check whether the output cap truncated the response**

`max_output_tokens` also includes reasoning tokens. If the response has `status = "incomplete"` and `incomplete_details.reason = "max_output_tokens"`, the budget may have been exhausted during reasoning, leaving partial or even empty visible output.

**3. Step 3: compare the client timeout with server-side completion**

For a non-streaming request, the complete response normally arrives only after generation finishes. A client disconnect at 60 seconds does not necessarily stop the server at the same time. The server may continue to completion and record usage, so an immediate retry can duplicate generation and charges.

## Recommended fixes

### 1. Lower reasoning effort first

For batch classification, extraction, and fixed-field screening, test `low` first, then evaluate whether `none` preserves sufficient quality:

```json theme={null}
{
  "model": "deepseek-v4.1-flash",
  "input": "Place the batch abstracts and screening protocol here",
  "reasoning": {
    "effort": "low"
  },
  "max_output_tokens": 8000,
  "stream": true
}
```

Use the same samples to compare accuracy, JSON validity, reasoning tokens, and total latency across `medium`, `low`, and `none`. `max_output_tokens = 8000` is only an example; adjust it for your actual output requirements and reasoning headroom rather than treating it as a universal value.

### 2. Use streaming while retaining an overall timeout

Streaming does not make the model generate faster, but it distinguishes ongoing generation from a genuinely stalled connection:

* Start with a 120–180 second overall timeout;
* A 20–30 second SSE idle timeout is a reasonable starting point;
* Measure idleness across all SSE events, including reasoning events, not just visible text events;
* Still validate the final response status and parse the complete JSON.

If you keep medium reasoning with non-streaming responses, use an overall timeout of at least **180 seconds**. In the measurements above, even 120 seconds did not cover the maximum 122-second server duration, while 90 seconds left still less headroom.

### 3. Reduce batch size, but do not rely on splitting alone

Start by reducing each batch from 20 papers to 10 and retesting with 2–4 concurrent requests to limit the impact of a failed request. Splitting, however, does not guarantee a proportional reduction in reasoning tokens. Use it together with lower reasoning effort rather than as a substitute.

### 4. Constrain retries

Use bounded exponential backoff for 429s, 5xx responses, and clear connection-establishment failures. Do not immediately retry every client timeout after a long wait; first determine whether the server is still generating, otherwise the same batch may run twice.

> [!WARNING]
>
> Do not sharply reduce `max_output_tokens` merely to prevent timeouts. The request may finish sooner because it ran out of budget, not because it succeeded, and the final JSON may be incomplete.

## Common questions

> [accordion] Why does a request take over a minute when the final JSON is short?
>
> The model may already have generated a large number of reasoning tokens before producing the JSON. Total latency depends on reasoning plus visible output, not visible output alone.

> [accordion] Does streaming reduce total generation time?
>
> Not significantly. Streaming improves visibility and timeout control by delivering events incrementally. Setting `stream = true` does not automatically reduce the number of tokens the model generates.

> [accordion] Should every batch summarization workload disable reasoning?
>
> No. Tasks requiring complex judgment may still benefit from reasoning. Evaluate quality on your own samples: start with `low`, and use `none` only after confirming that it does not reduce screening quality.

> [accordion] Why does the log still contain output usage after a client timeout?
>
> A client disconnect does not necessarily cancel server-side generation at the same moment. The model may continue through reasoning and visible output, so the log records the tokens actually generated. Blind retries after long timeouts can duplicate that usage.

## Related documentation

> [card] [DeepSeek V4 Flash Responses API](https://docs.apiyi.com/en/api-capabilities/deepseek-v4-flash/responses.md)
>
> Responses parameters, streaming, and caching

> [card] [Why does a reasoning model return empty content?](https://docs.apiyi.com/en/faq/reasoning-model-empty-response.md)
>
> Diagnosing output budgets exhausted by reasoning tokens

> [card] [How can I avoid API timeouts?](https://docs.apiyi.com/en/faq/timeout-configuration.md)
>
> Timeout settings for clients, proxies, and different workload types

> [card] [Long-form output best practices](https://docs.apiyi.com/en/api-capabilities/long-form-output-practices.md)
>
> Streaming, event idle timeouts, and retry strategies for long-running tasks


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.