AI Automation with n8n, Make and Zapier · APIs, webhooks, LLMs and MCP · lesson 10 of 17 · 17 min
Connecting LLM APIs: structured outputs, cost and MCP
Native AI steps vs direct API calls
Every platform now has built-in AI steps (n8n AI nodes, Make AI modules, AI by Zapier). But calling LLM APIs directly via HTTP gives you:
- Access to the newest models and features the moment they ship.
- Precise control over parameters: structured output schemas, tool definitions, reasoning settings, caching.
- Portability: the same request works in any platform or in code.
Use built-in steps for speed; use direct calls when you need control.
The request shape (provider-agnostic)
All major LLM APIs share a pattern: model name, instructions/system prompt, user input, optional tools, optional output format, limits (max output tokens), and metadata. Response: text and/or structured output, tool calls, and usage (input/output tokens) for cost tracking.
Structured outputs: the single most important technique
Ask the model to return JSON that must match a schema. Major providers support schema-constrained outputs (for example OpenAI's structured outputs with json_schema and strict, and similar features from Anthropic and Google). Your automation can then map fields reliably.
curl -sS https://api.openai.com/v1/responses \
-H "Authorization: Bearer $OPENAI_API_KEY" -H "Content-Type: application/json" \
-d '{
"model": "gpt-5-mini",
"instructions": "Classify inbound B2B leads for a Dubai agency. Use only the allowed values.",
"input": "Hi, we run 3 cafes in JLT and want Instagram ads before Ramadan. Budget around 8k AED/month.",
"text": {"format": {"type": "json_schema", "name": "lead", "strict": true,
"schema": {"type": "object", "additionalProperties": false,
"required": ["service", "industry", "budget_monthly", "currency", "urgency"],
"properties": {
"service": {"type": "string", "enum": ["seo", "paid_social", "web", "content", "other"]},
"industry": {"type": "string"},
"budget_monthly": {"type": ["number", "null"]},
"currency": {"type": ["string", "null"]},
"urgency": {"type": "string", "enum": ["low", "medium", "high"]}}}}}
}'
Model names change frequently; use a model from your provider's current list. The same idea works with Anthropic's Messages API (tool-use or structured output features) and Google's Gemini API (response schemas). Paste the call into an n8n HTTP Request node, a Make HTTP module or a Zapier webhook action, with the key stored as a credential.
Tool (function) calling in automations
Instead of JSON output, you can define tools the model may call (for example lookup_order(order_id)); your workflow executes the tool and returns the result. Built-in agent nodes handle this loop for you. Use direct tool calling only when you need custom loop logic.
Controlling cost and latency
- Right-size models: small, fast models for classification and extraction; larger reasoning models for complex drafting or analysis.
- Trim inputs: send the relevant part of an email, not the whole thread with signatures.
- Cap outputs with max output tokens.
- Cache repeated prompts where providers support prompt caching (long, stable system prompts).
- Batch non-urgent jobs (some providers offer discounted batch APIs).
- Log usage per workflow run (tokens in/out) and compute cost from current price sheets.
MCP across the three platforms
The Model Context Protocol is an open standard for connecting AI applications to tools and data. Two directions matter for automation builders:
| Direction | n8n | Make | Zapier | |---|---|---|---| | Your automations as tools for AI (MCP server) | MCP Server Trigger node | Make MCP Server | Zapier MCP | | Your AI agents using external tools (MCP client) | MCP Client Tool in AI Agent | MCP tools for Make AI Agents | Agents and AI features connect to apps (check current MCP client support) |
Pattern: build a tested, narrow workflow ("create_quote" with validated inputs), expose it via MCP, and let an AI assistant (for example Claude or ChatGPT with MCP connectors) call it. The AI gets capabilities; your workflow keeps the rules, credentials and logging.
Security: authenticate MCP endpoints; expose minimal tools; validate every input as untrusted; require human confirmation for writes; log calls.
Worked example: a London agency's "quote builder" tool
The agency builds an n8n workflow create_quote(client_name, services[], monthly_budget_gbp, start_date) that validates inputs, applies the rate card from a database, generates a Google Docs quote from a template, and returns the link. It exposes it through the MCP Server Trigger with authentication. Account managers ask their AI assistant: "Draft a quote for Crescent Foods: SEO and paid social, around 6k a month, starting October." The assistant calls the tool; pricing logic stays deterministic in n8n; the account manager reviews the doc before sending.
Pitfalls
- Parsing free text with regex instead of requesting schema-bound JSON.
- Sending entire email threads and attachments to expensive models.
- Exposing broad write tools via MCP without confirmation.
Video lecture: Connecting LLM APIs: structured outputs, cost and MCP
Lecture coming soon · 13 chapters · about 9 minutes. Read the full transcript below.
- Connecting LLM APIs
- Why it matters
- Analogy: story vs form
- Request shape
- Walkthrough: Dubai cafe lead
- Tools + cost control
- MCP both ways
- Example 1: schema-bound triage
- Example 2: London quote builder via MCP
- Security + mistakes
- Watch me do it: direct API + MCP
- Recap + try this now
- Try this now
Lecture transcript
Connecting LLM APIs
Every automation platform now has a friendly AI step. So why would you ever call a language model API directly? Because the moment a new model or feature ships, it's available in the API before it's in a connector. Because direct calls give you precise control over output formats, tools, caching and cost. And because the same request works in n8n, Make, Zapier or your own code. In this lesson, you'll learn the request shape, structured outputs, tool calling, cost control, and how MCP connects automations and AI assistants in both directions.
Why it matters
Why does this matter so much? Because the difference between an AI demo and an AI automation is reliability. A demo can show a nice paragraph. An automation needs the same fields, in the same format, every single time, so the next step can route and write data without breaking. Structured outputs are how you get there, and direct API calls give you full control of them.
Analogy: story vs form
Here's an analogy. Asking a model for free text is like asking a new employee to tell me about this lead. You'll get a different story every time. Asking for structured output is like handing them a form with boxes: service, one of these five; industry; monthly budget as a number; currency; urgency, low, medium or high. They can still use judgment, but the answers land in the right boxes, every time. Your automation reads the boxes.
Request shape
The request shape is similar across providers. You send a model name, instructions, the user input, optionally tools and an output format, and limits like maximum output tokens. You get back text or structured output, any tool calls, and usage figures for input and output tokens, which you use to track cost. In the lesson text, there's a complete curl example to OpenAI's Responses API that classifies a lead for a Dubai agency, using a JSON schema with strict mode and allowed values. Anthropic and Google offer equivalent structured output features.
Walkthrough: Dubai cafe lead
Let's walk through that example. The input is: we run three cafes in J L T and want Instagram ads before Ramadan, budget around eight thousand dirhams a month. The schema requires service, from SEO, paid social, web, content or other; industry; monthly budget as a number or null; currency; and urgency, low, medium or high. Strict mode means the model's output must match the schema. A likely result: paid social, food and beverage, eight thousand, AED, high urgency because of the Ramadan deadline. Your workflow maps those fields straight into the CRM and routes high urgency to the paid social lead.
Tools + cost control
Instead of JSON output, you can define tools the model may call, like lookup order with an order ID. The model asks to call the tool, your workflow runs it and returns the result, and the model continues. Built-in agent nodes handle that loop for you, so only build it by hand when you need custom logic. Now cost and latency. Right-size models: small fast models for classification and extraction, bigger reasoning models only for complex drafting. Trim inputs, cap outputs, cache long stable prompts where supported, batch non-urgent jobs, and log token usage per run.
MCP both ways
Now MCP, the Model Context Protocol, an open standard for connecting AI applications to tools and data. There are two directions. First, your automations as tools for AI: n8n's MCP Server Trigger, the Make MCP Server and Zapier MCP let AI assistants call your workflows or actions. Second, your AI agents using external tools: n8n's MCP Client Tool and MCP tools for Make AI Agents let your agents call external MCP servers. The powerful pattern is to build a narrow, tested workflow, expose it via MCP, and let an assistant call it. The AI gets the capability; your workflow keeps the rules.
Example 1: schema-bound triage
Example one, simple. A Zapier or Make workflow receives support emails and calls a language model API directly with a schema: category, sentiment, and whether a refund is requested, true or false. Because the output is schema-bound, a filter can reliably route refund requests to the finance queue. No regular expressions, no guessing from free text.
Example 2: London quote builder via MCP
Example two, realistic. A London agency builds an n8n workflow called create quote, taking the client name, services, monthly budget in pounds and a start date. It validates inputs, applies the rate card from a database, generates a Google Docs quote from a template and returns the link. They expose it through the MCP Server Trigger with authentication. An account manager asks their AI assistant: draft a quote for Crescent Foods, SEO and paid social, around six thousand a month, starting October. The assistant calls the tool, the pricing stays deterministic in n8n, and the manager reviews the document before sending.
Security + mistakes
Security matters most with MCP. Authenticate every MCP endpoint. Expose the minimum set of tools. Validate every input as untrusted, because an AI can be tricked into sending bad data. Require human confirmation for anything that writes or sends. And log every call. The common mistakes: parsing free text with regular expressions instead of using schemas, sending entire email threads and attachments to expensive models, and exposing broad write tools via MCP without confirmation.
Watch me do it: direct API + MCP
Watch me do it. I replace the Zapier AI step with a direct structured-output call, to compare. I start in the terminal with the curl request from the lesson text, adapted to our schema, and run it on five real messages, including one in Roman Urdu and one in Arabic. Every response parses, and the enum fields only contain allowed values. I note the token usage from each response. Then in Zapier I add a Webhooks by Zapier custom request step: method POST, the responses endpoint, the authorization header from a stored secret, and the JSON body with the lead message mapped in. The next step, a Formatter utility, parses the output text into fields. Now MCP. In n8n I open the process lead sub-workflow and add an MCP Server Trigger in front of a new small workflow called create lead, with inputs name, email, company and message, which then calls process lead. I enable authentication and copy the server URL. In my AI assistant's connector settings I add the server with the token. Then I type: add a lead, Fatima Raza from Lahore Bakes, she wants SEO help, fatima at lahorebakes dot p k. The assistant calls create lead, and I watch a new execution appear in n8n, go through dedupe, extraction, scoring and routing, and post to Slack.
Recap + try this now
Recap. Use built-in AI steps for speed and direct API calls for control. Always request schema-bound structured outputs for automation. Right-size models, trim inputs and log usage. Use MCP to expose narrow, tested workflows to AI assistants and to let your agents use external tools, securely. Try this now: take the curl example in the lesson text, change the schema to fit your own leads, run it on five real messages, and paste the working call into an HTTP step on your platform.
Try this now
Try this now. Copy the curl example from the lesson text. Change the schema to the fields your own business needs, with allowed values wherever possible. Run it on five real messages, including one in Urdu or Arabic if relevant, and check every field. Then paste the same request into an HTTP step in your platform, store the API key as a credential, map the fields into your CRM, and add a filter that routes on one of the enum fields.
Key takeaways
- Direct LLM API calls give access to new models and precise control over schemas, tools, caching and limits; built-in steps are faster to set up.
- Structured outputs (schema-bound JSON with allowed values) make AI steps reliable enough to route and write data.
- Control cost and latency by right-sizing models, trimming inputs, capping outputs, caching, batching and logging token usage.
- MCP works both ways: expose narrow workflows as tools (n8n MCP Server Trigger, Make MCP Server, Zapier MCP) and let agents call external MCP tools; secure every endpoint.
Try it
Adapt the curl structured-output example to your own lead fields, run it on five real messages, then recreate it as an HTTP step in your platform with the key stored as a credential.