Browse documentation
Batch jobs
Batch jobs run many Portfolio Summary requests asynchronously from a JSONL file. Use them when you need hundreds or thousands of summaries and do not want to manage concurrency, retries, or rate limits yourself.
When to use batch jobs
- Nightly digests for every user: one line per user portfolio, generated after market close and delivered the next morning.
- Segmented briefings: investor portfolios in
exposuremode alongside research readers innews_contextmode, in one job. - Weekly catch-ups and backfills:
news_contextlines withcontext_window_daysset to7.
For a single summary on demand, call POST /v1/daily-summary/ directly.
JSONL request lines
Each line is a complete JSON object: the Portfolio Summary request body plus a unique custom_id that you use to join results back to your own records.
Every line is independent, so one file can mix modes, input shapes, and context windows. Lines without mode get the same default as the single-request endpoint.
{"custom_id":"user-101","mode":"exposure","portfolio":[{"symbol":"RELIANCE","exposure":18.5},{"symbol":"TCS","exposure":12}]}
{"custom_id":"user-102","mode":"intraday_movements","symbols":["INFY","WIPRO"],"context_window_days":2}
{"custom_id":"user-103","mode":"news_context","symbols":["HDFCBANK","ICICIBANK"],"context_window_days":7}| Mode | Use it for |
|---|---|
exposure | Portfolio digests weighted by exposure. Only symbols with news are included. |
intraday_movements | Watchlist move scans with live and previous-close percentages. Movers without news are still reported. |
news_context | News, filings, and events only, with no price commentary. |
See Choosing a mode for the full comparison. context_window_days accepts 1 to 7 Asia/Kolkata calendar days, inclusive of today, and defaults to 1.
The whole file is validated before the job is created. One invalid line, a missing custom_id, or a duplicate custom_id rejects the upload with 400 and the failing line number, and no credits are charged.
Lifecycle
- Create a job by uploading the JSONL file. It starts as
pending. - Poll the job. It moves to
running, then finishes assucceeded,partial, orfailed. - Download results as JSONL once the job has finished.
- Cancel a
pendingorrunningjob if you no longer need it.
status | Meaning |
|---|---|
pending | Queued, not started. |
running | Lines are being processed. |
succeeded | All lines finished without a failure. |
partial | Some lines failed. Check each result line's status. |
failed | No line succeeded, or the job hit an unrecoverable error. |
cancelled | Cancelled before it finished. |
End-to-end example
Upload a file, wait for it to finish, then join the summaries back to your users by custom_id.
import { readFile } from "node:fs/promises"
import { Blob } from "node:buffer"
import { DrishtiClient } from "drishti-sdk"
const client = new DrishtiClient({ apiKey: process.env.DRISHTI_API_KEY! })
const fileBuffer = await readFile("./batch.jsonl")
const fileBlob = new Blob([fileBuffer], { type: "application/jsonl" })
const job = await client.postBatchJobsFile({
file: fileBlob,
filename: "batch.jsonl",
display_name: "Nightly digests",
})
const finished = await client.waitForBatchJobCompletion({
job_id: job.id,
pollIntervalMs: 15_000,
timeoutMs: 30 * 60 * 1000,
})
const results = await client.getBatchJobsJobIdResultsParsed({ job_id: finished.id })
for (const line of results) {
if (line.status === "failed") {
console.error(line.custom_id, line.error)
continue
}
// success, success_no_news, or success_no_signal
const summary = line.response?.body?.summary
const mode = line.response?.body?.details?.mode
console.log(line.custom_id, mode, summary)
}Result lines
Each result line has custom_id, a status, and a response with status_code and body. body holds the same summary and details as the single-request endpoint.
success: a summary was generated. Billed 5 credits.success_no_news/success_no_signal: nothing relevant was found, andsummaryholds a fallback sentence. Not billed.failed:bodyisnull, anderroris an object with acodeand amessage. Not billed. See line error codes.
Results can be downloaded once a job is succeeded, partial, failed, or cancelled. If you cancel a job, lines that finished before the cancel are billed and appear in the results; the rest are skipped and aren't billed.
Billing
- 50 credits when the job is accepted.
- 5 credits per
successline. - Status checks, listing, cancellation, and result downloads are free.
See Create batch job, Get batch job, and Get batch results.