What This Covers
- The exact window the discount applies to (8 PM – 6 AM America/Los_Angeles) and what it covers
- Realistic monthly savings: a team running 1,000 swarm jobs/day at daytime rates vs. overnight rates
- A drop-in cron recipe for scheduling overnight batch swarms from any server
- An Airflow DAG pattern for production-grade overnight orchestration
- The two failure modes to watch: timezone drift and on-the-boundary jobs
Why This Matters
The single highest-ROI cost lever the Swarms API offers is its overnight discount: swarm-completion input and output tokens are billed at 50% between 8 PM and 6 AM Pacific time. For any workload that doesn’t need sub-second turnaround — overnight reports, daily research digests, RAG-index refreshes, training-data generation, backfills, evaluation suites — this is free money you collect by changing when the job runs, not what the job runs. A team spending $10,000/month on swarm jobs that could shift to the overnight window saves roughly $4,500/month with zero code-quality tradeoff. This guide makes that shift mechanical.How the Discount Works
The discount is applied server-side, inapi/swarm_completions.py, inside the calculate_swarm_cost function. When a swarm completion finishes, the billing function checks the current hour in America/Los_Angeles:
swarm_completions_input_cost_per_1m— full 50% offswarm_completions_output_cost_per_1m— full 50% off
swarm_completions_agent_cost— the$0.01per-agent fee is billed full price
The check is on the time the run finishes, in Pacific. A job that starts at 5:55 AM and finishes at 6:02 AM PT will be billed at the daytime rate. Schedule batches to land cleanly inside the window — see “Scheduling on the Boundary” below.
The Monthly Math
Take a realistic mid-sized team: 1,000 swarm jobs per day, each averaging:- 5 agents
- 6,000 input tokens
- 3,000 output tokens
Daytime baseline (jobs run during business hours)
Per-job cost:$0.1445 * 1,000 = $144.50
Per 30-day month: $4,335.00
Overnight: same workload, scheduled 8 PM – 6 AM PT
Per-job cost:$0.09725 * 1,000 = $97.25
Per 30-day month: $2,917.50
Savings
$4,335 – $2,917.50 = $1,417.50/month saved by shifting the same workload into the overnight window. Annualized: $17,010. Zero code changes to the agents themselves — just when they run. For larger workloads the savings scale linearly until the agent-fee floor dominates. At 10,000 jobs/day this same calculation yields $14,175/month in savings.Verifying the Discount in Your Response
Every swarm completion response includes adiscount_active flag. Check it programmatically to confirm your scheduling actually landed in the window:
discount_active is False on a job you scheduled for overnight, your cron or worker timezone is wrong — see the troubleshooting section below.
Scheduling Recipe 1: System cron
The simplest possible setup. Add this to your crontab and you’re done. Note that cron schedules are interpreted in the system’s local time — be deliberate about which timezone your server runs in.CRON_TZ is supported by Vixie cron and systemd timers — it makes your schedule survive DST shifts without manual adjustment.
The batch script itself is the same swarm call you’d write at any other time. The discount is applied server-side based on when the request hits the API, not on any flag you set.
Scheduling Recipe 2: Airflow DAG
For teams already running Airflow, this is the production-grade pattern. The DAG runs once per night at 9 PM PT, fans out to N batch jobs in parallel viabatch_swarm_completions, and writes a cost-discount audit so you can prove the 50% landed.
audit_discount task is the bit most teams forget. Without it, a daylight-savings change or a quiet timezone reconfiguration can move your overnight job back into the daytime band and you won’t notice until the invoice arrives.
Scheduling on the Boundary
The discount window ishour >= 20 or hour < 6 in Pacific. Two practical implications:
- 5:59 AM PT is still discounted; 6:00 AM PT is not. If your job is long-running, start it earlier so it finishes inside the window.
- 8:00 PM PT is the earliest discounted moment. A job that starts at 7:55 PM lands at the full-price rate.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
discount_active: false on a job you scheduled overnight | Scheduler ran in UTC/local-server-time, not Pacific | Set CRON_TZ=America/Los_Angeles or convert in your DAG |
| Discount lands on some runs in the batch but not others | Long-running job crossed the 6 AM boundary | Start earlier; cap batch size so all runs finish before 5 AM PT |
| Discount applied but bill barely changed | Agent fee dominates (heavy-swarm pattern with many agents) | Token costs are 50% off; the $0.01 * num_agents fee is not. Prune agents per the Cost Optimization Playbook |
| Daylight savings broke the schedule | Cron is using a fixed UTC offset that no longer matches PT | Use CRON_TZ=America/Los_Angeles (or Airflow’s tz=...) — these handle DST |
When NOT to Use Night Mode
Night-mode is a batch-economics play. Don’t shoehorn the following into the overnight window — the user-experience cost outweighs the discount:- Interactive chat or assistant traffic — users want answers now
- Webhook-driven agent runs where the upstream caller is blocking
- Realtime fraud / moderation / classification pipelines
- Anything where a 6-hour latency would break a contract
Next Steps
- Batch Swarm Scale Tutorial — full batch-swarm scaling patterns to pair with night-mode
- Batch Agent Scale Tutorial — batching individual agent completions
- Cost Optimization Playbook — pair night-mode with a tiered architecture for compounding savings