🎯 SQL Practice

API & Local Dev Setup

Connect to Claude from your local machine and start building.

The Claude API vs Claude.ai

Claude.ai is the consumer product. The Claude API is for developers who want to integrate Claude into their own applications, scripts, or data pipelines. Key differences:

AspectClaude.aiClaude API
BillingFlat monthly subscriptionPay per token (input + output)
LimitsDaily message limitsRate limits (requests/minute)
FeaturesProjects, Memory, UISystem prompts, streaming, tools, batches
Best forInteractive workAutomated workflows, apps, pipelines

Step 1: Create an Anthropic account and get an API key

  1. Go to console.anthropic.com
  2. Sign up or log in
  3. Navigate to API Keys in the left sidebar
  4. Click "Create Key", give it a name (e.g., "local-dev")
  5. Copy the key immediately — Anthropic only shows it once
  6. Add a credit card and load some credits ($5 is enough to start)
API KEY SECURITY Never put your API key directly in code. Store it in environment variables or a secrets manager. Never commit it to Git.

Step 2: Set up your environment

TERMINAL COMMANDS
# Create a project folder
mkdir claude-projects && cd claude-projects

# Create a virtual environment
python -m venv venv
source venv/bin/activate   # Windows: venv\Scriptsctivate

# Install the Anthropic SDK
pip install anthropic

# Set your API key (add to ~/.bashrc or ~/.zshrc for permanent)
export ANTHROPIC_API_KEY="sk-ant-..."

Step 3: Your first API call

Python — basic API call
import anthropic

client = anthropic.Anthropic()  # reads ANTHROPIC_API_KEY from env

message = client.messages.create(
    model="claude-sonnet-4-5",
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "Explain what a star schema is in 3 sentences."}
    ]
)

print(message.content[0].text)

Step 4: Add a system prompt

Python — system prompt
message = client.messages.create(
    model="claude-sonnet-4-5",
    max_tokens=1024,
    system="You are a senior data engineer. Always answer concisely. Show SQL code before explanation.",
    messages=[
        {"role": "user", "content": "How do I find duplicate emails in a customer table?"}
    ]
)
print(message.content[0].text)

Step 5: Multi-turn conversation

Python — conversation with history
messages = []

def chat(user_input):
    messages.append({"role": "user", "content": user_input})
    response = client.messages.create(
        model="claude-sonnet-4-5",
        max_tokens=1024,
        system="You are a helpful data engineering assistant.",
        messages=messages
    )
    reply = response.content[0].text
    messages.append({"role": "assistant", "content": reply})
    return reply

print(chat("What is a fact table?"))
print(chat("And what's the difference between a dimension table and a fact table?"))
print(chat("Give me an example with a retail company"))

Understanding API costs

The API is billed per token (roughly 1 token ≈ 0.75 words). As of 2026 pricing:

ModelInput (per 1M tokens)Output (per 1M tokens)
Claude 4 Opus~$15~$75
Claude 4 Sonnet~$3~$15
Claude 3.5 Haiku~$0.25~$1.25

For development and learning: start with Sonnet. For production APIs with high volume: use Haiku. For one-off complex reasoning: use Opus. Monitor your usage in the Console dashboard.