Haeminway haemin/way
한국어
2 min read

ChatGPT API bill higher than expected? Where the cost leaks

When a ChatGPT API bill grows faster than expected, retries, logs and model choice are often why. Track tokens, cache repeated work, route models and set budget guards.

Retries multiply calls; cache hits and caps bound repeat work

A cache hit reuses a prior result without another call; a cache miss sends input and output through each attempt, while a request cap stops further calls.View full-size diagram
Visual guideInput and output both contribute per attempt. Retries add attempts; a cache hit can avoid a repeat call, and a cap can stop requests before usage grows further.

The AI feature in the request form looked cheap in testing. Then the first full month’s API bill came in well above the estimate, and nobody could say which calls caused it.

The answer: tokens, retries and logs multiply quietly. Without per-call accounting, model routing, caching and a budget guard, ChatGPT API spend outruns any forecast. For AI features built with those guards from the start, see AI features for work tools.

Token Cost Fundamentals

ChatGPT API Costs Quietly Leak Money If You Do Not Count Them operating model diagram Input and output tokens are billed separately. GPT-4o costs $2.50 per million input tokens and $10.00 per million output tokens. Repeating a long system prompt on every call scales cost linearly.

Model Selection Impact

ModelInput $/MOutput $/MUse case
GPT-4o2.5010.00Complex reasoning
GPT-4o-mini0.150.60Simple classification

Source: OpenAI’s GPT-4o model page and GPT-4o mini announcement, checked 2026-11-07. OpenAI now marks GPT-4o as deprecated, so check the current pricing page before you budget a new project.

Retry and Backoff Policy

Without exponential backoff on 429/5xx errors the same prompt is sent dozens of times. Adopt the pattern from the retry-backoff note.

Caching Implementation

function getCacheKey(prompt, model, temp, userId) {
  const hash = Utilities.computeDigest(Utilities.DigestAlgorithm.SHA_256, prompt + model + temp);
  return `${userId}:${model}:${hash}`;
}

function budgetGuard(currentTokens, limit) {
  if (currentTokens > limit) throw new Error('Budget exceeded');
}

Logging Overhead

Writing every response to Sheets adds both storage and read costs. See spreadsheet-inventory-limits and store only required fields.

Takeaway

Including user ID in the cache key enables personalized reuse while preserving privacy boundaries.

Model Routing Strategy

Route simple queries to mini and complex ones to 4o. Cross-reference apps-script-automation-guide and ai-cost-and-keys.

Failure Modes and When Not to Use

  • Disable caching when hit rate stays below 20%.
  • Never cache when live data is required.
  • Check six-minute-limit if LockService contention appears.

Operational Checklist

  • Daily token-usage script
  • Per-model budget thresholds
  • 24 h TTL cache
  • Defined fallback model

Final review criteria

The useful question is not how many features the automation has. It is whether the workflow can be understood, recovered, and safely rerun after something goes wrong.

  • Raw input is separated from the human-facing working view.
  • Each run records success, failure, processed count, and error message.
  • Replaying the same input does not create duplicate results.
  • Permission changes, quota errors, and external API failures are visible later.

For low-risk internal tasks, that may be enough. For customer replies, booking confirmation, inventory updates, payments, or legal records, the threshold is higher: compare Apps Script against a dedicated SaaS or a small server-backed system before relying on it.

Frequently asked questions