Image Generation APIs: Pricing Units, Retries, and Resolution
Learn how to calculate true cost per usable image, structure retries to avoid double spend, and choose resolution wisely.
What the unit price hides
The headline price for an image generation API is rarely the full story. Most providers charge per image, but the definition of an 'image' can vary: some count each generation request, others count each output image when multiple are returned, and some bill per megapixel of output resolution. A low per-image price at 512x512 can become expensive at 1024x1024 if the provider charges by pixel count.
Beyond the base unit, there are hidden costs: failed generations due to safety filters or server errors may still be billed, retries add up, and any post-processing like upscaling or background removal might incur separate charges. To understand your true cost, you need to track not just the list price but the cost per usable image that meets your quality and safety requirements.
Cost per usable image
Cost per usable image is the total amount you spend to obtain one image that passes your acceptance criteria, divided by the number of such images. It accounts for all attempts, including retries and rejected outputs. This metric is far more actionable than the sticker price because it reflects your actual workflow.
To calculate it, log every API call with its cost, the reason for any failure (safety filter, timeout, low quality), and whether the output was accepted. Then, for a given batch, sum all costs and divide by the number of accepted images. You can do this manually or instrument your code to emit metrics to your monitoring system. Over time, this reveals which models and settings yield the best economics for your use case.
Retry and safety-filter accounting
Retries are a major source of unexpected spend. A naive retry loop that re-sends the same prompt after a safety rejection or a transient error can quickly multiply costs. Worse, some providers may bill for generations that are later blocked by safety filters, so you pay for images you never see.
To avoid silent double spend, structure retries with clear policies. First, distinguish between retryable errors (network timeouts, rate limits) and non-retryable ones (safety violations, invalid parameters). For retryable errors, use exponential backoff with a cap on attempts. For safety violations, do not retry the same prompt; instead, log the event and consider adjusting the prompt or using a different model. Always track the cost of each attempt, including failed ones, so you can attribute spend accurately.
- Classify errors: retry only on transient failures (5xx, timeouts, rate limits).
- Set a maximum retry count (e.g., 3) and use exponential backoff with jitter.
- For safety-filter rejections, do not auto-retry; log the prompt and consider fallback strategies.
- Record the cost of every attempt, even failures, in your cost tracking system.
- Periodically review retry rates and adjust thresholds to balance reliability and cost.
Choosing resolution for the destination
Resolution directly impacts cost when billing is per megapixel, and it also affects generation time and quality. Generating at a higher resolution than needed wastes money, while generating too low and upscaling can degrade quality and add post-processing costs.
Start by defining the maximum display size for your use case. For a thumbnail, 256x256 may suffice; for a hero image, you might need 1024x1024 or higher. Check your provider's pricing to see if higher resolutions cost more per image or per megapixel. If the latter, calculate the pixel count and compare. Also consider whether you can generate at a lower resolution and upscale with a separate service if that is cheaper overall, but factor in the upscaling cost and potential quality loss.
Monitoring and optimization
Once you have a handle on cost per usable image, set up dashboards to monitor it over time. Track metrics like retry rate, safety-filter rate, and average cost per accepted image. Anomalies can indicate prompt issues, model degradation, or pricing changes.
Optimization opportunities include prompt engineering to reduce safety rejections, caching frequently requested images, and selecting models that offer the best quality-cost tradeoff for your specific content. Regularly review your model mix and consider testing alternatives when new models become available.
How to apply this with Admesh
Admesh provides a unified API for multiple model families, including image generation models from OpenAI, Anthropic, Google, and others. With a single API key and balance, you can experiment with different providers to find the best cost per usable image for your needs. Use the OpenAI-compatible base URL https://api.admesh.ai/v1 or the Anthropic-compatible endpoint https://api.admesh.ai/v1/messages to integrate quickly.
To apply the cost-tracking strategies above, instrument your Admesh API calls to log the model, resolution, and outcome (success, safety rejection, error) for each request. Admesh's console at https://console.admesh.ai provides usage and billing details that you can cross-reference. Check the model catalog at https://admesh.ai/models and pricing at https://admesh.ai/pricing to compare per-image or per-megapixel costs across providers.
When implementing retries, use Admesh's unified interface to switch between models if a particular model frequently triggers safety filters for your content. This can reduce retry costs. For detailed API usage, refer to the documentation at https://docs.admesh.ai.
Частые вопросы
How do I know if my image API bills per image or per megapixel?
What should I do when a generation is blocked by a safety filter?
How can I reduce the cost per usable image?
Источники
Вызывайте эти модели через один шлюз
Admesh предоставляет единый API, совместимый с OpenAI: один Base URL и один ключ для Claude, GPT, DeepSeek и других моделей. Новым аккаунтам доступен пробный кредит без срока действия.
