What This Example Shows
- How to score or triage tens of thousands of records with
/v1/agent/batch/completions - A real lead-scoring workload built on
/v1/agent/batch/completions - Per-record cost math you can take to your CFO
- How to chunk a large input list to stay inside the endpoint’s hard batch-size limit, and how to submit those chunks concurrently so throughput doesn’t collapse
- Where this beats hand-rolled
asyncio.gatheragainst the single-agent endpoint
Why This Matters
Every revenue team has a backlog of records that need a human-quality judgment call: leads to qualify, tickets to triage, resumes to screen, transcripts to tag. Hiring a person to do this work costs $30-$60 per hour and produces 20-40 decisions per hour. Sending each row to a single-agent endpoint one-at-a-time gets you the right answer but burns wall-clock time and connection overhead. The batch endpoint compresses that same workload into one request, parallelized server-side, with a single bill at the end. This tutorial shows the concrete shape of that job.Step 1: Setup
Step 2: Define the Lead Scoring Agent
We will use one agent definition and reuse it across every record. The agent reads a lead profile and returns a score and a one-line reason.Step 3: Load Your Records
In a real workload these come from a CRM export, a database query, or an S3 file. For this tutorial we generate a synthetic list of 10,000 leads.Step 4: Convert Records into Batch Requests
Each item in the batch body is oneAgentCompletion: the same agent_config plus a per-record task.
Step 5: Submit in Chunks
/v1/agent/batch/completions enforces a hard server-side cap of 50 items per request — send more than 50 AgentCompletion objects in one call and you get back an HTTP 422 (“List should have at most 50 items after validation”). For 10,000 leads that means 200 chunked requests, so submit the chunks concurrently with a small thread pool instead of one at a time, or wall-clock time balloons.
Each request is capped at 50 items, but the server processes those 50 concurrently, and Pro/Ultra/Premium keys allow up to 2,000 requests per minute — so a pool of 20-30 worker threads submitting 50-item chunks in parallel gets you back to job-like throughput without tripping the per-request limit or the per-minute rate limit.
Step 6: Aggregate and Route
Parse each agent response, slot leads into A/B/C/D tiers, and forward only A-tier leads to your SDRs.The exact response shape depends on the model and whether the agent returns structured outputs. Wrap the JSON parse in a try/except and dump unparseable rows to a review queue — never let one bad row halt a 10k-lead pipeline.
The Cost Math
Pricing varies by model and current token rates — these numbers are illustrative, not a quote.Adapting the Pattern
Swap theagent_config system prompt and the per-record task shape to retarget:
Nothing else in this tutorial changes — same endpoint, same chunking, same cost-tracking story.
Next Steps
- Batch Swarm Completions for Overnight Reports when one agent isn’t enough per record
- Batch Agent Completions (Single Agent) for the request-shape mechanics
- Streaming when you need real-time token output instead of batch throughput