Module 5 · Page 3 of 5 · Advanced topic

Put AI inside your solution

So far, you've used AI to help you build applications. But the applications themselves don't necessarily use AI. What if your dashboard could explain trends or your survey tool could summarize feedback? In this lesson, you'll learn how an application connects to an AI model, and what to consider before giving that feature to users.

Using AI to build vs. building something that uses AI

Recall the coffee shop dashboard from Module 4. An AI coding agent helped you build charts, filters, and calculations. Once the dashboard is finished, those features can work without calling an AI model.

Now imagine adding a button labeled Generate AI insights. When the manager clicks it, the dashboard sends selected sales metrics to an AI model and displays a short written interpretation. The application itself now uses AI.

Built with AI: Claude Code helps you create a dashboard. Users explore charts and metrics calculated by ordinary code.

AI inside the product: The dashboard offers a feature that contacts an AI model to generate explanations for its users.

Adding AI is a choice, not an automatic improvement. If a feature can be handled more accurately and cheaply with a simple formula or rule, use that instead.

What is an API?

An API (application programming interface) is a way for one software application to request information or services from another. For example, a weather app might use an API to retrieve a forecast. Your dashboard can use an AI provider's API to request a written summary.

Manager clicks “Generate AI insights”
                  ↓
Your application sends sales metrics + instructions
                  ↓
          AI provider's API
                  ↓
        AI generates a response
                  ↓
Your application displays the summary

Four terms are useful to know:

API: The interface through which software systems communicate.

Request: The data and instructions your application sends.

Response: The information or output the service returns.

API key: A secret credential used to authenticate requests to a service.

Cost Using an AI model through an API may require separate billing, even if you already subscribe to a consumer AI chatbot. Check the provider's current pricing and set a small budget before experimenting.

How does an AI-powered website work?

In the previous lesson, you published a website through GitHub Pages and explored Vercel. GitHub Pages works well for websites that run entirely in the browser. But a website that calls a paid AI API usually needs a server-side component.

Why not just put the AI provider's API key into the website's JavaScript? Because code delivered to a visitor's browser can be inspected. Someone could copy the key and use it at your expense.

User's browser (frontend)
  Clicks “Generate AI insights”
                ↓
Your server-side function (backend, on Vercel)
  Validates the request; accesses a secret API key
                ↓
AI provider's API
  Generates a summary
                ↓
Your server-side function
                ↓
User's browser displays the summary

A frontend is what users see and interact with in their browsers. A backend handles tasks on the server, including securely calling outside services. Vercel can run server-side functions without requiring you to manage a conventional server yourself.

An environment variable can supply a secret, such as OPENAI_API_KEY, to server-side code. The key must never be included in client-side code, a public configuration variable, or a Git commit.

Important A hidden API key is necessary but not sufficient. If anyone can freely call your backend endpoint, they may still generate charges through it. Public AI features also need suitable access restrictions, request limits, and other safeguards.

Example: Add AI insights to a sales dashboard

Let's add one narrowly defined feature to the coffee shop dashboard. When the user clicks Generate AI insights, the app sends a few already-calculated metrics and asks for a concise interpretation.

Illustrative dashboard metrics

This week's revenue: $8,450
Change from last week: -8%
Number of orders: 632

Example response: “Revenue declined 8% from last week. This could reflect fewer orders or a lower average order value, but the current figures do not establish which. Compare order counts and average transaction values across the two weeks before deciding on an intervention.”

The numbers and response above are hypothetical, not a live AI result.

Notice the division of labor: ordinary code calculates the metrics, while the AI model helps explain them. The model should distinguish facts supported by the data from hypotheses that need further investigation.

Ask your coding agent to plan the feature

You don't need to write the API integration yourself. Your job is to specify the expected behavior and review the agent's implementation plan.

Prompt
I have a coffee shop sales dashboard deployed on Vercel.
I want to add a button called “Generate AI insights.”

When clicked, it should send selected, pre-calculated
sales metrics to an AI model and display a concise
management summary.

Before coding:
1. Inspect the project and propose the simplest design.
2. Explain exactly what data will leave the application.
3. Explain the frontend, backend, and API request flow.
4. Explain how you'll protect the API key and restrict
   usage to avoid unexpected costs.
5. Identify likely errors and how the UI should handle them.

Keep numerical calculations in ordinary code. Ask the
model to distinguish observations from possible causes.
Do not expose secrets, commit credentials, or deploy
changes without my approval.

Then implement and test

After reviewing the plan, ask the agent to implement the feature. Depending on the project, it may use an official provider SDK or a library that supports multiple providers. You don't need to memorize the implementation syntax, but you should understand the basic architecture.

Follow-up prompt
Implement the approved plan, using a server-side function.
Do not put the API key in frontend code or in Git.

Then help me verify:
- The summary reflects the actual dashboard metrics.
- Missing or unusual data is handled appropriately.
- The interface handles slow or failed requests clearly.
- Access and request limits work as intended.
- The deployed feature works, not just the local version.

Show me what changed before committing or deploying.

For this exercise, use synthetic or otherwise shareable data. If an API key or account setup is unavailable, you can still ask the agent to implement the interface using a clearly labeled mock response and verify the flow without making real model calls.

What changes when other people use your AI feature?

An AI feature introduces a different set of responsibilities from a chart or calculator. Before publishing, ask:

Accuracy: Does the response match the numbers? Does it invent explanations not supported by the data?

Privacy: What information is sent to the model provider? Is it appropriate to share?

Cost: Could repeated or automated requests create unexpected charges?

Security: Are credentials protected? Can the endpoint be abused?

User experience: What happens if the request fails, is slow, or returns an unhelpful response?

For the sales dashboard, a good design sends only the summarized metrics necessary for the task. It avoids unnecessary customer-level data. You can also limit who can use the AI feature, restrict request frequency, and show a clear error message when the API is unavailable.

Remember the verification principle from Module 4: working code does not imply a trustworthy answer. Test both the software and the quality of the AI-generated content.

Exercise: Add one AI-powered feature

Start with a simple application, ideally one already deployed to Vercel. Choose one narrow feature rather than building a general-purpose chatbot.

  1. Choose a use case. For example, summarize dashboard trends, categorize customer feedback, or generate a study plan from tasks and deadlines.
  2. Plan. Ask the agent what data the feature needs, what it will send to the model, and how the server-side connection will work.
  3. Review safeguards. Check how the API key, privacy, access, and potential costs will be handled.
  4. Build and verify. Implement the feature (or a clearly labeled mock version), then test at least three cases: normal input, missing data, and unusual input.
  5. Deploy and check. If using a real API, deploy the approved version and verify the live feature. Do not publish an unrestricted, billable endpoint.

Reflection: What does AI contribute that a simpler rule-based feature would not? Which parts of the AI-generated output must be verified before users rely on them?

Takeaway AI can help you build an application, and an application can also use AI. The second requires an API connection, careful deployment, and ongoing attention to accuracy, privacy, security, and cost. Add AI when it solves a real user problem—not simply because you can.
Next · Optional extension · Page 4 of 5
Extend your agent: Skills and MCP
→