LESSON 186 / 215·2 min readIntermediate

Cost optimization

ReferenceReference guide
01 Understand02 Recall03 Prepare

Words made simple

A few useful meanings before you read the explanation.

AI
Software techniques for tasks such as recognizing patterns, understanding language or generating content.
API
A way for one piece of software to ask another for data or an action. A claims API might return the current status of a claim.
Token
A small piece of text processed by a model. It may be a whole word, part of a word, or punctuation.
More words from this lesson
Embedding
A list of numbers that represents the meaning of some content. Similar meanings can produce nearby lists of numbers.
Agent
An application that uses a model to choose its next action within defined limits. It can use tools and continue through several steps.
Tenant
A customer or organization whose data must stay separate from other customers in a shared application.
Latency
How long a request takes to return a result. Lower latency usually means a shorter wait for the user.
Dependency
A library or package that your application relies on. Compatible versions help the application run as expected.

Beginner — What determines AI cost?

  • Input/output usage, model pricing, tool/search calls, embeddings, retries, and infrastructure.
  • Human review and failed tasks also matter.
  • I calculate total cost per completed useful task rather than only one API call.

Intermediate — When is semantic caching unsafe?

  • When similar requests differ in tenant, user permissions, policy version, date, or personalized facts.
  • I restrict it to suitable stable tasks and include freshness and scope dependencies; exact caches also require proper keys and invalidation.

Senior — How do you optimize without hurting quality?

  • Establish a quality/security baseline, measure the expensive stages, and experiment with routing, context reduction, batching, or caching.
  • Release only when held-out outcomes, tail latency, and privacy requirements remain acceptable.

Scenario — Five agent steps became fifty after a change. What happens?

  • A strict step/time/token budget stops the run and reports a supported fallback.
  • I inspect progress and repeated calls, compare prompt/tool changes, and track long-tail cost rather than allowing an expensive loop to continue.
PAUSE & RECALL

Can you explain it without the notes?

Cost optimization

Use your own words. Explain an example and one limitation before checking the explanation.

Check your explanation

Beginner — What determines AI cost?

CONNECT IT TO YOUR INTERVIEW

Turn this concept into a clear answer.

Practice this concept
YOUR NEXT STEP

Keep connecting the ideas.

Next lesson: Python

Adapted from 13_AI.MD · “29.17 Cost optimization”. Examples are study fragments; framework behavior can depend on your version.