# Pipelines and API

> Start and gate an AI Pentest from a CI job with scansuite-ci, or through the team API.

Source: https://scansuite.eu/documentation/ai-pentest/pipelines-and-api
Last reviewed: 2026-11-26

> **ScanSuite AI:** This page describes ScanSuite AI and its CI client 2.x (appsec4u/ai-ci:2). The ScanSuite Teams client is described in CI/CD and automation.

A pipeline can start an AI Pentest of a staging deployment, follow it to the end and fail the job on what it confirms. It uses a service account's API token, never a person's password, and the same checks as the AI Pentest page: every target must be allowed by the team's targets, and the safeguards apply as for a run started by hand.

## One-time setup

1. **Create a service account**

   Teams → your team → People → Automation and API tokens. Create an account such as ci with the role Operator.
2. **Issue a token**

   With product.read, scan.execute, scan.read and finding.read; at most 90 days. The dialog shows the team's short name for pipelines and a ready-to-run --check command.
3. **Store it in the CI system**

   SCANSUITE_TOKEN as a masked variable; SCANSUITE_URL and SCANSUITE_TEAM as plain variables; SCANSUITE_PRODUCT (exact name) or SCANSUITE_PRODUCT_ID.
4. **Test the connection**

   ```bash
   docker run --rm -e SCANSUITE_URL -e SCANSUITE_TEAM -e SCANSUITE_TOKEN appsec4u/ai-ci:2 --check
   ```

> **A person does this step:** Store the token in the CI system's masked variables yourself; never paste it into a chat or a file in the repository.

## Run a pentest from a job

```bash
scansuite-ci --scan-type pentest --target https://staging.example.com --cookie "session=$SESSION" --instructions "Focus on the checkout and the admin API" --fail-on-severity high
```

| Option | Variable | What it does |
|---|---|---|
| --scan-type pentest | SCANSUITE_SCAN_TYPE | An AI Pentest instead of the default static scan. |
| --target | SCANSUITE_TARGETS | A URL, host or network; repeat it or separate with commas. One kind per scan, as on the page. |
| --cookie |  | Cookies "key=value", several separated by ; |
| --header |  | Request headers "Name: value", several separated by \| |
| --instructions |  | The focus text: guidance and rules for the agents. |
| --fail-on-severity | SCANSUITE_FAIL_ON_SEVERITY | Fail the job on confirmed findings at or above this severity (default high; none turns it off). |
| --max | SCANSUITE_MAX | Allowed findings per severity, for example high=0,medium=10. |
| --block-class | SCANSUITE_BLOCK_CLASS | Findings of these classes fail the job at any severity. |
| --junit, --sarif, --summary-json |  | Reports for the CI system. |

The pentest's one scanner, `ai_pentest_agent`, is selected without `--scanners`. A server without the AI Pentest refuses the scan type. A target the team does not allow ends the job with exit code 3 and the reason; the secrets gate applies to static scans only.

Exit codes: 0 passed, 1 the gate failed, 2 the scan failed, 3 configuration or token error, 4 timeout, 5 server error. A pentest takes hours, not minutes: give the job a timeout to match the run time safeguard.

### GitLab

Include the template your server serves at `/ci/scansuite.gitlab-ci.yml` and add a job after the deployment:

*.gitlab-ci.yml*

```
include:
  - remote: 'https://scansuite.example.com/ci/scansuite.gitlab-ci.yml'

scansuite-pentest:
  extends: .scansuite
  needs: []
  timeout: 4h
  variables:
    SCANSUITE_SCAN_TYPE: pentest
    SCANSUITE_TARGETS: https://staging.example.com
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
```

> **Agent prompt: Let an agent run a pentest of staging**
>
> ```text
> Using the ScanSuite AI CI client (appsec4u/ai-ci:2) and the SCANSUITE_URL, SCANSUITE_TEAM and SCANSUITE_TOKEN variables already set in my environment, run --check, then start an AI Pentest of https://staging.example.com with --scan-type pentest and --fail-on-severity high. Follow it to the end and summarise the confirmed findings by severity, with the evidence for each High and Critical one. Do not change any safeguard and do not add targets.
> ```

## The team API

Every call goes to `/api/teams/<team>/` with `Authorization: Bearer <token>`.

| Call | What it does |
|---|---|
| POST scans/pentest | Start a pentest. JSON: product_id and targets (a list or a comma-separated string), optional header, cookie and instructions. An Idempotency-Key header makes a retry safe. Answers 202 with the job. |
| GET jobs/<job> | The job and the scan it started. |
| GET scans/<scan> | The scan and its status. |
| GET scans/<scan>/logs | The scan log. |
| GET scans/<scan>/findings | The findings of the scan. |
| GET scans/<scan>/report | The report. |
| POST scans/<scan>/cancel | Cancel the scan. |
| GET scanners | What this server can run, per scan type. |

The API starts one-time runs only; schedules are made on the AI Pentest page.
