You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Modern AI systems are primarily accessed through APIs (Application Programming Interfaces). Understanding how to integrate AI into applications, manage tokens and costs, and use vector databases for enhanced retrieval is essential for building AI-powered products.
AI API Request Flow:
+--------------+ HTTPS POST +------------------+
| Your |----------------->| AI Provider |
| Application | | (e.g. Anthropic) |
| |<-----------------| |
| | JSON Response | +------------+ |
+--------------+ | | LLM Model | |
| +------------+ |
+------------------+
A typical call involves: authentication (API key in headers), a request body (model, messages, parameters), and a JSON response (generated text plus metadata).
import anthropic
client = anthropic.Anthropic(api_key="your-api-key-here")
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
system="You are a helpful assistant that explains concepts clearly.",
messages=[
{"role": "user", "content": "What is photosynthesis?"}
]
)
print(message.content[0].text)
| Parameter | Description | Typical Values |
|---|---|---|
| model | Which model to use | claude-sonnet-4-20250514, gpt-4o |
| messages | Conversation history | Array of role/content objects |
| system | System instructions | String defining behaviour |
| max_tokens | Max response tokens | 256-4096 |
| temperature | Randomness | 0.0-1.0 |
| top_p | Nucleus sampling | 0.0-1.0 |
| stream | Stream the response | true/false |
LLMs process tokens, not raw text. One token is roughly three-quarters of a word (about 4 characters).
Tokenisation Example:
Text: "Artificial intelligence is transforming the world."
Tokens: ["Art", "ificial", " intelligence", " is",
" transform", "ing", " the", " world", "."]
| Model | Input (per 1M tokens) | Output (per 1M tokens) |
|---|---|---|
| Claude 3.5 Sonnet | $3.00 | $15.00 |
| GPT-4o | $2.50 | $10.00 |
| Claude Haiku | $0.25 | $1.25 |
| GPT-4o mini | $0.15 | $0.60 |
Tip: Use the smallest model that meets your quality needs. Reserve frontier models for complex reasoning.
Embeddings are dense vectors capturing semantic meaning. Similar texts have similar vectors.
Embedding Space (simplified to 2D):
^
| * "happy"
| * "joyful" * "delighted"
|
"sad" * |
"unhappy" * | * "programming"
"miserable" * | * "coding"
| * "software"
+----------------------------->
Words with similar meanings cluster together.
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.