Adding a GPT model to your product is easy to demo and surprisingly hard to run well. A prototype that answers a question takes an afternoon. A feature that stays accurate, affordable, private and available for real customers takes planning.
This guide covers the decisions that matter, in the order they usually come up: whether an API is the right tool, how to design the feature, and how to keep it safe and reliable once people depend on it.
When an API is the right choice
Use a hosted model API when the task involves language and a good-enough answer is valuable. That includes summarising, drafting, classifying, extracting details from messy text, answering questions about documents and translating. These are jobs where rules-based code struggles and where a person can quickly check the result.
An API is a poor choice when you need the same exact answer every time, or when the logic is already clear. Calculating an invoice total or applying a tax rule should stay as ordinary code. A model can sit beside that code, for example by reading an email and filling in a form, but it should not decide the amount.
A simple test helps: “If this answer is wrong now and then, what happens?” If a user edits it or a human approves it, an API is a good fit. If money moves or someone could be harmed, add review steps or keep the model out of that step.
Calling a provider is also the fastest route for a first release. Running your own model can wait until strict data rules or very high volume demand it. The advice in How to build an MVP applies: test the riskiest assumption with the smallest build.
Design prompts like product requirements
A good prompt is a short specification, not a clever phrase. Store it in version control and change it with the same care as code. Strong prompts usually contain:
- Role and goal: what the model is doing and for whom.
- Rules: what it must always do and never do, in plain sentences.
- Context: the facts it needs, supplied by you rather than guessed.
- Format: exactly what the output should look like.
- Examples: two or three sample inputs with the output you want.
Be explicit about what to do when the model does not know. Tell it to say so, or to return a specific “unknown” value. Without that instruction it will often fill a gap with something plausible.
Keep your instructions separate from user input, and treat anything a customer types or any document you load as data. People will try to override instructions, so never let model output trigger a sensitive action without checks in your own code.
Get structured outputs, not free text
If your software needs to act on the result, ask for structured data such as JSON instead of a paragraph. Free text is fine in a chat window but fragile when another part of your system has to read it.
Most major providers let you constrain the response to a schema you define. Use it, then validate the response in your own code anyway, because a valid shape does not guarantee a sensible value. For example:
{
"category": "billing | bug | feature_request | other",
"urgency": "low | medium | high",
"summary": "one sentence"
}
Use closed lists of allowed values so the model picks from your categories instead of inventing new ones. If validation fails, retry once with the error message, then fall back to a safe default or a human queue. Never pass unchecked output into a database, a payment or an email to a customer.
Use retrieval to answer from your own data
A model knows only what it was trained on plus what you put in the prompt. It does not know your pricing, your policies or last week’s documents. The usual fix is retrieval: when a question arrives, your system finds the most relevant passages from your own content, includes them in the prompt and asks the model to answer from that material only.
For question answering this is often better than fine-tuning. Your content can change without retraining, you can show the source of each answer, and you can restrict who sees which documents. Our guide on What is RAG explains the mechanics. In practice:
- Clean your sources first. Outdated or contradictory documents produce outdated or contradictory answers.
- Split content sensibly into meaningful sections, not arbitrary slices.
- Respect permissions. Filter retrieved content by what the current user may see before it reaches the prompt.
- Cite, and allow “I don’t know”. Show the passages used, and let the system decline when nothing relevant is found.
Keep the API key on the server
Your API key is a credential that spends money, so it must never reach a browser or a mobile app. Anything shipped to a device can be extracted, and a leaked key can be used by strangers at your expense.
The safe pattern is that your app calls your own backend, and your backend calls the provider. That backend is where you:
- Authenticate the user and check what they are allowed to do.
- Apply limits for each user or account.
- Build the prompt, including any retrieved content.
- Call the model and validate the response.
- Log what happened, without storing more personal data than you need.
Keep keys in your hosting platform’s secret settings, never in the repository. Use separate keys for development and production, and rotate one immediately if you suspect a leak. The rule is the same for mobile apps: they talk to your server, not directly to the provider.
Control cost and rate limits
Usage is billed by how much text goes in and comes out, so cost grows with traffic and prompt length. Plan for it before launch. The levers that matter most:
- Choose the smallest model that does the job. Tasks like classification often work well on a smaller, cheaper one.
- Keep prompts lean. Long histories and oversized documents are the most common source of waste.
- Cap output length so one runaway response cannot cost a lot.
- Cache repeated work instead of paying twice for the same answer.
- Limit per user so one account or script cannot drain your budget.
- Set spending alerts and a hard limit in the provider’s dashboard.
Providers also enforce rate limits on requests. Queue non-urgent work, retry with increasing delays after a “too many requests” response, and avoid sending bursts. Track cost per feature from the start, so you know which parts of the product earn their running cost.
Evaluate and test before you ship
Model output varies, so ordinary unit tests are not enough. You need an evaluation set: realistic inputs, each paired with what a good answer looks like. Build it from real examples, covering typical requests, awkward ones, edge cases and attempts at misuse. Include cases where the right answer is “I can’t help with that.”
Run the whole set whenever you change the prompt, the model or the retrieval setup, and compare results. Score what you can automatically, such as schema validity, the correct category or a required fact. For open-ended answers, have a person review a sample. Decide in advance what “good enough” means, so a change is accepted or rejected on evidence.
After launch, add a thumbs up or down, review a sample of real conversations with proper privacy controls, and turn every failure into a new test case. Providers update and retire models, so re-running your tests also tells you when a change on their side has affected you.
Protect privacy and handle data carefully
Treat every prompt as data leaving your system. Decide what the model really needs to see, and remove names, account numbers and other personal details when the task does not require them.
Read the provider’s current data terms for the plan you use. Check whether inputs are used for training, how long they are retained, where they are processed and what stricter options exist. These differ between plans and change over time, so confirm rather than assume.
If you handle health, financial or children’s data, or operate under rules such as GDPR, involve whoever owns compliance early. Update your privacy policy, tell users when they are talking to a machine, and offer a way to reach a human. Keep logs short-lived and access-controlled, because stored prompts often contain exactly the information you were trying to protect.
Plan for the API being down
Any external service will occasionally be slow, rate-limited or unavailable, so decide what happens before it does.
- Set timeouts so a slow call fails quickly instead of freezing the screen.
- Retry sensibly for temporary errors, with delays, and stop after a few attempts.
- Degrade gracefully. If the AI summary fails, show the original text. If the assistant is down, show a contact form.
- Keep a backup path. For important features, configure a second model or provider you can switch to.
- Queue background work so tasks finish later instead of being lost.
- Monitor and alert on error rates and response times.
The AI feature should enhance your product, not hold it hostage. Logging in, paying and saving data should keep working when the model does not.
Avoid vendor lock-in
Lock-in happens when your code, prompts and data become so tied to one provider that leaving is painful. You cannot remove the dependency entirely, but you can keep it small.
Put every model call behind one internal interface in your backend, so the rest of the product asks for “a summary” or “a classification” and does not care who supplies it. Keep prompts and schemas in your own files, store documents and retrieval data in formats you control, and keep your evaluation set, because it lets you compare a new provider fairly.
Then test an alternative now and again. If swapping a model means running your evaluation set and changing a setting, you have a way out if quality, terms or pricing change. Use provider-specific features only where the benefit is clear and you have accepted the trade-off.
Getting started
Begin with one narrow, low-risk feature, build the server-side wrapper, write your first evaluation set and launch to a small group. Expand once the results and costs are clear.
If you want help scoping an AI feature or building it safely into an existing product, talk to our team. Our AI development and ChatGPT development services cover everything from a first prototype to a production rollout.
Frequently asked questions
Is it safe to send customer data to an AI API?
It can be, if you plan for it. Send only what the task needs, remove personal details where possible, and read the provider's current data terms for your plan. For regulated data such as health or financial records, involve your compliance lead before you build.
Should I fine-tune a model or use retrieval?
Start with retrieval and good prompts. Retrieval uses up-to-date company content, shows sources and respects access rules. Fine-tuning suits a consistent style or format, and it rarely helps a model learn facts that change.
Can I call the API directly from my website or mobile app?
No. Doing so exposes your key, and anyone who finds it can use it at your expense. Route every request through your own backend, where you can authenticate users, apply limits and keep the key secret.
How do I stop the model from making things up?
You cannot eliminate it, but you can reduce it. Supply the facts in the prompt, tell the model to say when it does not know, require citations, validate outputs and keep a human in the loop for important decisions.
How do I keep costs under control?
Use the smallest model that meets your quality bar, keep prompts short, cap output length, cache repeated answers and set per-user limits. Add spending alerts in the provider's dashboard and track cost per feature.
What happens if the provider changes or retires a model?
Your product should not break. Keep model calls behind one internal interface and maintain an evaluation set, so you can test a replacement quickly and switch with confidence.
Have a project in mind? Let’s talk it through.
Tell us what you’re building. The first conversation is free, and you’ll leave with a clear next step.
Start your project













