# Using the Anthropic Python SDK ## Installation ``` pip install anthropic ``` ## Creating a client ```python import anthropic client = anthropic.Anthropic() ``` If you don't pass `api_key` explicitly, the client reads it from the `ANTHROPIC_API_KEY` environment variable. ## Sending a message ```python message = client.messages.create( model="claude-sonnet-5", max_tokens=1024, messages=[{"role": "user", "content": "Hello, world"}], ) ``` If you omit `max_tokens`, it defaults to 1024. ## Automatic retries By default, the client automatically retries a failed request up to 5 times before raising an error. ## Streaming responses You can stream a response incrementally using `client.messages.stream_response()` as a context manager, rather than waiting for the full response to complete. ## Async usage For async code, use `anthropic.AsyncAnthropic()` instead. It mirrors the same methods as the synchronous client, but you `await` them.