Anthropic Claude
The Anthropic Python library provides convenient access to the Anthropic Claude API from applications written in the Python language.
To use the Anthropic Claude API, you first need to have your Anthropic Claude API key.
Warning
When including private API keys in your code, make sure you DO NOT make your project "Open Source" when you share it.
Examples
from anthropic import Anthropic
api_key = input("🤖 What's your Anthropic API Key?\n")
client = Anthropic(api_key=api_key)
question = input("🤖 What's your question?\n")
print("🤖 Please wait a second ...")
message = client.messages.create(
max_tokens=1024,
messages=[
{
"role": "user",
"content": question,
}
],
model="claude-sonnet-4-6",
)
print("🤖", message.content[0].text)