Skip to main content

What This Example Shows

  • The enterprise pattern: kick off a long batch of independent multi-agent swarms at end-of-day, have results waiting at 7am
  • A real due-diligence workload across 50 portfolio companies
  • How to schedule with cron, persist results, and recover from partial failures
  • Concrete cost framing versus a human research desk
  • Why this is materially different from running each swarm one at a time
Premium-only endpoint. /v1/swarm/batch/completions is restricted to Pro, Ultra, and Premium subscribers. Free-tier keys will get a 403. Upgrade your account to unlock enterprise batch swarm execution.

Why This Matters

A single multi-agent swarm — director plus three specialists — does the work of an analyst team over a 30-minute call. But the real enterprise pattern isn’t one swarm. It’s fifty swarms running while everyone sleeps: one per portfolio company, one per RFP response, one per region for a market scan, one per candidate in a final-round panel. Schedule a batch swarm job at 8pm, have a folder of completed due-diligence memos waiting at 7am. This tutorial shows how to build that job.

Step 1: Setup

Step 2: Define a Reusable Due-Diligence Swarm Template

Every swarm in the batch is a full SwarmSpec. We define one template (a four-agent HierarchicalSwarm) and stamp it out per company.

Step 3: Build the 50-Company Batch

In a real workload, the watchlist comes from a portfolio database. Here we hard-code 50 tickers.
Batch size limit: /v1/swarm/batch/completions accepts at most 50 SwarmSpec items per request — this tutorial is deliberately sized to that ceiling. A request with more than 50 items is rejected with an HTTP 422 validation error before any swarm runs. If your watchlist grows past 50, chunk it the same way Batch Agent Completions at Scale chunks leads, and submit the chunks concurrently.

Step 4: Submit the Overnight Job

One POST. The server parallelizes the swarms behind the gateway.
The endpoint returns one entry per swarm in the same order as the request, each with its own status, swarm_name, usage, and result (there is no job_id on batch entries — that only appears on the single-swarm /v1/swarm/completions response). Persist the array to disk before you start parsing — partial network failures are easier to recover from when you have the raw response saved.

Step 5: Persist Per-Memo Files

Drop one Markdown file per company into a dated folder so your team finds the memos waiting in the morning.

Step 6: Schedule the Overnight Run

The simplest production deploy is a cron job on a small VM or a scheduled GitHub Action. Save the script above as nightly_dd.py and add to crontab:
For zero-infrastructure scheduling, use a serverless cron platform (GitHub Actions schedule: cron, AWS EventBridge, Vercel Cron). The job itself is a single Python script — anywhere that can run Python on a schedule will work.

Recovering From Partial Failures

Each entry in the response carries its own status. Retry only the failed ones — never resubmit the full batch.

The Cost Math

Pricing varies by model and current token rates — these numbers are illustrative.
This overnight batch costs roughly $50-$100 to run for 50 four-agent due-diligence swarms. A junior analyst team would take ~250 hours at $100/hour to produce the same fifty memos — about $25,000 in direct labor. Run it nightly across your watchlist and you have a permanent overnight research desk for the cost of a single analyst’s coffee budget.

Adapting the Pattern

The same overnight-batch shape applies to any “N independent multi-agent jobs” workload: Only the swarm template and the input list change. The batch envelope, scheduling, persistence, and retry pattern stay identical.

Next Steps