Skip to main content
AI / Machine Learning

Phase 3: Direct AI API Access

10 Modules
Chapter 8: Chapter 6: Resources & Continued Learning80%

Chapter 6: Resources & Continued Learning

Introduction: Your AI API Reference Library

This resource collection supports your ongoing journey with direct AI API access. Bookmark this page — you'll return to it whenever you need a provider console link, a code snippet, a pricing update, or guidance on a new model.

Provider Consoles & Documentation

Anthropic (Claude Models)

Consoles & Dashboards:

Documentation:

Tools:

Current Models (mid-2026):

ModelIDContextBest For
Fable 5claude-fable-5200KLatest and most capable
Opus 4.8claude-opus-4-8200KTop-tier reasoning
Sonnet 4.6claude-sonnet-4-6200KBest balance of quality/speed/cost
Haiku 4.5claude-haiku-4-5200KSpeed champion, lowest cost

Check console.anthropic.com for current pricing — it changes as new models launch.

OpenAI (GPT Models)

Consoles & Dashboards:

Documentation:

Tools:

Current Models (mid-2026):

ModelIDContextBest For
GPT-4ogpt-4o128KReliable general purpose
GPT-4o-minigpt-4o-mini128KHigh volume, very cheap
o3o3200KComplex reasoning, maths

Check platform.openai.com/docs/models for current pricing.

Google (Gemini Models)

Consoles & Dashboards:

Documentation:

Tools:

Current Models (mid-2026):

ModelIDContextBest For
Gemini 2.5 Progemini-2.5-pro2MMassive context, code analysis
Gemini 2.5 Flashgemini-2.5-flash1MFast, cheap, generous free tier

Check aistudio.google.dev for current free-tier limits and pricing.

Groq (Open-Source Models, Free Tier)

Consoles & Dashboards:

Documentation:

Key Advantage: Ultra-fast inference, free tier, no credit card required. Models available change frequently — check the console for the latest offerings including Llama 4 variants.

Quick Reference: API Calls

Anthropic Claude (curl)

curl https://api.anthropic.com/v1/messages \
  -H "Content-Type: application/json" \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "claude-sonnet-4-6",
    "max_tokens": 1024,
    "messages": [
      {
        "role": "user",
        "content": "Explain API access in plain English, under 50 words."
      }
    ]
  }'

Anthropic Claude (Python)

from anthropic import Anthropic

client = Anthropic()  # reads ANTHROPIC_API_KEY from environment

message = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "Explain API access in plain English, under 50 words."}
    ]
)

print(message.content[0].text)
print(f"Tokens used: {message.usage.input_tokens} in, {message.usage.output_tokens} out")

OpenAI GPT (curl)

curl https://api.openai.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "model": "gpt-4o",
    "messages": [
      {
        "role": "user",
        "content": "Explain API access in plain English, under 50 words."
      }
    ],
    "max_tokens": 200
  }'

OpenAI GPT (Python)

from openai import OpenAI

client = OpenAI()  # reads OPENAI_API_KEY from environment

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[
        {"role": "user", "content": "Explain API access in plain English, under 50 words."}
    ],
    max_tokens=200
)

print(response.choices[0].message.content)
print(f"Tokens used: {response.usage.prompt_tokens} in, {response.usage.completion_tokens} out")

Google Gemini (curl)

curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=$GEMINI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {
        "parts": [
          {"text": "Explain API access in plain English, under 50 words."}
        ]
      }
    ]
  }'

Google Gemini (Python)

import google.generativeai as genai
import os

genai.configure(api_key=os.getenv("GEMINI_API_KEY"))

model = genai.GenerativeModel("gemini-2.5-flash")
response = model.generate_content("Explain API access in plain English, under 50 words.")

print(response.text)
print(f"Tokens used: {response.usage_metadata.prompt_token_count} in, "
      f"{response.usage_metadata.candidates_token_count} out")

Environment Setup Reference

The .env File

# .env — NEVER commit this file to version control
ANTHROPIC_API_KEY=sk-ant-api03-your-key-here
OPENAI_API_KEY=sk-proj-your-key-here
GEMINI_API_KEY=AIzaSy-your-key-here
GROQ_API_KEY=gsk_your-key-here

The .gitignore Entry

# Add to .gitignore
.env
.env.local
.env.*.local

Loading Keys in Python

import os
from dotenv import load_dotenv

load_dotenv()  # reads .env file

anthropic_key = os.getenv("ANTHROPIC_API_KEY")
openai_key = os.getenv("OPENAI_API_KEY")
gemini_key = os.getenv("GEMINI_API_KEY")

# Verify keys are loaded
for name, key in [("Anthropic", anthropic_key), ("OpenAI", openai_key), ("Gemini", gemini_key)]:
    if key:
        print(f"{name}: configured ({key[:8]}...)")
    else:
        print(f"{name}: NOT CONFIGURED")

Installing Python SDKs

# Create a virtual environment (optional but recommended)
python3 -m venv ai-env
source ai-env/bin/activate  # Linux/Mac
# ai-env\Scripts\activate   # Windows

# Install all provider SDKs
pip install anthropic openai google-generativeai python-dotenv groq

Cost Calculators & Tracking

Quick Cost Estimation Formula

Cost = (input_tokens / 1,000,000) x input_price + (output_tokens / 1,000,000) x output_price

Token estimation rules of thumb:

  • 1 token is roughly 4 characters or 0.75 words in English
  • A typical A4 page of text is approximately 500-600 tokens
  • A 1,500-word blog post is approximately 2,000 tokens

Monthly Cost Tracking Template

# AI API Cost Tracker — [Month] 2026

## Weekly Breakdown

| Week | Anthropic | OpenAI | Google | Groq | Total |
|------|-----------|--------|--------|------|-------|
| 1 | $ | $ | Free | Free | $ |
| 2 | $ | $ | Free | Free | $ |
| 3 | $ | $ | Free | Free | $ |
| 4 | $ | $ | Free | Free | $ |
| **Total** | **$** | **$** | **Free** | **Free** | **$** |

## vs Subscriptions
- ChatGPT Plus: £20/month
- Claude Pro: £18/month
- Gemini Advanced: £19/month
- **Subscription total: £57/month**
- **API total: £___/month**
- **Saving: £___/month (____%)**

## Model Usage Log
| Date | Task | Model | ~Tokens | ~Cost | Quality (1-5) |
|------|------|-------|---------|-------|---------------|
| | | | | | |

Provider Billing Pages (Bookmark These)

Model Selection Decision Tree

Quick Reference Card

TASK: Quick email, summary, simple question
  --> GPT-4o-mini or Haiku 4.5 (cheapest, fastest)

TASK: Professional writing, blog post, creative content
  --> Claude Sonnet 4.6 (best prose, natural voice)

TASK: Long document analysis (50+ pages)
  --> Gemini 2.5 Pro (2M context) or Gemini 2.5 Flash (1M, cheaper)

TASK: Complex reasoning, strategy, maths
  --> o3, Claude Opus 4.8, or Claude Fable 5

TASK: Rapid experimentation, prototyping
  --> Llama 4 via Groq (free, ultra-fast)

TASK: Code generation and review
  --> Claude Sonnet 4.6 or GPT-4o

TASK: Proofreading, formatting, simple edits
  --> Haiku 4.5 or GPT-4o-mini (no need for premium)

Context Window Guide

Under 50 pages:    Any model works
50-300 pages:      Claude models (200K) or GPT-4o (128K)
300-2,500 pages:   Gemini 2.5 Flash (1M context)
2,500-5,000 pages: Gemini 2.5 Pro (2M context) — only option

Learning Paths

Week 1-2: Foundation

Focus: Daily API usage, model preference formation

  • Use API access instead of web interfaces for all AI tasks
  • Track costs daily (use the template above)
  • Test each model on 3 different task types from your work
  • Identify your go-to model for each task category
  • Cancel or pause one AI subscription

Resources:

Week 3-4: Optimisation

Focus: Cost reduction, workflow automation

  • Refine model routing based on 2 weeks of data
  • Explore prompt caching (Anthropic, Google) for repeated tasks
  • Build 5 reusable prompt templates for your common tasks
  • Try the Python or TypeScript SDK for one provider
  • Experiment with temperature and max_tokens settings

Resources:

Month 2+: Advanced Techniques

Focus: Automation, integration, teaching others

  • Build a multi-model script that routes tasks automatically
  • Explore structured output (JSON mode) for data extraction
  • Investigate tool use / function calling for AI agents
  • Set up automated batch processing for recurring tasks
  • Help a colleague set up their own multi-model access

Resources:

Community & Support

Provider Communities

Anthropic:

OpenAI:

Google AI:

General AI Communities

DreamLab Workshop Support

  • 📧 Email: workshop@dreamlab.ai
  • 💬 Discord: Workshop Channel
  • 📅 Office Hours: Fridays 2-3pm GMT
  • 📖 Documentation: This workshop and all linked resources

Troubleshooting Reference

Common Errors and Solutions

401 Unauthorized / Invalid API Key

Cause: Key is wrong, expired, or has leading/trailing whitespace
Fix:
  1. Regenerate key from provider console
  2. Check for spaces when copying
  3. Verify key is in .env file (not hardcoded)
  4. Restart your editor after changing .env

429 Rate Limited

Cause: Too many requests in a short time window
Fix:
  1. Wait 60 seconds and retry
  2. Switch to a different provider temporarily
  3. Check your tier level — higher tiers have higher limits
  4. Implement exponential backoff in scripts

400 Bad Request / Context Length Exceeded

Cause: Input + expected output exceeds model's context window
Fix:
  1. Trim your input (remove unnecessary context)
  2. Reduce max_tokens in the request
  3. Switch to a model with a larger context window
  4. Split the task across multiple smaller requests

402 Payment Required / Insufficient Credits

Cause: Account balance is zero or card declined
Fix:
  1. Top up credits on the provider console
  2. Check payment method is valid
  3. Switch to a free-tier provider (Google, Groq) temporarily

500/503 Server Error

Cause: Provider is experiencing issues (rare but happens)
Fix:
  1. Wait 2-3 minutes and retry
  2. Check provider status page
  3. Switch to a different provider
  4. These are transient — don't change your setup

Provider Status Pages

Bookmark these to check during outages:

Security Checklist

Monthly Review

  • Rotate API keys (every 90 days minimum)
  • Review spending across all providers
  • Check for any unusual usage patterns
  • Verify .env is still in .gitignore
  • Confirm MFA is enabled on all provider accounts
  • Review which keys are active — revoke any unused ones

Key Rotation Procedure

  1. Log into the provider console
  2. Create a new API key
  3. Update your .env file with the new key
  4. Restart your editor / Claude Code session
  5. Verify the new key works with a test prompt
  6. Revoke the old key from the provider console

Calendar Reminder: Set a recurring event every 90 days: "Rotate AI API keys"

Staying Current

What Changes Frequently

AI APIs evolve fast. Here is what to watch for:

  • New models — Providers launch new models every few months. Check the model overview pages quarterly.
  • Pricing changes — Competition drives prices down. Recheck pricing before budgeting.
  • New features — Tool use, caching, structured outputs, and batch APIs emerge regularly.
  • Rate limit changes — Tiers and limits adjust as providers scale.
  • Context window increases — These tend to grow over time, expanding what's possible.

How to Stay Informed

  • 📧 Subscribe to provider newsletters (Anthropic, OpenAI, Google AI)
  • 🐦 Follow provider accounts on X
  • 🌐 Check r/ClaudeAI and r/OpenAI weekly
  • 📖 Read release notes when you see "new model available" in your console
  • 📅 Set a monthly calendar reminder: "Check AI model updates"

Your Ongoing Journey

Mastery path after the workshop: daily API usage, cancel subscriptions, optimise costs, automate workflows, then teach others by month three

Conclusion

Direct AI API access is a professional skill that compounds over time. The setup effort is one morning. The savings, flexibility, and capability improvements last indefinitely.

What you've gained today:

  • Access to the world's best AI models at wholesale prices
  • The knowledge to choose the right model for any task
  • Secure, professional API key management
  • A multi-model workflow that outperforms any single subscription
  • A foundation for automation and advanced AI integration

What to do next:

  1. Use API access for every AI task this week
  2. Track your costs and compare to your old subscriptions
  3. Refine your model preferences based on real work
  4. Share this knowledge with a colleague
  5. Return to this resource page whenever you need a reference

Welcome to professional AI access. The models are waiting.


Workshop Complete!

Back to Assessment | Back to Workshop Overview | Proceed to Next Phase -->