> This page is for Gateway.

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

# Replace a project's prompt injection settings

PUT https://api-gateway.merge.dev/v1/projects/{project_id}/pi-settings
Content-Type: application/json

Replaces the override as a whole. Fields you omit inherit the organization value; send a field as null to clear it back to inheritance. An empty body means inherit everything, the same as DELETE. A project pinned to an API key uses this policy as written. A project named per request (project_id body field or X-Project-Id header) may only tighten the organization policy; anything that loosens it is ignored at request time.

Reference: https://docs.merge.dev/merge-gateway/management-api/projects/update-project-pi-settings

## Authentication

- `Authorization` header (bearer token, required) — A management key (prefixed `mgmt_`), created on the dashboard's **API keys** page under **Management keys**. Distinct from a regular gateway API key, and never used to call models.

## Request

### Path parameters

- `project_id` (string, required)

### Body (application/json)

This endpoint expects a PiProtectionOverride.

- `pi_mode` (enum, optional, nullable) — Direct-injection enforcement mode: off, alert, or block
  - Allowed values: `off`, `alert`, `block`
- `pi_block_threshold` (double, optional, nullable) — Direct-injection block threshold. Must be at least the organization's pi_pass_threshold, which is not overridable per project
- `pi_indirect_mode` (enum, optional, nullable) — Indirect-injection enforcement mode, a separate axis from pi_mode
  - Allowed values: `off`, `alert`, `block`
- `pi_tier2a_block_threshold` (double, optional, nullable) — Indirect-injection heuristic-confidence threshold
- `pi_tier2b_block_threshold` (double, optional, nullable) — Indirect-injection embedding-similarity threshold
- `pi_output_action` (enum, optional, nullable) — What to do when the response-side check fires
  - Allowed values: `observe`, `redact`, `route`, `block`, `escalate`
- `pi_fail_closed` (boolean, optional, nullable) — Whether to reject requests when the detection service is unavailable. Defaults to failing open
- `pi_allowlist_patterns` (list of string, optional, nullable) — Regexes whose matching segments skip scanning. Unioned with the organization's list, never replacing it. A pattern broad enough to match ordinary prose disables enforcement rather than narrowing it

## Response

### 200

The project's settings, with the effective policy resolved.

- `override` (PiProtectionOverride, optional) — What this project sets. Fields it does not set are null here
- `effective` (PiProtectionSettings, optional) — The policy a request to this project runs under, assuming the project is pinned to an API key
- `inherited_fields` (list of string, optional) — Fields taken from the organization policy because the project does not set them

## Errors

### 403 Forbidden Error

The management key lacks the `manage_projects` scope.

- `detail` (string, optional) — Human-readable error message.

### 404 Not Found Error

Project not found, or it belongs to another organization.

- `detail` (string, optional) — Human-readable error message.

### 422 Unprocessable Entity Error

Invalid field, unknown field, or an override the organization policy cannot support (for example a block threshold below the org's pass threshold).

- `detail` (string, optional) — Human-readable error message.

## Types

### PiProtectionOverride

A project's sparse prompt injection override. Every field is optional: omitted means inherit the organization value, null clears the field back to inheritance. Unknown fields are rejected with a 422.

- `pi_mode` (enum, optional, nullable) — Direct-injection enforcement mode: off, alert, or block
  - Allowed values: `off`, `alert`, `block`
- `pi_block_threshold` (double, optional, nullable) — Direct-injection block threshold. Must be at least the organization's pi_pass_threshold, which is not overridable per project
- `pi_indirect_mode` (enum, optional, nullable) — Indirect-injection enforcement mode, a separate axis from pi_mode
  - Allowed values: `off`, `alert`, `block`
- `pi_tier2a_block_threshold` (double, optional, nullable) — Indirect-injection heuristic-confidence threshold
- `pi_tier2b_block_threshold` (double, optional, nullable) — Indirect-injection embedding-similarity threshold
- `pi_output_action` (enum, optional, nullable) — What to do when the response-side check fires
  - Allowed values: `observe`, `redact`, `route`, `block`, `escalate`
- `pi_fail_closed` (boolean, optional, nullable) — Whether to reject requests when the detection service is unavailable. Defaults to failing open
- `pi_allowlist_patterns` (list of string, optional, nullable) — Regexes whose matching segments skip scanning. Unioned with the organization's list, never replacing it. A pattern broad enough to match ordinary prose disables enforcement rather than narrowing it

### PiProtectionSettings

A fully resolved prompt injection policy, with no field left to inherit.

- `pi_mode` (string, optional)
- `pi_block_threshold` (double, optional)
- `pi_pass_threshold` (double, optional)
- `pi_input_action` (string, optional)
- `pi_output_action` (string, optional)
- `pi_allowlist_patterns` (list of string, optional)
- `pi_safer_vendor_route` (string, optional, nullable)
- `pi_fail_closed` (boolean, optional)
- `pi_log_full_text_on_block` (boolean, optional)
- `pi_indirect_mode` (string, optional)
- `pi_tier2a_block_threshold` (double, optional)
- `pi_tier2b_block_threshold` (double, optional)

## Examples

**Request**

```json
{}
```

**Response**

```json
{
  "override": {
    "pi_mode": "off",
    "pi_block_threshold": 0.5,
    "pi_indirect_mode": "off",
    "pi_tier2a_block_threshold": 0.5,
    "pi_tier2b_block_threshold": 0.5,
    "pi_output_action": "observe",
    "pi_fail_closed": true,
    "pi_allowlist_patterns": [
      "string"
    ]
  },
  "effective": {
    "pi_mode": "string",
    "pi_block_threshold": 1.1,
    "pi_pass_threshold": 1.1,
    "pi_input_action": "string",
    "pi_output_action": "string",
    "pi_allowlist_patterns": [
      "string"
    ],
    "pi_safer_vendor_route": "string",
    "pi_fail_closed": true,
    "pi_log_full_text_on_block": true,
    "pi_indirect_mode": "string",
    "pi_tier2a_block_threshold": 1.1,
    "pi_tier2b_block_threshold": 1.1
  },
  "inherited_fields": [
    "string"
  ]
}
```

**SDK Code**

```python
import requests

url = "https://api-gateway.merge.dev/v1/projects/project_id/pi-settings"

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

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

print(response.json())
```

```javascript
const url = 'https://api-gateway.merge.dev/v1/projects/project_id/pi-settings';
const options = {
  method: 'PUT',
  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-gateway.merge.dev/v1/projects/project_id/pi-settings"

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

	req, _ := http.NewRequest("PUT", 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-gateway.merge.dev/v1/projects/project_id/pi-settings")

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

request = Net::HTTP::Put.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.put("https://api-gateway.merge.dev/v1/projects/project_id/pi-settings")
  .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('PUT', 'https://api-gateway.merge.dev/v1/projects/project_id/pi-settings', [
  'body' => '{}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://api-gateway.merge.dev/v1/projects/project_id/pi-settings");
var request = new RestRequest(Method.PUT);
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-gateway.merge.dev/v1/projects/project_id/pi-settings")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PUT"
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()
```