Browse documentation
Guides

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 exposure mode alongside research readers in news_context mode, in one job.
  • Weekly catch-ups and backfills: news_context lines with context_window_days set to 7.

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.

jsonl
{"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}
ModeUse it for
exposurePortfolio digests weighted by exposure. Only symbols with news are included.
intraday_movementsWatchlist move scans with live and previous-close percentages. Movers without news are still reported.
news_contextNews, 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

  1. Create a job by uploading the JSONL file. It starts as pending.
  2. Poll the job. It moves to running, then finishes as succeeded, partial, or failed.
  3. Download results as JSONL once the job has finished.
  4. Cancel a pending or running job if you no longer need it.
statusMeaning
pendingQueued, not started.
runningLines are being processed.
succeededAll lines finished without a failure.
partialSome lines failed. Check each result line's status.
failedNo line succeeded, or the job hit an unrecoverable error.
cancelledCancelled 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.

ts
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, and summary holds a fallback sentence. Not billed.
  • failed: body is null, and error is an object with a code and a message. 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 success line.
  • Status checks, listing, cancellation, and result downloads are free.

See Create batch job, Get batch job, and Get batch results.