OpenAI Batch API·Prompt Caching Practical Guide: Why LLM API cost reduction requires designing request routing, cache hit rate, and failure reprocessing first rather than model replacement
To reduce LLM API costs, real-time calls, Batch API, Prompt Caching, and usage metering should be divided by request nature. Based on OpenAI and Anthropic official documents, we compiled a cost reduction structure, failure pattern, and execution checklist.
Korean search intent answered by this article
- “How to use OpenAI Batch API”: Intent to understand the JSONL file, upload, batch creation, and result retrieval flow as an actual operating procedure
- “How to reduce LLM API costs”: Intent to lower costs through batch processing, prompt caching, and usage metering rather than model replacement
- “Difference between Batch API and real-time API”: Intent to share which requests can be sent asynchronously 24 hours a day and which requests require an immediate response
- “No prompt caching cache hit”: Intent to find the reason why cost savings are not felt despite including long system prompts and examples
1. One-line problem definition
Key line: LLM API costs are leaked more often from “which request is sent, when and through what path” rather than “which model is used”.
Teams whose costs increase faster than expected after adding AI features usually make the same mistake. User conversations, back-office classification, bulk evaluation, embedding generation, and long instruction-based analytics all go down the same real-time API path. Then, the real-time cost and real-time rate limit are used as is for tasks that do not require delay time.
The scope of this article is to explain how to divide Batch API, Prompt Caching, real-time call, and usage measurement, focusing on the OpenAI API. It does not cover serving your own models at scale, purchasing GPU infrastructure, or prompt engineering generalities. Our readers are developers looking to add AI capabilities to their products, teams running automated workflows, and practitioners looking to reduce their API bills.
For background related to, it is recommended to look at Context Engineering Practical Guide for context design of agent operation, and Gemini API Flex·Priority Inference Practical Guide for model routing perspective. This article focuses, among other things, on linking the OpenAI Batch API and prompt caching into real cost-saving structures.
2. First, conclusion
Key one line: Requests that the user is waiting for are candidates for real-time, bulk tasks that do not wait are candidates for Batch, and requests that repeat long common instructions are candidates for Prompt Caching.
My conclusion is clear. To reduce LLM API costs, you should create ⟦Request Routing Table before changing the model. “Do I have to answer now?”, “Is the same prefix repeated?”, “Is it possible to retry even if it fails?”, “Isn’t the order of results important?” Depending on these four questions, real-time API, Batch API, Prompt Caching, and queue reprocessing must be divided.
OpenAI's official Batch API document describes asynchronous bulk requests as 50% lower cost than synchronous API, separate rate limit, and completion window of up to 24 hours. On the other hand, Prompt Caching is a method of lowering cost and delay with a cached input rate when a long common prefix is repeated. In other words, Batch is a technology to reduce costs by giving up time, and Prompt Caching is a technology to reduce costs by reusing repeated input processing.
However, neither of them are perfect. Batch is not suitable for screens where people are waiting, such as customer chat, recommendations just before payment, or real-time consultation. Caching does not work well for requests that send different system prompts, different tool lists, or different orderings of examples each time. Therefore, the recommendation in this article is not “Send all requests cheaply,” but Separate routes by request type
3. Decomposition of core structure
Key line: The cost-saving structure is not a single API call, but a small operating system with a connected router, queue, cache-friendly prompt, and usage log.
For a novice developer, the LLM API cost reduction structure is easy to look at in four layers.
- Request Router: Classifies incoming jobs into real-time, batch, cache priority, and human review.
- Batch queue: Gathers tasks that do not require an immediate response, such as bulk evaluation, product description generation, review sorting, and document embedding, into JSONL files.
- Cache-friendly prompts: Anchor repeating system instructions, rubrics, few-shot examples, and tool definitions up front, with user-specific variables at the back.
- Usage metering: Store request id, custom_id, cached_tokens, cache_write_tokens, failed, expired, latency to ensure savings are real.
The important connections here are the router and instrumentation. Without a router, all requests flow in real time, and without instrumentation, it is impossible to know whether the cache was correct or whether the batch was actually saved. Savings starts with “quarters and records” rather than “good prompts”
For example, let's say you are creating an AQ test result description. The key takeaways that users are waiting for on the results page need to be processed in real time. However, the tasks of bundling the entire result data nightly to regenerate type-specific descriptions, reevaluate failed responses, or update embeddings for searches can be passed on to Batch. If the same evaluation table is entered every time, the table can be fixed with a cache-friendly prefix.
4. Description of design intent
Key one-liners: Batch and caching are not “smarter models” but “operational devices that make repetitive work cheaper and more predictable”
The design intent of the Batch API is to take waitable work out of the real-time path. The OpenAI article's examples of evaluation, bulk classification, and content repository embedding are all tasks that don't require users to wait in front of a screen. Instead of receiving results immediately like the synchronous API, you upload a file, create a batch, check the status, and receive the results file after completion.
The design intent of Prompt Caching is different. When processing the same long prefix repeatedly, it prevents it from being read from the beginning each time. The official documentation explains that a cache hit is possible with exact prefix match. So, instructions and examples should be placed first, and user-specific questions or documentation should be placed last. Caching is not a function that understands “roughly similar prompts,” but a function that reuses “the same first part.”
What this design gains is cost and throughput. What you give up is immediacy, simplicity, and some operational flexibility. Batch must accept a 24-hour completion window, and the cache must keep the prompt structure stable. If you don't know this trade-off, failures and debugging costs will increase even if you turn on the discount feature.
5. Evidence and Comparison
Key one line: The comparison is not “OpenAI vs. other models” but real-time calls, batch calls, prompt caching, and self-queue processing.
| Approach | Best task | Cost perspective | Operational Risk |
|---|---|---|---|
| Real-time API | Chat, search answers, results page description | The simplest, but becomes expensive when mixed with bulk work | When traffic surges, rate limit and cost surge occur simultaneously |
| OpenAI Batch API | Evaluation, classification, embedding, nightly report | 50% cost reduction compared to the same API based on official document | 24 hour window, result order mismatch, failed file processing required |
| Prompt Caching | Long instructions, fixed evaluation criteria, few repetitions | Lowers long prefix cost when cached input rate is applied | If the prefix fluctuates, the cache hit rate drops |
| Own queue + generic API | Action with retry, priority, human approval | No discounts, but great operational control | You must implement queues, retries, idempotency, and cost caps yourself |
Anthropic also proposes a 50% cost reduction and massive asynchronous processing in the Message Batches API. Rather than a temporary discount exclusive to a specific company, this is a sign that the “pattern of diverting waitable requests to a separate processing path” is already becoming common in LLM API operations. It is also important to note that the Anthropic documentation states that some parameters and cache pre-warming are restricted in Batch requests. Batch is powerful, but it is not a path to replicating all the behavior of the synchronous API.
Cost calculation cannot be done by simply looking at the discount rate. For example, if you have the task of sorting through 1,000 reviews, and each request repeats a long rubric, you might consider Batch and caching together. However, if it is a single request where the results must be shown to the user immediately, the batch discount is meaningless. Conversely, if the same benchmark has fewer than 1,024 tokens or is reordered every time, the cache may not match as expected.
6. Actual operation flow / step-by-step execution method
Key one line: First classify the request, then fix the JSONL·custom_id·usage log so you can account for costs during operation.
6-1. Create a request classification table first
| Question | YES | NO |
|---|---|---|
| Is the user waiting on the screen? | Real-time API | Batch candidate |
| Do you process more than 100 inputs at once? | Batch candidate | Generic API or Queue |
| Are long common guidelines/examples repeated? | Prompt Caching Candidate | Prioritize prompt collapse over cache |
| Even if it fails, can it be reprocessed later? | Batch or own queue | Real-time + immediate error handling |
6-2. Batch input file uses custom_id as the task key
OpenAI Batch API explains that it puts a unique custom_id in each request and maps it to custom_id because the order of the result file may be different from the input order. In practice, it is safer to use values that are directly linked to the original record later, such as review:12345:v2, eval:prompt-a:case-009.
{"custom_id":"review-1001-v1","method":"POST","url":"/v1/responses","body":{"model":"gpt-5.6-luna","input":"Categorize the following reviews as positive/neutral/negative and explain your rationale in one sentence: ..."}}
{"custom_id":"review-1002-v1","method":"POST","url":"/v1/responses","body":{"model":"gpt-5.6-luna","input":"Categorize the following reviews as positive/neutral/negative and explain your rationale in one sentence: ..."}}
6-3. Cache-friendly prompts are divided into a fixed prefix and a variable suffix
Prompt Caching is more advantageous when repeated prefixes are exactly the same. As shown below, system guidelines and evaluation criteria are fixed at the front, and only user-specific data is attached at the back. As the team modifies the template, they track cache rate changes by increasing the version.
const STATIC_PREFIX = `
Role: Customer Review Quality Assessor
standard:
1. Causes of dissatisfaction
2. Whether the product is defective
3. Refund/Exchange Necessity
4. Red flags to raise to an agent
Output Format: JSON
`;
const input = `${STATIC_PREFIX}
This review:
${reviewText}`;
6-4. Operation logs are left for cost explanation
You must save at least the following fields:
route: realtime, batch, cache-priority, manual-reviewmodel: Call model namecustom_id: Task key for batch result mappinginput_tokens,output_tokens,cached_tokens,cache_write_tokensstatus: completed, failed, expired, retriedlatency_msor time taken to complete batch
You should save it like this so you can explain both “why this month’s expenses went down” and “why they didn’t go down.” Cost-saving features are more important to verify than to turn on.
7. Pitfalls
Key one line: Failure patterns mostly arise from request classification, result mapping, and prompt stability, not the discount function itself.
- Trip: Sending tasks that customers are waiting for in batch
Prevention: “Is the user waiting on the screen now?” as the first condition for routing Leave.
Recovery: Revert the functionality to the real-time API, and limit Batch to only post-processing reports or quality assessments. - Pitfall: Batch results are processed in input order
Prevention: As in the official document Associatecustom_idwith the original record key.
Recover: Join the resulting files by custom_id rather than order, and reprocess only the missing custom_id. - Pitfall: Expecting the cache to answer “similar prompts” on its own
Prevention: Fixed prefix as template Lock and send variables to the back.
Recovery: Check cached_tokens ratio in usage log, compare prompt diff to remove shaky positions. - Trip: Ignoring the output token by looking only at the discount rate
Prevention: Clarify JSON schema, maximum length, and prohibition of unnecessary descriptions Leave
Recover: Sample the top 20 long outputs to reduce the output format and remeasure. - Trip: Failure, expiration, and retry costs are not calculated
Prevention: Separate the failed, expired, and canceled status of the batch. Leave it as an indicator.
Recovery: Read the failure file to classify validation errors, rate limits, and exceeded input size and separate them into a reprocessing queue.
8. Strengths and Limitations
Key line: Batch and caching are powerful for repetitive and bulk tasks, but they do not design the entire product experience for you.
The strengths are clear. The Batch API separates bulk operations from the real-time path, lowering costs and rate limit burden. Prompt Caching gives teams that iterate on long, common instructions the opportunity to reduce both latency and cost. Both features have the advantage of improving cost structure without developers having to directly operate GPU servers.
The limitations are also clear. Batch has no immediacy. The order of results is not guaranteed, so mapping logic is required. Caching is based on prefix stability. Assembling system prompts for each request, changing the order of the tool list, or shuffling examples can reduce cache rates.
Sometimes other choices are better. If your traffic is small and your monthly API costs are low, creating a routing system can be more expensive. For products where the responsiveness of customer screens is key, model quality and latency stability take precedence over cost savings. Conversely, if more than hundreds of thousands of classification, summary, and evaluation tasks are repeated each month, introducing batch and caching late is a greater cost.
9. Points to study more deeply
Key line: To reduce operational accidents, read the status/limit/usage fields before the “Usage” in the official document.
- OpenAI Batch API Official Guide: Check JSONL input, file upload, batch creation, status, result file, custom_id mapping.
- OpenAI Prompt Caching Official Guide: Check exact prefix match, prompt_cache_key, cached_tokens, cache_write_tokens conditions.
- OpenAI API Pricing: The unit price of input, cached input, output, and cache write for each model is reflected in the actual calculation.
- Anthropic Batch Processing Official Documentation: Compare limitations with other vendors also providing 50% cost saving patterns in bulk asynchronous processing.
- Anthropic Prompt Caching official document: Check the differences in caching grammar by vendor by looking at cache_control, TTL, and cache hit pricing.
In the site, you can first look at AQ Score practical guide hub, which collects practical automation flows, and check your current team's automation readiness with AQ test to check your tendency to adopt AI. The operational LLM evaluation structure is more practical when viewed in connection with LLM Evaluation Dataset Operation Guide
10. Action Checklist + Author's Perspective
Key line: I recommend that “teams that are starting to see monthly costs” should introduce the 3-piece Batch·Cache·Meter set first rather than replacing the model.
- All LLM requests were classified into user waiting type, mass post-processing type, repetitive prefix type, and human inspection type
- Batch candidate jobs can tolerate a 24-hour delay and can be reprocessed in case of failure
- Batch input
custom_idis mapped 1:1 with the original task record - We confirmed that the fixed prefix of the Prompt Caching candidate is more than 1,024 tokens and is exactly the same for each request
- User-specific variables, dates, random examples, and tool lists are pushed to the back of the cache prefix
- Store cached_tokens, cache_write_tokens, failed, expired, route in usage log
- Compare before and after cost reduction not by “total amount” but by unit price and failure rate by request type
- Key responses on customer screens prioritize latency and quality over cost reduction
Definition of Done: If the cost by request type, cache hit rate, batch failure rate, and user waiting delay can be explained in numbers when processing the same workload for two weeks, the first introduction verification is complete.
From the author's perspective, the order of recommendation is as follows. First, mass evaluation, classification, and embedding are separated into batches. Second, we measure the cache rate by fixing the prefix of requests with repeated long common instructions. Third, only cost caps and fallbacks are placed on real-time routes. On the other hand, if the monthly call volume is still small or the function changes frequently and the prompt fluctuates every day in the early stage of PoC, it is not too late to plant only logs first and introduce them two weeks later.
Self-grading
Final score: 94/100. Search intent relevance 19/20, internal linking 10/10, ad slot suitability 10/10, original commentary 18/20, feasibility 19/20, source reliability 10/10, failure patterns/limitations Rated 8/10. It exceeded the 90-point threshold and passed the publication standard because it linked Batch and caching into a cost routing design rather than a simple feature introduction.
READ THIS NEXT
Continue with a related guide hub
Share this article
Related articles
CodeGraph v0.9.5 Commentary: Why AI coding agents should attach local code knowledge graphs and freshness signals first rather than running more greps
CodeGraph v0.9.5 is a developer tool that seeks to move codebase navigation from file search iterations to local Knowledge Graph lookups. This article organizes the structure, execution procedures, comparison standards, and failure prevention standards when attaching CodeGraph to an AI coding agent from a practical perspective.
GKE Cloud Storage FUSE Profiles for AI Inference: A Pilot and Rollback Guide
Use GKE Cloud Storage FUSE profiles to test AI model-loading performance with clear workload classification, least-privilege access, cost controls, and a rollback plan.
AWS Trainium + Cerebras Hybrid Inference Guide 2026
This is a practical guide that allows you to immediately determine which inference workload is advantageous when looking at AWS Trainium and Cerebras together from a cost, speed, and operation perspective.
Take the AQ test
See your AI capability in three minutes. Assess recognition, utilization, verification, integration, and ethics at once, then receive practical insights.
Start the free AQ test