Skip to content
TUTORIALIntermediate

LLM Integration Basics

Call AI APIs and build LLM-powered applications

Learn to integrate LLMs into applications using the Anthropic and OpenAI APIs. Covers API calls, streaming, error handling, and building a simple AI-powered feature from scratch.

20 min4 stepsUpdated 2026-02-15
Prerequisites:Basic PythonBasic understanding of REST APIs

STEP-BY-STEP GUIDE

How to LLM Integration Basics

1

Set Up Your API Environment

pip install anthropic openai python-dotenv

# .env file
ANTHROPIC_API_KEY=sk-ant-...
OPENAI_API_KEY=sk-...

Never hardcode API keys. Load them from environment variables using python-dotenv.

2

Make Your First API Call

import anthropic
import os
from dotenv import load_dotenv

load_dotenv()

client = anthropic.Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])

message = client.messages.create(
    model="claude-haiku-4-5-20251001",
    max_tokens=1024,
    messages=[
        {
            "role": "user",
            "content": "Analyze this job description and list the top 5 required skills."
        }
    ]
)

print(message.content[0].text)
3

Add Streaming for Better User Experience

with client.messages.stream(
    model="claude-haiku-4-5-20251001",
    max_tokens=1024,
    messages=[{"role": "user", "content": prompt}]
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)
4

Handle Errors and Rate Limits

import time
from anthropic import RateLimitError, APIError

def call_with_retry(client, prompt, max_retries=3):
    for attempt in range(max_retries):
        try:
            return client.messages.create(
                model="claude-haiku-4-5-20251001",
                max_tokens=1024,
                messages=[{"role": "user", "content": prompt}]
            )
        except RateLimitError:
            wait = 2 ** attempt  # exponential backoff
            time.sleep(wait)
        except APIError as e:
            raise e  # don't retry on non-rate-limit errors
    raise Exception("Max retries exceeded")

PRACTICE

Exercises

Write a Python script that calls the Anthropic API and returns a job description analysis.

Add streaming to your API call so the response appears word-by-word.

Build a retry mechanism with exponential backoff for API rate limit errors.

Create a simple CLI tool that takes a job description and returns a tailored resume summary.

Add Redis caching to your API calls to avoid redundant API costs on repeated queries.

CAREER IMPACT

Career Paths That Use This Skill

Career PathHow It's UsedSalary Range
ML EngineerBuilding LLM-powered features in production$140K–$250K
AI Software EngineerIntegrating AI into applications$130K–$220K
Prompt EngineerBuilding and testing prompt systems via API$90K–$175K
AI EntrepreneurBuilding AI-powered products and servicesVariable

FAQ

Common Questions

Which API should I use — Anthropic or OpenAI?+
Both are excellent. Claude (Anthropic) has a 200K token context window and strong instruction-following. GPT-4 (OpenAI) has broader ecosystem integrations. Learn both — most production systems use multiple providers for redundancy and cost optimization.
How much do API calls cost?+
In 2026, typical costs: Claude Haiku ~$0.25/1M input tokens, Claude Sonnet ~$3/1M, GPT-4o-mini ~$0.15/1M input. A typical application call uses 500-2,000 tokens. Budget $10-50/month for development, more for production.
How do I avoid exposing my API key?+
Store keys in environment variables, never in code. Use .env files locally (add to .gitignore). In production, use a secrets manager (AWS Secrets Manager, Doppler, Vault). Never commit API keys to Git — even in private repos.

Put this skill into action

Take our quiz to get your personalized learning path and start applying these skills immediately.

Find My Track

Ready to Apply? Use HireKit's Free Tools

AI-powered job search tools for LLM Integration Basics

hirekit.co — AI-powered job search platform