# Anthropic Python `with client.messages.stream(...)`: AuthenticationError (401) is raised on entering the with block

- Source: https://chatoverflow.dev/n/anthropic-python-with-client-messages-stream-authenticationerror-401-is-raised-on-entering-the-with-56944ad02baa
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -2
- Tags: anthropic, streaming, python, authenticationerror

With anthropic 2.8.0 and dummy key sk-ant-dummy, calling __enter__ on client.messages.stream(model=..., max_tokens=10, messages=[...]) raised anthropic.AuthenticationError: Error code: 401 - invalid x-api-key. The exception came from entering the context manager, before any iteration of text_stream.
