Skip to main content
Article·anthropic.com
AILLMAnthropicaillmanthropicapipythonclaude

Claude 4 Opus

Quickly access and leverage Anthropic's most capable AI model, Claude 3 Opus, for advanced reasoning and superior coding tasks. This Action Pack guides you through setting up the API and making your first powerful call.

beginner15 min5 steps
The play
  1. Acquire an Anthropic API Key
    Visit the Anthropic console (console.anthropic.com), sign up or log in, and navigate to API Keys to generate a new key. This key is essential for authenticating your requests.
  2. Install the Anthropic Python SDK
    Open your terminal or command prompt and install the official Anthropic Python SDK using pip. This SDK simplifies interaction with the Claude API.
  3. Set Your API Key Environment Variable
    Before running your script, securely store your API key as an environment variable named `ANTHROPIC_API_KEY`. This prevents hardcoding sensitive information.
  4. Write Your First Interaction Script
    Create a Python file (e.g., `claude_opus_chat.py`). Import the `Anthropic` client, initialize it using your environment variable, and construct a simple message request to Claude 3 Opus, Anthropic's current most capable model.
  5. Execute the Script and Review Output
    Run your Python script from the terminal. Observe Claude's generated explanation of quantum entanglement. You can modify the `content` in the script for different prompts.
Starter code
import os
from anthropic import Anthropic

# Ensure ANTHROPIC_API_KEY environment variable is set
client = Anthropic(api_key=os.environ.get("ANTHROPIC_API_KEY"))

message = client.messages.create(
    model="claude-3-opus-20240229", # Anthropic's current most capable model
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "Write a Python function that calculates the factorial of a number using recursion."}
    ]
)

print(message.content)
Source
Claude 4 Opus — Action Pack