Prompt Engineering
Estimating AI API cost by token usage
0views0comments
A formula for input/output token cost, plus tips for reducing cost with prompt caching.
Overview
This article shows how to estimate AI API cost before shipping a feature that relies on an LLM.
The cost formula
Cost = (input tokens × input price) + (output tokens × output price), multiplied by the expected number of calls.
Reducing cost
Caching repeated content (a fixed system prompt) and trimming unnecessary context both meaningfully cut cost.
Tags
costtokens
AI
← BackCategory
Prompt Engineering · AI