Skip to main content

Batch Mode

Run hundreds of questions against the same context. Cache is always enabled — the first question pays full cost, subsequent questions benefit from provider-level caching at up to 90% savings.

End-to-end example

Audit a TypeScript source tree for security smells in three commands:
End-to-end
stdout
The first question paid ~0.0070(cachemiss);thenexttwopaid 0.0070 (cache miss); the next two paid ~0.0007 each thanks to Gemini’s 90% cache discount.

Quick start

Create a questions file (one question per line):
questions.txt
Run it:
Output is JSONL — one JSON object per question, plus a final aggregate line:

Questions file format

  • One question per line
  • Empty lines are skipped
  • Lines starting with # are treated as comments

Cache behavior

Batch mode always enables caching. Here’s the cost flow: The exact savings depend on your provider:

Pre-warming the cache

Warm the cache before running batch queries to ensure the first question also gets cache pricing:

Estimating costs

Check how much a batch run will cost before committing:
For a 100-question batch over this context: ~0.003(first)+990.003 (first) + 99 * 0.0003 = ~$0.033 total.

Budget enforcement

Set a maximum spend to prevent runaway costs:
Cumulative cost is tracked across all questions. When the budget is exceeded, RLMX stops gracefully and reports how many questions were completed.

Batch options

Gemini Batch API

For Google Gemini models, the --batch-api flag enables the Gemini Batch API, which provides an additional 50% cost reduction on top of caching:

Cost stacking

100 queries over 500K tokens of context: under $2.00 with both cache and batch stacking.
Batch API jobs are asynchronous. Results may take longer to return compared to standard API calls, but the cost savings are significant for large runs.

Practical patterns

Study session over documentation

Code audit

Codebase onboarding

CAG vs RLM for batch

By default, batch mode uses CAG (cache enabled). For very large contexts that exceed provider limits, RLMX falls back to standard RLM iteration automatically.

Provider context limits

If your context exceeds the provider limit, RLMX will warn you and fall back to RLM mode where the LLM navigates the context programmatically.