Setup & your first request
Before you can build anything with Claude, you need an API key and a working Python (or TypeScript) environment. Install the official SDK, export your key as an environment variable, and make your first call to the Messages API.
import anthropic
client = anthropic.Anthropic() # reads ANTHROPIC_API_KEY from the environment
message = client.messages.create(
model="claude-sonnet-5",
max_tokens=1024,
messages=[
{"role": "user", "content": "Hello, Claude! What can you help me with?"}
],
)
print(message.content[0].text)
Key takeaways: the API key should always come from an environment variable
or secret store, never hardcoded in source or committed to git. The Messages
API is stateless — each request is independent, so a multi-turn conversation
means resending the full message history every time. Finally, max_tokens
caps the length of the response, not a fixed cost — set it high enough for
what you expect to receive.