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

# Launch a pentest

POST https://api.pensar.dev/pentests
Content-Type: application/json

Queues a hosted pentest. It runs asynchronously: poll [Get a pentest](/console/api/api-reference/pentests/get-pentest) with the returned `scanId`, or subscribe to the `pentest.completed` [webhook](/console/features/webhooks). An identical active launch may be reused, in which case the response names that pentest.

**Scope.** With `endpointIds`, exactly those discovered endpoints are tested. Find them with [List applications](/console/api/api-reference/applications/list-apps) and [List endpoints](/console/api/api-reference/endpoints/list-endpoints), and send endpoint `id` values, not URLs or application IDs. Without `endpointIds`, every eligible application in the workspace is tested. Applications must have a linked domain with pentesting enabled, verification where required, and discovered endpoints; a selected application that is not ready is rejected rather than silently dropped.

**Depth.** `scanLevel` defaults to `priority`, or to `full` with `endpointIds`, which accepts only `full`.

**Branch.** `branch` must match the connected repository’s configured target branch; omitting it uses that branch. It cannot be combined with `endpointIds`. To test the changes between two commits, use [CI dispatch](/console/features/ci-integration#compare-two-explicit-commits) instead.

Unknown fields and invalid scope return `400` before a pentest is created; the scope is never widened after a validation failure.

Requires the `pentests:launch` API key scope.

Reference: https://docs.pensar.dev/api/api-reference/pentests/launch-pentest

## Authentication

- `Authorization` header (bearer token, required) — A workspace API key, sent as `Authorization: Bearer`.
- `x-api-key` header (required) — A workspace API key, sent as `x-api-key`.

## Request

### Body (application/json)

This endpoint expects a PentestLaunchRequest.

- `branch` (string, optional) — Configured repository branch only; cannot be combined with endpointIds.
- `scanLevel` (enum, optional) — Legacy launches default to priority; exact endpoint launches require full and default to full.
  - Allowed values: `priority`, `full`
- `endpointIds` (list of string, optional) — Exact nonempty list of discovered endpoint UUIDs in this workspace (maximum 1000).
- `knowledgeEntryIds` (list of string, optional) — Active knowledge base entry UUIDs to attach as context for this run (maximum 20).

## Response

### 201

The pentest was queued.

- `scanId` (string, required) — Pentest ID. Pass it to `GET /pentests/{pentestId}`.
- `label` (string, required)
- `status` (enum, required)
  - Allowed values: `queued`
- `message` (string, required)

## Errors

### 400 Bad Request Error

The request is invalid. `error` names the field.

- `error` (string, required) — What went wrong, naming the offending value when useful.

### 401 Unauthorized Error

The API key is missing or invalid.

- `error` (string, required) — What went wrong, naming the offending value when useful.

### 403 Forbidden Error

The credential lacks the required scope or is not allowed this action.

- `error` (string, required) — What went wrong, naming the offending value when useful.

## Examples

**Request**

```json
{}
```

**Response**

```json
{
  "scanId": "string",
  "label": "PEN-000123",
  "status": "queued",
  "message": "Pentest queued for My Workspace"
}
```

**SDK Code**

```python
import requests

url = "https://api.pensar.dev/pentests"

payload = {}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.pensar.dev/pentests';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.pensar.dev/pentests"

	payload := strings.NewReader("{}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.pensar.dev/pentests")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.pensar.dev/pentests")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.pensar.dev/pentests', [
  'body' => '{}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.pensar.dev/pentests");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.pensar.dev/pentests")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```