AI Hints
Home›Generative AI Tutorial›Building with APIs
Generative AI · Lesson 33 of 77

Cost, Speed and Streaming

Making AI apps practical.

⏱ 2 min read▶ Video at 1:17:36🎓 Free
Watch this lesson in the Generative AI courseWatch on YouTube ↗Full Generative AI course

A demo that works is not the same as a product that lasts. Real apps must be fast enough, cheap enough, and reliable. In this lesson, you will learn how to estimate cost, how to speed things up, and why streaming makes apps feel instant.

Cost, Speed and Streaming
From the video: Cost, Speed and Streaming
  • Estimate the cost
  • Make it faster
  • Stream for a better feel

How pricing works

Most providers charge per token, with separate prices for input tokens, the text you send, and output tokens, the text you receive. Output usually costs more. A short question and answer costs a tiny fraction of a cent. But a long document, sent a thousand times a day, adds up. So estimate before you launch. Count the tokens in a typical request, multiply by the price, and by your expected number of users.

Priced per tokeninput and output separately
Output costs morethan input, usually
Tiny per requestbut it adds up at scale
Estimate firsttokens x price x requests

Speed and savings

There are many ways to save time, and money. Use a smaller model for easy tasks. Keep prompts short, and cut repeated instructions. Cache answers to common questions. Ask for shorter outputs, when long ones are not needed. And process big jobs in batches. A smart design can cut costs by an order of magnitude, with no loss of quality.

Smaller model for easy tasksbig models only when needed
Shorter promptsdrop repeated text
Cache common answersdo not pay twice
Shorter outputssay how long to reply
Batch big jobscheaper and tidier

Streaming responses

Waiting for a full answer can take many seconds. Streaming fixes that feeling. Instead of waiting, the server sends the answer token by token, as it is produced, and your app shows each piece at once. The total time is the same, but the first words appear almost immediately, so the app feels fast. This is why chat tools type out their answers.

  1. Request sentthe user asks
  2. First token arriveswithin a moment
  3. Tokens keep flowingshown as they come
  4. Complete answerfeels fast throughout
Same total time, much better feel
Streaming responses
From the video: Streaming responses

Summary

Good. Costs depend on tokens, so estimate early. Save with smaller models, shorter prompts, caching, and batching. And stream replies, so apps feel instant. You can now build a real chatbot. Next, we give it knowledge of your own documents, with embeddings, and retrieval.

Key takeaways
  • Pay per token: input and output
  • Smaller models, shorter prompts, caching
  • Stream for a fast feel
Next up: Search by Meaning — embeddings in action