Reuse a Target Across Scans

A target owns its recon profile, so once a target exists you can scan it again and again without re-describing your application or re-running recon. This is the common case for scheduled or CI scans: the target was set up once — in an earlier run or in the dashboard — and every later scan just fetches it by id.

Use getTarget when you already have a target’s id. Unlike createOrGetTarget, it is read-only: it never creates a target or runs recon. It throws if no target with that id exists or the caller cannot access it.

Get the target’s id

There are two ways to obtain the id:

  1. Read target.targetId (TypeScript) / target.target_id (Python) from the Target returned by createOrGetTarget in an earlier run, and store it.
  2. Open the target in the dashboard and copy the id from the URL: /targets/<targetId>.

Fetch the target and scan it

Fetch the existing target by id, then pass its targetId to createScan. No recon runs and no handler is needed to acquire the target — the stored profile is reused.

1import { LakeraRedClient } from "lakera-red-sdk"
2
3const client = new LakeraRedClient({
4 apiKey: process.env.LAKERA_RED_API_KEY,
5 baseUrl: "https://red-webhooks.lakera.ai",
6})
7
8// Reuse the target created in an earlier run.
9const target = await client.getTarget("target_abc123")
10
11const scan = await client.createScan({
12 name: "CI nightly security check",
13 targetId: target.targetId,
14 strategy: { name: "static" },
15 objectives: ["security.system-prompt-extraction.1"],
16 concurrency: 5,
17})
18
19await scan.run(async (session) => {
20 for await (const { attack, respond } of session) {
21 const reply = await myAgent.chat(attack)
22 await respond(reply)
23 }
24})
25
26console.log(`View report: ${scan.dashboardLink}`)

The handler passed to scan.run still drives the attack sessions — reusing a target only skips recon, not the scan itself.

If the target’s underlying application has changed since it was created, its stored recon profile may be stale. See runRecon in the SDK Reference to refresh it before scanning.