openclaw - 💡(How to fix) Fix Feature Request: Batch API routing for async/cron agent tasks [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#49326Fetched 2026-04-08 00:56:26
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
2
Participants

Support routing agent messages through Anthropic's Message Batches API (/v1/messages/batches) for non-real-time workloads.

Root Cause

Support routing agent messages through Anthropic's Message Batches API (/v1/messages/batches) for non-real-time workloads.

Fix Action

Fix / Workaround

Current behavior

All agent messages go through the standard Messages API (/v1/messages), even for cron-dispatched tasks that don't need immediate responses.

Use cases

  • Nightly cron tasks (report cards, journal entries)
  • Overnight study/research sessions
  • Bulk content generation (blog images, SEO analysis)
  • Any scheduled task dispatched by cron-master
RAW_BUFFERClick to expand / collapse

Summary

Support routing agent messages through Anthropic's Message Batches API (/v1/messages/batches) for non-real-time workloads.

Motivation

Anthropic's Batch API offers a 50% discount on all token costs, and it stacks with prompt caching (up to 95% savings on cached input). For agents running scheduled/cron tasks overnight — report cards, content generation, study sessions, bulk analysis — there's no need for real-time responses. Routing these through the Batch API would dramatically cut costs.

Current behavior

All agent messages go through the standard Messages API (/v1/messages), even for cron-dispatched tasks that don't need immediate responses.

Proposed behavior

  • New agent-level or task-level config option: batch: true or routing: batch
  • When enabled, OpenClaw collects the request and submits it to /v1/messages/batches instead of /v1/messages
  • Results are polled/webhooked and delivered back to the agent session when ready
  • Could be configured per-agent, per-cron-task, or as a flag on sessions_send

Use cases

  • Nightly cron tasks (report cards, journal entries)
  • Overnight study/research sessions
  • Bulk content generation (blog images, SEO analysis)
  • Any scheduled task dispatched by cron-master

API reference

https://docs.anthropic.com/en/api/creating-message-batches

Pricing impact

  • Standard Opus: /\ per M tokens (input/output)
  • Batch Opus: .50/.50 per M tokens
  • Batch + cached input: /bin/zsh.25/M input

For a team running 10+ agents with nightly cron cycles, this could reduce overnight costs by 50-95%.

extent analysis

Fix Plan

To support routing agent messages through Anthropic's Message Batches API, we will introduce a new configuration option and modify the message submission logic.

Steps:

  • Add a new configuration option batch: true or routing: batch at the agent or task level.
  • Modify the message submission code to check for the batch option and submit requests to /v1/messages/batches instead of /v1/messages when enabled.
  • Implement polling or webhooking to retrieve results from the Batch API and deliver them back to the agent session.

Example Code (Python):

import requests

def submit_message(agent_config, message):
    if agent_config.get('batch'):
        # Submit to Batch API
        response = requests.post('/v1/messages/batches', json={'messages': [message]})
        # Poll for results
        batch_id = response.json()['id']
        results = poll_batch_results(batch_id)
        return results
    else:
        # Submit to standard Messages API
        response = requests.post('/v1/messages', json=message)
        return response.json()

def poll_batch_results(batch_id):
    while True:
        response = requests.get(f'/v1/messages/batches/{batch_id}')
        if response.json()['status'] == 'completed':
            return response.json()['results']
        # Wait and retry
        time.sleep(10)

Verification

To verify the fix, test the message submission with the batch option enabled and disabled. Check that the requests are submitted to the correct API endpoint and that the results are delivered back to the agent session correctly.

Extra Tips

  • Consider adding logging and error handling to the polling logic to handle cases where the Batch API returns an error or times out.
  • Review the Anthropic API documentation to ensure compliance with any usage limits or requirements for the Batch 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 Request: Batch API routing for async/cron agent tasks [1 participants]