Execution (3): Adding AI Features to Your Product#

If the previous chapter was about “building a product with agents,” this chapter is about “putting AI inside the product.” They are different problems. The former is about the tools I use; the latter is about the structure and cost of my product calling a model on behalf of its users. In a one-person startup, mixing the two breaks your cost structure, and separating them simplifies your design.
Separate the Two Kinds of AI Cost#
As Services and Tools, Chapter 2 said, a coding agent’s monthly subscription is so much cheaper than consuming the same volume through the An agreed-upon window through which programs exchange functions with each other. Think of a restaurant: the customer (your program) does not walk into the kitchen (the AI model) but orders from a set menu in a set way and gets the result back. AI companies open their models through APIs, and developers pay for the amount they request. A party that is neither the company that built the service nor the user. Here it means apps or services made by companies other than the model provider. Information that proves who you are when you access a service: passwords, API keys, login tokens, and the like. If they leak, someone else can use the service with your permissions, so they are kept separately rather than in the repository. A usage allowance deducted in place of money when you pay for API use. You can use the API up to the amount you have topped up or received as a benefit, and once it runs out you have to top up or pay more. Credits bundled with a subscription are granted as a fixed amount each month and often do not roll over to the next month. The easy route taken to move fast now, left behind like a debt to be repaid later. It may run fine today, but when conditions change, fixing it costs far more than it would have at the start. Like a debt that accrues interest, the longer you put it off, the harder it is to pay back.
So the principle is simple. Use subscriptions for development and conversation that a person performs directly, and from day one treat API cost as cost of goods for everything the product calls on behalf of users. The rest of this chapter is about who you make pay that API cost, and how to design and reduce it.
AI Features Cost Money Every Time They Run: Design Billing from Day One#
A product with AI features has a different cost structure from traditional software. With traditional A way of offering software that you use over the internet without installing it, for a subscription fee. Services such as Notion and Slack are typical. Once built, adding users costs little extra, so the strategy of gathering users for free and then converting some to paid worked well.
This structure creates two problems.
- Free users cost money too. If you open the product for free, cost grows along with the number of users. It can become a structure where the better the response, the bigger the loss.
- Heavy users create losses. People who pay the same price use very different amounts. With a single flat-rate plan, a small number of heavy users can use up what everyone else paid. Agent features repeat model calls several times within a single request, which widens this gap further.
So a product with AI features has to settle its business model before launch. There are four things to decide.
- Who pays the cost. Decide whether users pay directly, whether advertisers or business customers pay, or whether the user’s agent calls the model so that the user’s own subscription pays (see the “Distribution” section below).
- What unit you charge for. Options include a monthly subscription with a usage limit, prepaid credits, pay-as-you-go, and users connecting their own API keys. Whichever you pick, the key is to make the unit of price and the unit of cost move together.
- How far free use goes. Cap free trials by period or by count, and put lighter models on the free tier. Treating free use as “the cost of getting the product known” and giving it a separate budget makes the decisions easier.
- When to add payments. Payments look like a feature you can bolt on later, but they come with plans and limits, usage metering, refunds, and tax handling. If you attach a
A service that takes over payment processing such as card payments, recurring billing, and refunds. Stripe is a typical example, and some services even handle taxes such as country-by-country VAT on the seller’s behalf. Since you never handle card details yourself, the security burden also drops sharply.
from the start and record usage per user, you also have evidence when you later change prices.
I think this is the biggest wall a one-person startup has to get over. Building has become something you can do alone with agents. But the cost of AI features goes out from the first user, while revenue comes in only after users have confirmed the value. Unlike a company that bridges that gap with investment, an individual has to bridge it with their own money. So it is not “build a good product and the money will follow”; the structure for getting paid has to be part of the product design. The cost-cutting techniques in the rest of this chapter widen the margin on top of that structure; they cannot replace it.
Architecture: Calls on the Server, Models as Parts#
The basic structure for putting AI in a product is the “user app ↔ my server ↔ model API” we saw in Services and Tools, Chapter 2. On top of it, there are three design principles a one-person startup should follow from the start.
First, API keys live only on the server. Calling the model directly from the client exposes the key, makes usage impossible to control, and reveals your prompts and logic as-is. Every call goes through the server, and the server handles usage limits, logging, cost aggregation, and caching. Even for features where the browser must connect to the model directly, such as real-time voice, the server issues a short-lived temporary token instead of handing over the real key.
Second, wrap model calls in a single Middle code that connects different formats. Like a travel power adapter, your service always requests “generate an answer” the same way, and the adapter converts that request into the format of OpenAI, Anthropic, or Google. When you switch providers you only fix the adapter, and the rest of the code stays untouched. The code that holds the rules for what the product actually has to do, for example “free users get up to ten uses a day” or “answers come with their source documents.” If you keep it separate from screens and connections to outside services, these core rules can stay the same even when everything around them changes. A bundle of tools and code that makes a particular service or platform easy to use. Calling an API directly means matching request formats and authentication by hand, while an SDK lets you do the same thing with a single function such as A feature in which the model provider briefly stores the opening part that is identical across many requests (system instructions, a long reference document, and so on) and reuses it. Re-reading the stored part is billed at a much lower rate than regular input, and responses get faster too. That is why the basic cost-saving rule is to put unchanging content at the front of the prompt and content that changes every time at the end. Whether it applies automatically or must be marked explicitly differs by provider. A service or library that puts a single entry point in front of the APIs of several model providers and routes each request to the model you want. OpenRouter and LiteLLM are examples. You call it in one format and the gateway converts it to each provider’s format, and it often also offers usage tracking and failover to another model.client.responses.create(). OpenAI, Anthropic, and Google all provide SDKs for major languages such as Python and JavaScript.
Third, decide a tier for each call site. Even within one product, classifying user queries, summarizing documents, and generating the final answer require different levels of intelligence. Use the top-tier model for every call and your costs multiply; use a Model providers release models of the same generation in several tiers by size and price. Lightweight models are cheap and fast but weak at complex judgment, top-tier models are the smartest but expensive and slow, and balanced models sit in between. The names differ by provider, but they usually fall into these three levels.
| Call site | What it does | Tier | Cacheable prefix | Budget cap |
|---|---|---|---|---|
| Intent classification | Sort user input into a few types | Lightweight | System instructions + classification criteria | Very low |
| Document retrieval summary | Summarize chunks found via When a question comes in, the system first searches for relevant documents, then gives what it found to the model along with the question so the model answers from it. This lets answers draw on recent information or internal company documents the model was never trained on, and with the evidence right in front of it, the model is less likely to make things up. Since you only change documents instead of retraining the model, it is the first method to consider when connecting your own data to AI. Its structure and limits are covered in detail in the next chapter. | Lightweight or balanced | System instructions | Low |
| Answer generation | Final answer grounded in evidence | Balanced | System instructions + fixed documents | Medium |
| Complex analysis · planning | Multi-step reasoning and tool calls | Top-tier | System instructions + tool definitions | High, with a per-task cap |
The Heart of Cost Design: Prompt Caching#
Key AI Concepts, Chapter 1 said that a token is both a unit of length and a unit of currency. Once you put AI in a product, you learn that most of that currency goes to input tokens, and in particular to the leading part that repeats on every request: system instructions, tool definitions, fixed documents. Agent features are worse, because they resend the entire history every turn. Prompt caching is a feature where the model provider stores that repetition and charges a much lower rate for it, and used properly it removes a large share of input cost.
The most important fact I learned from digging deep into caching is that caching works on The part of a text that runs from the very beginning. Prompt caching checks how far a new request is identical to a previous one from the very start, and reuses the stored computation only up to that point. If even one character differs in the middle, everything after it is not reused, even if the content is the same.
Ranked by impact, the practical rules come out as follows.
- Treat system instructions as a build-time constant. The moment you put values like the current time, the user’s name, or a session ID into the system instructions, your
The share of the total input that was reused from the stored cache. A higher hit rate means more of the input is charged at the cheaper rate, and a sudden drop is a sign that the front of the prompt is changing every time.
becomes permanently zero. This one mistake was the most common thing separating 0% from 90%. - Fix the tool list so it is shared by all users. Tool definitions sit at the very front, so if you split the list by permission there is no way to recover. Give everyone the full set, and check permissions in the
The code on your server that receives the model’s request, “run this tool with these values,” and actually runs the tool. The model cannot run tools itself and can only ask, so checks that must always hold, such as permission checks, belong here.
. If you have so many tools that their definitions alone make the front of every request heavy, look into the tool search feature of the model API. You register every tool but show the model only a few frequently used ones from the start; the rest enter the context only after the model searches for them by name and description mid-task and picks them. The Anthropic and OpenAI APIs support it, and because the definitions loaded through search do not change the tool list at the very front, the cache does not break either. - Make
Turning data inside a program into text such as JSON to send it out. Even the same data produces different text if the order of fields or the spacing varies from run to run; making the output always identical is called “deterministic.”
deterministic. The cache key is the rendered bytes. If JSON key order wobbles, the same content becomes a different prompt. - Only append to conversation history. Editing or trimming the middle invalidates everything after that point.
- Put search results at the very end. If something that changes with every query sits in front, everything behind it is recomputed every time.
And there is one trap. The cache hit rate is not the goal. A hit rate is a ratio; cost is an absolute. Carry a long history around and the hit rate approaches 99%, but the cost per request keeps rising. The cache discount applies equally to both sides, so a context ten times larger is still ten times more expensive after the discount. Use the hit rate as a diagnostic that catches “is the prefix wobbling,” and judge the final cost by total context volume. Whether to summarize and compress a long conversation is decided not by the hit rate but by “compression cost versus the cumulative savings afterward.” Depending on the provider and model, cache reads can also count in full against The cap on how many requests or tokens an API account can send in one minute. Requests beyond it are rejected, so your service can stall at times when users crowd in. The limit rises with the account’s usage history and pricing tier.
In other words, raising the cache hit rate and shrinking the context itself through Summarizing the earlier part of a conversation into something shorter when what you send to the model has grown too large. Sending less helps cost and speed, but summarizing also costs a model call and can lose some details.
Beyond caching, there are two more. Work that does not need a real-time response (overnight aggregation, bulk classification) can go through the A way of handing over non-urgent requests all at once and receiving the results later. Instead of an immediate answer, requests are usually processed within 24 hours, and in return the price is discounted by about half. It suits work users do not wait on, such as classifying or summarizing thousands of documents.
Where to Run It: Public APIs and Managed Platforms#
Most one-person startups can start with a model provider’s public API. It is the easiest, and you get the latest models immediately. But once your customers are companies and they start asking “does our data leave the building,” you have to move toward the right side of the deployment spectrum we saw in Services and Tools, Chapter 2.
Knowing precisely what a A service in which a cloud company runs and manages AI models for you. Amazon Bedrock, Google Cloud’s Gemini Enterprise Agent Platform (formerly Vertex AI), and Microsoft Foundry are typical examples, and you can use models from several companies just by calling an API, without preparing servers yourself. Because the models run inside that cloud, a company already using it can easily keep data management and security policies in one place. The vast set of numbers a neural network obtains through training; everything the model has learned, its knowledge and abilities, is stored in these numbers. You can think of them as the same thing as the parameters covered in Key AI Concepts, Chapter 1, and a large model has hundreds of billions or more of them. With the weight files alone you can run the exact same model again, so publishing the weights means handing over the model itself. A geographic unit in which a cloud company operates a cluster of data centers. Regions are divided into places such as Seoul, Tokyo, and US East, and the region you choose determines which country your data is physically stored and processed in. If you handle data with restrictions on cross-border transfer, such as personal or financial data, the choice of region can become a contract condition. A record kept in time order of who accessed which data, when, and what they did. It is used to trace the cause after an incident or to prove that rules were followed. Business customers often check for it in security reviews. A certification in which an outside auditor confirms that a company’s security and data management meet a set standard. SOC 2 and ISO 27001 are typical, and business customers often ask about them before signing a deal.
Managed platform base pricing is usually the same as or close to the model provider’s direct API. Endpoints that pin processing to one region can carry a small premium, though, and new models or beta features sometimes arrive later than on the direct API. Still, you get the security guarantees without much extra cost, so if you have A business model in which a company serves other businesses rather than individual consumers. Contracts are larger and last longer, but they come with demands individual customers never make, such as security reviews and contract terms. Serving individuals is called B2C.
Adding an Agent to Your Product: Borrow the Execution Environment, Build Only Your Product’s Core#
To put “a feature that does work for the user” rather than “a feature that answers questions” into your product, you need an agent: a feature that, for a task the user hands over, finds material, creates files, runs commands, and checks the results. It needs an agent loop that calls the model repeatedly and runs tools, a sandbox, an isolated workspace where damage stays contained even if the agent makes a mess, and the infrastructure that actually runs the tools. As the previous chapter said, building this from scratch is irrational for a solo developer. There are two ways to borrow what already exists.
The first is to run a coding agent on your own server. You call an agent such as Claude Code or Codex through its SDK and run it in an isolated workspace you prepare (a A technology that bundles a program and the environment it needs, and runs it in a space separated from everything else. Docker is the representative example. Inside a container only the folders you connect (mount) are visible, so it is used to narrow the agent’s range of access.
The second is to use a hosted service where the model provider also takes care of the execution environment. Anthropic’s Managed Agents is an example. The developer only decides which model gets which instructions and tools, and which packages, network permissions, and A general term for values that must not leak, such as API keys, passwords, and access tokens. If such a value leaks, anyone can use services with your account or access your data. Agents often see secrets while reading configuration files during work, so you need safeguards that stop them from sending those values out in logs or external requests.
I compared whether the A structure in which several agents with different roles divide up and handle work together. For example, one plans, one looks up material, and one reviews the result. It handles complex work better than giving everything to one agent, but you have to design the handoffs and coordination between agents.
- What you lose: In the system we built, when the agent calls a tool, a function inside the same program runs right away. With a hosted service, if the tool lives on your server, the request has to travel over the network, which can be slower. And some branching you used to define precisely in code, like “if this result comes back, go to A, otherwise B,” may have to be written as instructions and left to the model’s judgment. Some features are still in beta.
- What you gain: Deployment finishes with a single API call, and you do not have to write code to save task state or recover from failures yourself. For someone running things alone, that is a big advantage.
Whichever way you choose, what you have to build yourself is the same: the screens and flows users see, the structure that decides which tasks need a person’s approval, work records, per-user cost limits, security rules, and the data of your own field. Even if you borrow the machinery the agent works with, these are what set your product apart.
Distribution: Bringing Your Product into the User’s Agent#
Finally, there is an option that runs in the opposite direction from putting AI into your product: bringing your product into the AI. The MCP server from Key AI Concepts, Chapter 2 is the channel. Expose your service’s data and features as an MCP server, and users call your product from inside the agents they already use, such as Claude, ChatGPT, and Cursor. The user does not need to open a new app, and you do not need to build a separate one. For features that need a screen, such as tables or buttons, An official MCP extension that lets an MCP server send not only text results but also a small interface, such as tables, buttons, and input forms, to be shown inside the chat window. In AI services that support it, users can operate that interface directly without leaving the conversation.
This direction is attractive for two reasons. First, distribution cost. Instead of acquiring users from an app store or search, your feature sits inside the agent where the user spends the whole day. Providers also run directories that gather A feature that connects external services such as Google Drive, mail, or calendar to an AI service. Most are built on MCP, and once connected, the agent can find and upload files in that service directly.
Of course, opening an MCP server brings security responsibilities. Who reads and writes your data with what permissions, how to prevent mistaken calls by agents, and how to limit usage are covered in the next chapter.
Checklist#
- Track subscriptions (my tools) and the API (product cost of goods) in separate cost accounts.
- Before launch, decide who pays the AI cost, what unit you charge for, and how far free use goes, and attach payments and per-user usage records from the start.
- Keep API keys only on the server, and route every call through the server.
- Wrap model calls in a single adapter layer, and decide a tier and a budget cap for each call site.
- Stack the prompt in order of rate of change. Put no variable values in the system instructions, and put search results at the very end.
- Judge cost by total context volume, not by cache hit rate.
- Send non-real-time work through the batch API.
- Once B2B customers appear, open the managed platform route in the adapter, and check the data handling terms of the models you plan to use.
- For agent features, borrow the execution environment and build only your product’s core, such as approval, cost limits, and work records.
- Consider exposing your data and features as an MCP server as a distribution channel.