Using Interfaces: APIs & MCP
When software talks to models, someone needs the vocabulary — APIs and MCP do that.
You have seen what a language model can do when you type into a chat window. But software does not type — it sends structured requests through an API.
This article takes you from your first API call to the protocol that could standardize how all AI tools connect: MCP. Along the way, you will learn what these calls cost, why 50 custom integrations are a problem, and how four building blocks turn a single model into an acting agent.
From Chat Window to Code
The moment you move from a chat UI to code, the model becomes a service you call — like any other web API.
Definition
LLM API
Analogy
Definition
Important: you do not choose the ingredients — you have no access to the model's internal workings.
A minimal Python call looks like this (keep the real key in an environment variable, never directly in the code):
from openai import OpenAI
client = OpenAI() # reads OPENAI_API_KEY from the environment
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "What is DNA?"}]
)
print(response.choices[0].message.content)Billing is split between input and output tokens.
Example with GPT-4o pricing (an older model that OpenAI removes from the API on January 14, 2027): 30 input tokens × USD 2.50 per million = USD 0.000075. 100 output tokens × USD 10.00 per million = USD 0.001. Total: about USD 0.001 — roughly one tenth of a cent.
At 1,000 calls per day: about USD 1.08. At 100,000 calls per day: about USD 107.50.
Per Call
~0.1 cents
Cost of a single GPT-4o API call
At 100k Calls/Day
~107.5 USD
Daily cost at high volume
Fewer Integrations
70 %
Savings through MCP with 5 apps and 10 tools (N+M instead of N×M)
Caution
Common Misconception: APIs Are Expensive
Individual short calls often cost only fractions of a cent. The cost risk lies in volume and long context windows — not in single requests. Think of API costs like a water bill: the per-liter price is tiny, but leaving the tap open drains the budget.
Interactive: What Happens During an API Call?
Click Play and watch step by step what happens behind the scenes when your code calls an API — from the browser through DNS and TLS to the JSON response.
This animation shows the six stations every API call passes through — from the click in the browser to the JSON response.
Click "Play" to see the process step by step.
Every API call — whether to OpenAI, Claude, or your own REST API — goes through these steps (DNS lookup and handshake usually only on the first call; after that the connection is reused). Understanding what happens helps you diagnose errors (timeouts, 404, CORS) much faster.
One Plug for Everything — MCP
You have just seen how one app talks to one model. Now imagine five apps, each needing ten different tools. Without a standard, that is 50 integrations. This is the N-times-M problem.
Definition
Model Context Protocol (MCP)
Analogy
Definition
5 apps × 10 tools = 50 custom integrations to build and maintain.
5 MCP clients + 10 MCP servers = 15 implementations. That is a 70% reduction.
Key difference: USB-C is a mature, universal standard. MCP is young (2024); ChatGPT, Gemini and Microsoft Copilot now support it, but it is not yet universally adopted.
Architecturally, MCP forms a triangle: the MCP server exposes tools, the client manages the connection, and the LLM decides when to use which tool. Concrete example: Claude Desktop connects to filesystem, SQLite, and GitHub through three MCP servers — one protocol, three capabilities.
Caution
Important: MCP Is Not a Universal Replacement
MCP does not replace all APIs. Direct integrations remain necessary for specialized SaaS services where no MCP server exists yet. MCP standardizes how AI discovers and invokes tools — not how the tool works internally.
Anatomy of an Agent
An API call is a question with one answer. An agent is a loop — it plans, acts, observes, and decides whether to continue. This loop needs four building blocks.
Think of a head chef managing dinner service.
The chef's brain is the LLM — reading orders, deciding what to cook, and prioritizing. The chef's hands are the tools — knife, stove, oven, each with a specific function. The order tickets above the pass are the context — they track what has been ordered, what is in progress, what is done. The kitchen workflow is the orchestration: starters first, then mains, then desserts, check timing.
Like a real chef, an agent can also make mistakes — picking the wrong tool or misreading an order.
- 1. Receive Task
- 2. PlanLLM chooses tool
- 3. Executetool runs
- 4. Observeresult returns
- 5. Decidecontinue or stop
Example: A Travel-Booking Agent
Step 1: The user says: Book me a flight to Berlin next Tuesday. Step 2: The LLM reads the calendar (context) — Tuesday is March 24. Step 3: The LLM calls the flight-search tool — three options found. Step 4: The LLM compares prices and times, selects the cheapest morning flight. Step 5: The LLM asks the user for confirmation (safety gate). Step 6: User confirms. Step 7: The LLM calls the booking tool. Step 8: Orchestration checks the result — booking confirmed — loop ends.
Caution
Common Misconception: Agents Are Freely Improvising AI
Today's agents are only as capable as their tools, permissions, and safety boundaries. They do not improvise — they follow a plan-act-observe loop within defined guardrails. An agent without tools is a chatbot. An agent without guardrails is a liability.
LangChain: Broad integration ecosystem — many connectors, many possibilities.
LlamaIndex: RAG-focused — document processing and knowledge retrieval as core strengths.
CrewAI: Multi-agent collaboration — agents with defined roles working together.
Claude Agent SDK: Claude Code's agent loop and tools as a library, with built-in MCP support.
This overview is a signpost, not a benchmark. Each framework has its own emphasis.
Note
Key Takeaways
- An API call is an HTTP POST with JSON — the same mental model you already know from web development, applied to language models.
- MCP turns many-to-many integration chaos (N times M) into a manageable many-plus-many structure (N plus M) by standardizing how tools expose their capabilities.
- An agent is not magic — it is a loop of four components (LLM, Tools, Context, Orchestration) repeating until a stopping condition is met.
Check
Knowledge Check: APIs & MCP
What is the primary role of an API key when calling an LLM API?
Select one answer
1. What is the primary role of an API key when calling an LLM API?
2. Which statement best describes what MCP standardizes?
3. A startup runs 50,000 API calls per day. Each call uses 200 input tokens and 500 output tokens. The provider charges USD 3.00 per million input tokens and USD 15.00 per million output tokens. What is the approximate daily cost?
4. A company has 3 AI applications that each need to work with 8 different tools. How many integrations are needed without MCP — and how many with MCP?
5. An AI agent is tasked with summarizing a 200-page PDF but keeps producing incomplete summaries. Which component of the agent architecture could be the cause?
6. A developer argues: We do not need MCP — direct API integrations are fine. In which scenario is this argument strongest?
Check
Self-Check: APIs & MCP
Can you explain this in your own words? Tick what you've got.
0 of 3 done