How to calculate AI API cost
For rates per million tokens: cost = input tokens / 1,000,000 * input rate + output tokens / 1,000,000 * output rate. With fictional rates of $2 input and $8 output, 1,200 input tokens and 400 output tokens cost $0.0056. These are illustrative rates, not current prices. Check live pricing and account for retries, caching and media charges.