Chapter 1: Using LLM APIs
How Applications Connect to LLMs
When you use ChatGPT through the website, you're using a user interface. But how do apps, websites, and services integrate LLMs into their products? Through APIs.
What Is an API?
An API (Application Programming Interface) is a way for different software applications to communicate with each other.
The Restaurant Analogy
Think of an API like ordering at a restaurant:
| Restaurant | API |
|---|---|
| You (customer) | Your application |
| Menu | API documentation |
| Waiter | The API itself |
| Kitchen | The LLM service |
| Your order | Your API request |
| Your food | The LLM's response |
You don't go into the kitchen—you communicate through the waiter (API), who takes your order (request) to the kitchen (LLM) and brings back your food (response).
ChatGPT vs. API
These are different ways to access the same technology:
| Aspect | ChatGPT Website/App | OpenAI API |
|---|---|---|
| User | Everyday users | Developers |
| Interface | Chat window | Code |
| Pricing | Monthly subscription | Pay per use (tokens) |
| Customization | Limited | Extensive |
| Use Case | Personal productivity | Building products |
How API Calls Work
A Simplified Flow
What Goes in a Request
- Your API key: Identifies and authenticates you
- The model: Which LLM to use (e.g., gpt-4, claude-3)
- The prompt: What you want the LLM to do
- Parameters: Settings like temperature, max tokens
What Comes Back
- The generated text: The LLM's response
- Usage info: How many tokens were used
- Metadata: Model version, timing info
Simple API Example (Conceptual)
You don't need to code, but here's what an API call looks like:
// Conceptual example - not code to run
Request:
{
"model": "gpt-4",
"messages": [
{"role": "system", "content": "You are a helpful assistant"},
{"role": "user", "content": "What is the capital of France?"}
],
"temperature": 0.7
}
Response:
{
"choices": [
{"message": {"content": "The capital of France is Paris."}}
],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 8,
"total_tokens": 33
}
}
Major API Providers
OpenAI API
- Models: GPT-4, GPT-3.5-turbo
- Strengths: Most popular, well-documented
- Access: api.openai.com
Anthropic API
- Models: Claude 3 (Opus, Sonnet, Haiku)
- Strengths: Long context, safety-focused
- Access: anthropic.com
Google AI
- Models: Gemini Pro, Gemini Ultra
- Strengths: Multimodal, Google integration
- Access: ai.google.dev
Azure OpenAI
- Models: Same as OpenAI, via Microsoft
- Strengths: Enterprise features, compliance
- Access: azure.microsoft.com
No-Code Options
You don't need to be a developer to use LLM APIs!
No-Code Tools
| Tool | What It Does |
|---|---|
| Zapier | Connect LLMs to other apps without code |
| Make (Integromat) | Visual automation with AI |
| LangFlow | Visual programming for LLM apps |
| ChatGPT GPT Builder | Create custom GPTs without coding |
Low-Code Platforms
| Platform | Use Case |
|---|---|
| Microsoft Power Platform | Enterprise automation |
| Bubble | Web apps with AI |
| Retool | Internal tools |
Key API Concepts
Authentication
Your API key is like a password—keep it secret!
Rate Limits
Limits on requests per minute to prevent overload:
- Free tiers: ~3 requests/minute
- Paid tiers: ~60+ requests/minute
Endpoints
Different URLs for different functions:
/chat/completions- Chat responses/embeddings- Text to numbers/audio/transcriptions- Speech to text
Streaming
Receiving responses word-by-word as they're generated (like ChatGPT typing).
Common Use Cases
1. Customer Support Bots
- Integrate into website or app
- Handle common questions
- Escalate complex issues
2. Content Generation
- Email drafts
- Marketing copy
- Product descriptions
3. Data Processing
- Summarize documents
- Extract information
- Categorize content
4. Code Assistance
- Generate code snippets
- Explain code
- Fix bugs
Choosing Between Consumer and API
| Choose Consumer (ChatGPT/Claude) When... | Choose API When... |
|---|---|
| Personal use | Building a product |
| Occasional use | Need automation |
| Exploring AI | High volume |
| Simple tasks | Custom integration |
Key Takeaways
✅ APIs let applications communicate with LLM services
✅ ChatGPT is for consumers; APIs are for building products
✅ API calls include your key, model choice, prompt, and settings
✅ No-code tools make APIs accessible to non-developers
✅ Rate limits and authentication are important considerations
Think About It
- What kind of application might you build if you had API access to an LLM?
- Why would a company use the API instead of just telling employees to use ChatGPT?
- What security concerns might arise from using API keys?
Next Steps
Now let's understand the costs involved in Chapter 2: Tokens and Pricing.