Velamuvi AIAcademy

Lesson 4 of 5 · Agency

Cost and Latency Trade-offs

Estimate what agentic AI costs and how long it takes: model calls, growing context, model size, parallel steps and caching, and how to make agents cheaper.

  • 5 min read
  • Intermediate
  • Reviewed
In this lesson you will learn
  • Estimate the cost and response time of different designs
  • Explain why agent costs grow faster than the number of steps
  • Choose models of the right size for each step
  • Apply the main techniques for reducing cost and latency

Where the money and time go

Every model call costs money (tokens in and out) and time (the model generating, plus tools running). Agentic designs multiply both: more calls, and each call carries a longer history.

Comparing designs

The prices below are made-up round numbers for a “large” and a “small” model; check your provider's real prices. The shape of the results is what matters:

Try it yourselfPython
# Example prices and speeds (made-up round numbers: check your provider's real ones)
MODELS = {
    "large": {"in": 3.00, "out": 15.00, "secs_per_call": 6.0},   # $ per million tokens
    "small": {"in": 0.25, "out": 1.25, "secs_per_call": 1.5},
}

def run_cost(calls, model, base_in=2000, growth=800, out=300, parallel=1):
    m = MODELS[model]
    tokens_in = sum(base_in + growth * i for i in range(calls))          # history grows each call
    cost = tokens_in / 1e6 * m["in"] + calls * out / 1e6 * m["out"]
    seconds = (calls / parallel) * m["secs_per_call"]
    return cost, seconds

designs = {
    "Single call (large)":                    run_cost(1, "large"),
    "Workflow: 3 calls (small)":              run_cost(3, "small", growth=0),
    "Workflow: 3 calls (small, 2 parallel)":  run_cost(3, "small", growth=0, parallel=1.5),
    "Agent: 10 steps (large)":                run_cost(10, "large"),
    "Agent: 10 steps (small)":                run_cost(10, "small"),
}
print(f"{'Design':<38} {'cost/run':>9} {'time':>7} {'cost per 100k runs':>19}")
for name, (cost, secs) in designs.items():
    print(f"{name:<38} ${cost:>8.4f} {secs:>6.1f}s ${cost * 100_000:>17,.0f}")
  • The 10-step agent on the large model costs about 20 times the single call and takes a minute, because each step re-sends a growing history.
  • The same agent on a small model costs a fraction as much, and takes a quarter of the time.
  • The workflow on a small model is cheapest, and running two of its steps in parallel cuts its time further.

At 100,000 runs a month, these differences become the difference between a project that pays for itself and one that doesn't.

Ways to cut cost and latency

TechniqueSavesHow
Fewer stepsBothBetter tools and prompts; workflows for known paths
Smaller models for simple stepsBothA large model plans; small models extract, classify, format
Parallel stepsTimeRun independent tool calls and sub-tasks together
Shorter contextCost, timeSummarise old history; return compact tool results
Prompt cachingCost, timeKeep the system prompt and tools as a stable prefix
Caching answersBothReuse results for repeated questions
Streaming progressPerceived timeShow steps as they happen, so waiting feels shorter

Common mistakes

Practice exercise

Check whether an agent's response time fits what users will accept.

Your solutionPython
steps = 8
seconds_per_step = 2.5      # model call plus tool time, one after another
wait_limit = 15             # seconds a user will happily wait

# Print the total time and how far over (or under) the limit it is, like:
# Total: 12.0 s
# Over the limit by 3.0 s     (or: Under the limit by 3.0 s)
Knowledge check

Why do agent costs grow faster than the number of steps?

Summary

  • Agentic designs multiply model calls and context length, so cost and latency grow quickly.
  • Smaller models for simple steps, parallel work and shorter context give the biggest savings.
  • Caching and streaming progress help cost and perceived speed.
  • Design the user experience around realistic run times; long tasks belong in the background.

Next: designing where humans stay in the loop.

Finished reading? Tick it off to track your progress.