Anthropic SDK "Streaming is required for operations that may take longer than 10 minutes": cause and fix

This ValueError comes from the Anthropic Python SDK itself, not from the Claude API. The SDK raises it before sending anything when you call client.messages.create() without streaming and with a max_tokens value large enough that the SDK estimates the response could take more than 10 minutes. The fix is to stream the request, or to tell the SDK explicitly what timeout you accept.

The 30-second answer

The exact error

ValueError: Streaming is required for operations that may take longer than 10 minutes. See https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/python#long-requests for more details

This wording was reproduced today with anthropic==2.7.0 and matches the string in the installed SDK source (anthropic/_base_client.py).

Older SDK versions used a different sentence and link. In the SDK's GitHub source at tags v0.49.0 and v0.52.0 the message reads:

Streaming is strongly recommended for operations that may take longer than 10 minutes. See https://github.com/anthropics/anthropic-sdk-python#long-requests for more details

At tag v0.60.0 it already says "Streaming is required". We did not pin the exact release where the wording changed. Both wordings are the same check and have the same fix.

Verified against the installed SDK — 9 November 2026

Environment: anthropic==2.7.0, Python 3.11.9, macOS. The client used a bogus API key, max_retries=0, and a base_url pointing at a closed local port (http://127.0.0.1:9). A call that passes the SDK's check therefore fails with APIConnectionError, and a call that fails the check raises the ValueError. No request reached Anthropic.

1. The threshold logic, quoted from anthropic/_base_client.py in 2.7.0:

def _calculate_nonstreaming_timeout(self, max_tokens: int, max_nonstreaming_tokens: int | None) -> Timeout:
    maximum_time = 60 * 60
    default_time = 60 * 10

    expected_time = maximum_time * max_tokens / 128_000
    if expected_time > default_time or (max_nonstreaming_tokens and max_tokens > max_nonstreaming_tokens):
        raise ValueError(
            "Streaming is required for operations that may take longer than 10 minutes. "
            + "See https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/python#long-requests for more details",
        )

The SDK does not measure anything. It assumes 128,000 output tokens take 60 minutes and scales linearly, so 3600 × max_tokens / 128000 > 600 means any max_tokens above 21,333.33 raises. The prompt, the model's real speed and your network play no part.

2. When the check runs, from resources/messages/messages.py:

if not stream and not is_given(timeout) and self._client.timeout == DEFAULT_TIMEOUT:
    timeout = self._client._calculate_nonstreaming_timeout(
        max_tokens, MODEL_NONSTREAMING_TOKENS.get(model, None)
    )

DEFAULT_TIMEOUT is httpx2.Timeout(timeout=10 * 60, connect=5.0) in _constants.py. So the check is skipped if the call streams, if you pass timeout= on the call, or if the client was built with any timeout other than that default object.

3. Smallest max_tokens that raises, found by binary search on a non-streaming create():

anthropic 2.7.0 | Python 3.11.9 | Darwin
  claude-opus-5-5: smallest max_tokens that raises ValueError = 21334
  claude-sonnet-5: smallest max_tokens that raises ValueError = 21334
  claude-fable-5-2: smallest max_tokens that raises ValueError = 21334
  claude-haiku-4-5: smallest max_tokens that raises ValueError = 21334
  claude-opus-4-0: smallest max_tokens that raises ValueError = 8193

The model id is only a string here; the SDK does not validate it. The lower figure for claude-opus-4-0 comes from MODEL_NONSTREAMING_TOKENS in _constants.py, which in 2.7.0 lists seven ids (Claude Opus 4 ids and the Bedrock and Vertex ids for Claude Opus 4.1), all capped at 8,192. Every other model id gets the 21,333 rule.

4. What gets past the check (model claude-opus-5-5; APIConnectionError is the expected result against a closed port and proves the check passed):

create max_tokens=21333
  -> APIConnectionError: Connection error.  (0.00s)
create max_tokens=21334
  -> ValueError: Streaming is required for operations that may take longer than 10 minutes. See https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/python#long-requests for more details  (0.00s)
create max_tokens=64000, stream=True
  -> APIConnectionError: Connection error.  (0.00s)
messages.stream(max_tokens=64000).get_final_message()
  -> APIConnectionError: Connection error.  (0.00s)
create max_tokens=64000, timeout=1800 (per request)
  -> APIConnectionError: Connection error.  (0.00s)
create max_tokens=64000, timeout=600 (per request)
  -> APIConnectionError: Connection error.  (0.00s)
Anthropic(timeout=1800) create max_tokens=64000
  -> APIConnectionError: Connection error.  (0.00s)
Anthropic(timeout=600) create max_tokens=64000
  -> APIConnectionError: Connection error.  (0.00s)
client.with_options(timeout=1800) create max_tokens=64000
  -> APIConnectionError: Connection error.  (0.00s)
beta.messages.create max_tokens=64000
  -> ValueError: Streaming is required for operations that may take longer than 10 minutes. See https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/python#long-requests for more details  (0.00s)

Two details worth noticing: client.beta.messages.create() has the same check, and even timeout=600 (the same 10 minutes as the default) disables it, because the check only asks whether you set a timeout yourself.

5. Official documentation, fetched today. The Python SDK "Long requests" section (the URL in the error) says: "The SDK raises a ValueError if a non-streaming request is expected to take longer than approximately 10 minutes. Passing stream=True or overriding the timeout option at the client or request level disables this error." The "Long requests" section of the API errors page says the SDK "validates that your non-streaming Messages API requests are not expected to exceed a 10-minute timeout."

Not verified: no request was sent to the live API, so real generation times, live streaming behaviour and the Message Batches API were not tested. The TypeScript SDK was read, not run.

Cause 1: large max_tokens on a non-streaming call

This is the usual case: max_tokens was raised to 32,000, 64,000 or 128,000 and the call still uses plain create(). Stream it and let the SDK assemble the result. This is the pattern Anthropic's errors page gives, and the same call shape passed the check in test 4:

import anthropic

client = anthropic.Anthropic()

with client.messages.stream(
    max_tokens=128000,
    messages=[{"role": "user", "content": "Write a detailed analysis..."}],
    model="claude-sonnet-5",
) as stream:
    message = stream.get_final_message()

print(next(block.text for block in message.content if block.type == "text"))

The errors page describes the result as "the complete Message object, identical to what a non-streaming call returns", so the rest of your code does not have to change.

Cause 2: max_tokens is higher than you need

If the value was set high "to be safe" and your responses are short, lower it. Anything up to 21,333 passes the check on a non-streaming call in 2.7.0 (8,192 for the Claude Opus 4 and 4.1 ids listed above).

Cause 3: you must keep a non-streaming call

Pass a timeout so the SDK knows you accepted the wait. Either form passed the check in test 4:

message = client.messages.create(
    model="claude-opus-5-5",
    max_tokens=64000,
    messages=[{"role": "user", "content": "..."}],
    timeout=1800,   # seconds
)

# or once, for every call on this client
client = anthropic.Anthropic(timeout=1800)

Understand what you are trading away. The SDK documentation warns that "some networks might drop idle connections after a certain period of time", and that a request that outlasts the timeout "will result in the client ending the connection and retrying without receiving a response". A non-streaming request sends nothing back until it finishes, so a long one is exactly the idle connection that gets dropped. Use this for jobs you can afford to re-run, not as the default fix.

Cause 4: a long offline job that does not need an immediate answer

Anthropic's errors page lists the Message Batches API as the other option for long-running requests, "especially those over 10 minutes", because it lets you "poll for results rather than requiring an uninterrupted network connection". We did not test batches for this page.

TypeScript SDK

The TypeScript SDK has the equivalent check. Its documentation says: "This SDK also throws an error if a non-streaming request is expected to be above roughly 10 minutes long. Passing stream: true or overriding the timeout option at the client or request level disables this error." In the source on the main branch of anthropics/anthropic-sdk-typescript (src/client.ts, fetched today), calculateNonstreamingTimeout uses the same maxTokens / 128000 formula and throws an AnthropicError beginning "Streaming is required for operations that may take longer than 10 minutes." The fix on the errors page is client.messages.stream({...}) followed by await stream.finalMessage(). This was read from source and docs, not run.

FAQ

What max_tokens value triggers it? In anthropic 2.7.0, 21,334 or higher on a non-streaming call; 21,333 passes. A handful of Claude Opus 4 and 4.1 ids listed in the SDK are capped at 8,192.

Is this an API error? Was I charged? No. It is a Python ValueError raised inside the SDK before any HTTP request. In our test the client pointed at a closed port and the error still appeared in 0.00 seconds.

I do not want to handle stream events. Can I still get one Message object? Yes. Use client.messages.stream(...) as a context manager and call stream.get_final_message(). Anthropic's errors page describes the result as identical to what a non-streaming call returns.

Does the TypeScript SDK do the same? Yes, per its documentation and source: same formula, same "Streaming is required" wording, thrown as an AnthropicError. We did not run it.


Related

Verified on 9 November 2026: error, threshold and bypasses reproduced with anthropic 2.7.0 on Python 3.11.9 against a closed local port (output shown above); SDK source quoted from the installed package; Python and TypeScript SDK docs, the API errors page and the SDK GitHub source fetched the same day. No live API calls were made.