Level Marketing / Articles / Running a business
Using AI through an API: tokens, integrations and cost control
In a chat assistant, you talk to the AI yourself. Through an API, your software talks to it: the CRM, a Telegram bot or the website sends the request and uses the answer on its own. That turns AI from one employee's helper into part of a whole process. Here is what an API is, how the money is counted, which integrations pay off fastest and how to brief a developer.
What an API is, in plain words
An API is a "door" through which programs talk to each other. An AI provider offers this service through its API: your program sends text (and, if needed, an image or document), and the model returns an answer. Nobody has to open a window and copy and paste.
How a chat subscription differs from an API:
| Chat subscription | API | |
|---|---|---|
| Who uses it | An employee | A program (CRM, bot, website) |
| Payment | Monthly per user | Per token used |
| Setup | Immediate | Needs a developer |
| Best for | Writing, analysis, ideas | Repetitive, high-volume processes |
| Risk | Employee error | A program error repeats many times |
Rule of thumb: if you do the same job dozens or hundreds of times a day (classifying a lead, summarising a call, sending a customer the first reply), it is time to think about an API. If every task is different, a chat subscription is enough.
How token pricing works
With an API you pay for tokens. A token is a piece of a word: a short word may be one token, a long one several. Prices are usually quoted per million tokens and have two parts:
- Input tokens: everything you send to the model, including instructions, the knowledge base, the conversation history and the customer's message.
- Output tokens: the model's answer. They are usually several times more expensive than input.
For example, Anthropic's pricing page lists separate input and output prices per million tokens (MTok) for each model. It also states that the Batch API gives a 50% discount on both input and output for non-urgent requests, and that a repeated part read from the prompt cache costs far less than the base input price. Google's Gemini API pricing separates a free and a paid tier: content sent on the free tier is used to improve Google's products, while paid-tier content is not. OpenAI's rates are on its official page. Prices change often, so always open the current page before you calculate.
One more subtlety: text with the same meaning can take a different number of tokens in different languages. Check your Uzbek and Russian texts with the provider's token counter.
Worked example: a Telegram bot
Illustrative example: a bot handles 3,000 conversations a month, with 6 requests each. Every request contains instructions and a knowledge base of 3,000 tokens, history and the message of 1,000 tokens, and a 200-token answer. Model price (illustrative): $1 input and $5 output per million tokens.
| Part | Calculation | Result |
|---|---|---|
| Number of requests | 3,000 × 6 | 18,000 |
| Input tokens | 18,000 × 4,000 | 72 million → $72 |
| Output tokens | 18,000 × 200 | 3.6 million → $18 |
| Monthly total | $90 |
Now add caching: the 3,000-token knowledge base is identical every time, and reading it from the cache costs, illustratively, 10% of the base price. Input becomes 18 million regular tokens ($18) plus 54 million cached tokens ($5.40). The total is roughly $18 + $5.40 + $18 = $41.40. One setting cut the cost by more than half.
Compare this with the benefit. If the bot turns 10 extra night-time enquiries a month into customers, and the profit per customer is 300,000 soums, that is 3 million soums, several times the API cost.
Integrations that pay off fastest
- CRM: lead classification. As soon as a lead arrives, AI tags the service, district and urgency. On choosing a CRM, see what a CRM is and which one suits a small business.
- Call summaries. The recording is transcribed, and AI writes a short summary and next step into the CRM card. More in AI call analysis.
- A Telegram or website bot. Answers to frequent questions and lead capture. The basics are in how to create a Telegram bot, and the AI part in a Telegram AI assistant.
- Grouping reviews and requests. Themes and complaint types from hundreds of reviews.
- Extracting data from documents. Filling fields automatically from an invoice or application form.
To try an API without code, first develop the task in a browser console, for example Google AI Studio or another provider's playground. Hand the developer only an instruction that already works well.
A developer brief: template
A bad brief: "Connect AI to the bot." A good brief includes the following.
| Section | What to write |
|---|---|
| Goal | Which job, with what result (for example, reply to a lead within 1 minute) |
| Input data | Where it comes from, which fields, which are confidential |
| Instructions | A tested prompt and the knowledge base file |
| Output format | Text or JSON, which fields, where it is written |
| Prohibitions | No promises on prices or discounts, stay on topic |
| Handover to a human | When and to whom (complaints, unclear questions) |
| Limits | Monthly budget, maximum answer length |
| Logging | What is recorded and how long it is kept |
| Acceptance criterion | At least 90% correct answers on 50 test examples |
The acceptance criterion is the part most often forgotten. Without it, "it works" means nothing.
Cost control
- Monthly limit. Set a spending cap and an alert in the provider's console.
- The right model. The cheapest model is often enough for simple classification; use an expensive one only for complex tasks.
- Answer length. Output tokens are expensive, so cap the maximum length.
- Caching. Cache the instructions and knowledge base that repeat every time.
- Batch. Use batch mode for non-urgent work (analysing yesterday's calls).
- Shorter history. In long conversations, send a summary rather than the full history.
- Weekly report. Number of requests, average tokens, cost per lead.
Security and data
An API key is the same as a password. Do not put it in website code or a shared file, create a separate key for each project and rotate it when an employee leaves. Before sending personal data, read the provider's business terms and strip unnecessary fields. If data must never leave the company, look at local AI models.
Common mistakes
- Counting only input tokens and forgetting output.
- Sending the full knowledge base with every request without caching.
- Opening the bot to customers without checking its answers.
- Setting no limit: a bug in the program can run up a large bill overnight.
- Accepting a project without an acceptance criterion.
Your first API project: a 4-week plan
- Week 1. Pick one process and measure the current state, for example the average reply time to a lead and how many minutes an employee spends per lead.
- Week 2. Write the instruction in a console and test it on 50 real (anonymised) examples. Log errors in a table and refine the instruction.
- Week 3. The developer builds the integration with limits, logging and handover to a human. Start in internal mode only: an employee sees the answers, not the customer.
- Week 4. Open it to customers, spot-check 10–20 answers every day and compare spending with the weekly report.
At the end of each week ask one question: did the metric improve? If there is no result after 4 weeks, the problem is usually not the model but the process itself or a vague instruction.
Questions and answers
Do we need a developer?
No-code automation services are enough for simple connections, but serious CRM integration, security and cost control need a developer.
How can we estimate the monthly cost in advance?
Estimate the number of requests and the input and output tokens per request, then multiply by the provider's current price. In the first month add a 20–30% buffer and compare with the actual bill.
Can we use a free API tier?
For testing, yes, but read the terms. Google, for example, states that free-tier content is used to improve its products, so do not send customer data there.
Do we need both an API and a chat subscription?
Often yes: staff use the subscription for daily work, and processes use the API. They cover different jobs.
Conclusion
An API turns AI from an employee's helper into part of a process, so leads, calls and requests are handled automatically. Success depends on a clear brief, an acceptance criterion and spending limits. If you want to check whether the leads from your ads are handled quickly and correctly, book a free audit with Level Marketing.