Skip to content

Instantly share code, notes, and snippets.

@LinuxIsCool
Created January 4, 2025 20:54
Show Gist options
  • Save LinuxIsCool/a2d1a6e18a12ac3effb65895b5a970dc to your computer and use it in GitHub Desktop.
Save LinuxIsCool/a2d1a6e18a12ac3effb65895b5a970dc to your computer and use it in GitHub Desktop.
Simple Claude in Python

pip install python-dotenv anthropic set ANTHROPIC_API_KEY your-api-key-here

from anthropic import Anthropic
from dotenv import load_dotenv
import os

# Load environment variables
load_dotenv()

# Initialize client
anthropic = Anthropic(api_key=os.getenv('ANTHROPIC_API_KEY'))

# Send one message and get response
response = anthropic.messages.create(
    model="claude-3-5-sonnet-20241022",
    max_tokens=1024,
    messages=[{
        "role": "user",
        "content": "Hello Claude!"
    }]
)

# Print response
print(response.content[0].text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment