Intro

https://platform.claude.com/

Setup

API

  • Get API Credits
Thank you for submitting your Claude API credit request form. I'm pleased to inform you that credits have been added to your account.

 

As a reminder, these credits are available to use across all of our models as well as the following products:

    Claude Code: Anthropic's agentic coding tool

    Claude Code SDK: Anthropic’s agent developer kit

    Claude 1P API: build Claude directly into your product
  • Create API key

Environment Setup

  • Make virtual environment
python3 -m venv venv
source venv/bin/activate
  • Install packages
pip install python-dotenv anthropic
  • Create .env file
ANTHROPIC_API_KEY=your_api_key_here

Test Script

from dotenv import load_dotenv
import anthropic
 
# Environment Setup
load_dotenv()
 
client = anthropic.Anthropic(
    api_key=os.getenv("ANTHROPIC_API_KEY")
)
 
# Model Discovery
models = client.models.list()
print(f"Available models: ")
for m in models.data:
    print(m.id)
 
model="claude-sonnet-4-6"
print(f"\nUsing model: {model}\n")
 
# One-off prompt test
response = client.messages.create(
    #model="claude-3-5-sonnet-latest",
    #model="claude-3-5-sonnet-20241022",
    model=model,
    max_tokens=100,
    messages=[
        {"role": "user", "content": "say hello"}
    ]
)
 
print(response.content[0].text)
 
Available models: 
claude-opus-4-7
claude-sonnet-4-6
claude-opus-4-6
claude-opus-4-5-20251101
claude-haiku-4-5-20251001
claude-sonnet-4-5-20250929
claude-opus-4-1-20250805

Using model: claude-sonnet-4-6

Hello! 👋 How are you doing? Is there something I can help you with today?