N
NexusDigitalLabs
← Back to Academy

Phase 2 — Working with LLMs · Lesson 25 · 20 XP

Cost, latency, and prompt caching

API pricing is per token, and input and output tokens are usually priced differently — output tokens cost more, since generating each one requires a full forward pass through the model while input tokens are processed in parallel. A longer system prompt or more retrieved context directly raises cost on every single call.

Model choice is a real tradeoff: a larger model is more capable but slower and more expensive per token; a smaller model is cheaper and faster but may need better prompting to hit the same quality bar. Prompt caching lets a provider reuse a previously-processed prefix (like a long, unchanging system prompt) across calls, cutting both cost and latency for the cached portion.

Exercise

Estimate the cost of 1,000 calls to a prompt with a 2,000-token system prompt and a short user message, with and without prompt caching applied to the system prompt. Compare the totals.

Check yourself

1. Why are output tokens usually priced higher than input tokens?

2. What part of a prompt is the best candidate for a cached prefix, and why?

← Previous lesson

Prompting as engineering

Answer the check-yourself questions to unlock this