> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.lakera.ai/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.lakera.ai/_mcp/server.

# 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.

#### TypeScript

```typescript
import { LakeraRedClient } from "lakera-red-sdk"

const client = new LakeraRedClient({
  apiKey: process.env.LAKERA_RED_API_KEY,
  baseUrl: "https://red-webhooks.lakera.ai",
})

// Reuse the target created in an earlier run.
const target = await client.getTarget("target_abc123")

const scan = await client.createScan({
  name: "CI nightly security check",
  targetId: target.targetId,
  strategy: { name: "static" },
  objectives: ["security.system-prompt-extraction.1"],
  concurrency: 5,
})

await scan.run(async (session) => {
  for await (const { attack, respond } of session) {
    const reply = await myAgent.chat(attack)
    await respond(reply)
  }
})

console.log(`View report: ${scan.dashboardLink}`)
```

#### Python

```python
import os

from lakera_red_sdk import LakeraRedClient, StaticStrategyOptions


async def main():
    async with LakeraRedClient(
        api_key=os.environ["LAKERA_RED_API_KEY"],
        base_url="https://red-webhooks.lakera.ai",
    ) as client:
        # Reuse the target created in an earlier run.
        target = await client.get_target("target_abc123")

        scan = await client.create_scan(
            target.target_id,
            name="CI nightly security check",
            strategy=StaticStrategyOptions(),
            objectives=["security.system-prompt-extraction.1"],
            concurrency=5,
        )

        async def handler(session):
            async for message in session:
                reply = await my_agent.chat(message.attack)
                await message.respond(reply)

        await scan.run(handler)

        print(f"View report: {scan.dashboard_link}")
```

> **Note**
>
> 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](/docs/red/sdk-reference#running-recon) to refresh it
before scanning.