openclaw - 💡(How to fix) Fix Feature: Batch API support for non-urgent cron jobs (50% cost reduction) [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#56126Fetched 2026-04-08 01:44:36
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Author
Participants

Allow cron jobs with agentTurn payloads to optionally route through Anthropic's Batch API instead of the standard Messages API. The Batch API offers a 50% discount on both input and output tokens with a 24-hour completion window — perfect for scheduled, non-interactive tasks.

Root Cause

Allow cron jobs with agentTurn payloads to optionally route through Anthropic's Batch API instead of the standard Messages API. The Batch API offers a 50% discount on both input and output tokens with a 24-hour completion window — perfect for scheduled, non-interactive tasks.

Code Example

{
  "schedule": {"kind": "cron", "expr": "0 3 * * *"},
  "sessionTarget": "isolated",
  "payload": {
    "kind": "agentTurn",
    "message": "...",
    "batch": true
  },
  "delivery": {"mode": "announce"}
}
RAW_BUFFERClick to expand / collapse

Summary

Allow cron jobs with agentTurn payloads to optionally route through Anthropic's Batch API instead of the standard Messages API. The Batch API offers a 50% discount on both input and output tokens with a 24-hour completion window — perfect for scheduled, non-interactive tasks.

Use Case

I run several recurring cron jobs that are inherently non-urgent:

  1. Sentinel research — generates improvement proposals 4x/day. Each run calls Opus 4.6 for ~5 minutes. These don't need real-time responses — a 1-hour delay is fine.
  2. Dream Cycle — nightly memory consolidation at 3am. No user is waiting for this.
  3. Blogwatcher/RSS — periodic feed monitoring and summarization.
  4. Scheduled research tasks — one-shot cron jobs for deep research that return results via delivery.

All of these could use the Batch API's 50% discount without any impact on user experience.

Proposed Config

Add an optional batch flag to cron job payloads:

{
  "schedule": {"kind": "cron", "expr": "0 3 * * *"},
  "sessionTarget": "isolated",
  "payload": {
    "kind": "agentTurn",
    "message": "...",
    "batch": true
  },
  "delivery": {"mode": "announce"}
}

When batch: true:

  1. Submit the agentTurn to Anthropic's Batch API (/v1/messages/batches) instead of the standard Messages endpoint
  2. Poll for completion (or use webhook callback)
  3. When complete, deliver the result via the normal delivery mechanism (announce, webhook, etc.)
  4. If batch processing fails or times out (24hr), fall back to standard API

Pricing Impact

  • Batch API pricing: 50% of standard rates. Stackable with prompt caching (cache reads at 0.1x).
  • Combined savings: Up to 95% on cached portions of batch requests.
  • My estimated savings: ~$30-45/month on ~$90/month of batch-eligible cron traffic.

Technical Notes

Context

  • OpenClaw version: 2026.3.23-2
  • Running 5 cron-triggered jobs (1 recurring + ad-hoc one-shots)
  • Sentinel alone runs 4 Opus research calls/day + 1 update check = ~150 calls/month
  • All are non-interactive — perfect batch candidates

Impact

Any OpenClaw user with recurring cron jobs would benefit. The Batch API is GA and stable. This is essentially free money — same results, half the cost, with the only trade-off being completion time (which doesn't matter for scheduled background work).

extent analysis

Fix Plan

To implement the Batch API for cron jobs, follow these steps:

  • Update the cron job payload to include the batch flag:
{
  "schedule": {"kind": "cron", "expr": "0 3 * * *"},
  "sessionTarget": "isolated",
  "payload": {
    "kind": "agentTurn",
    "message": "...",
    "batch": true
  },
  "delivery": {"mode": "announce"}
}
  • Modify the API submission logic to use the Batch API (/v1/messages/batches) when batch: true:
if payload.get('batch'):
    # Submit to Batch API
    response = requests.post('/v1/messages/batches', json=payload)
    # Poll for completion or use webhook callback
    batch_id = response.json()['id']
    while True:
        batch_status = requests.get(f'/v1/messages/batches/{batch_id}').json()
        if batch_status['status'] == 'completed':
            break
        # Handle timeout or failure
        if batch_status['status'] == 'failed' or time.time() - start_time > 24 * 60 * 60:
            # Fall back to standard API
            requests.post('/v1/messages', json=payload)
            break
        time.sleep(60)  # Poll every 1 minute
  • Deliver the result via the normal delivery mechanism when the batch processing is complete:
# Deliver the result
delivery_mode = payload['delivery']['mode']
if delivery_mode == 'announce':
    # Announce the result
    print(f"Result: {batch_status['result']}")

Verification

To verify that the fix worked:

  • Check the API logs to ensure that the Batch API is being used for cron jobs with batch: true.
  • Verify that the results are being delivered correctly after batch processing is complete.
  • Monitor the cost savings to ensure that the Batch API pricing is being applied correctly.

Extra Tips

  • Make sure to handle errors and timeouts properly when using the Batch API.
  • Consider implementing a retry mechanism for failed batch jobs.
  • Review the Anthropic Batch API documentation for any updates or changes to the API.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix Feature: Batch API support for non-urgent cron jobs (50% cost reduction) [1 participants]