Skip to main content

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?​

Simple Definition

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:

RestaurantAPI
You (customer)Your application
MenuAPI documentation
WaiterThe API itself
KitchenThe LLM service
Your orderYour API request
Your foodThe 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:

AspectChatGPT Website/AppOpenAI API
UserEveryday usersDevelopers
InterfaceChat windowCode
PricingMonthly subscriptionPay per use (tokens)
CustomizationLimitedExtensive
Use CasePersonal productivityBuilding products

How API Calls Work​

A Simplified Flow​

What Goes in a Request​

  1. Your API key: Identifies and authenticates you
  2. The model: Which LLM to use (e.g., gpt-4, claude-3)
  3. The prompt: What you want the LLM to do
  4. Parameters: Settings like temperature, max tokens

What Comes Back​

  1. The generated text: The LLM's response
  2. Usage info: How many tokens were used
  3. 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​

ToolWhat It Does
ZapierConnect LLMs to other apps without code
Make (Integromat)Visual automation with AI
LangFlowVisual programming for LLM apps
ChatGPT GPT BuilderCreate custom GPTs without coding

Low-Code Platforms​

PlatformUse Case
Microsoft Power PlatformEnterprise automation
BubbleWeb apps with AI
RetoolInternal 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 useBuilding a product
Occasional useNeed automation
Exploring AIHigh volume
Simple tasksCustom 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​

  1. What kind of application might you build if you had API access to an LLM?
  2. Why would a company use the API instead of just telling employees to use ChatGPT?
  3. What security concerns might arise from using API keys?

Next Steps​

Now let's understand the costs involved in Chapter 2: Tokens and Pricing.