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

# Delete policy

DELETE https://platform.lakera.ai/api/v1/policies/{policyId}

Delete a policy. A policy cannot be deleted while any project is assigned to it — reassign those projects first.


Reference: https://docs.lakera.ai/api-reference/platform-api/policies/delete-policy

## Authentication

- `Authorization` header (bearer token, required) — Bearer authentication using API key. Generate an API key from the AI Guardrails Dashboard. Example: Bearer sk_123... Keys carry one of two access scopes, chosen when the key is created: - **Read and write** — may call every endpoint. This is the default, and the scope of every key created before scopes were introduced. - **Read only** — may call read endpoints such as `/v1-beta/logs`, `/v1-beta/analytics` and the `GET` endpoints. Write endpoints return `403`. Issue a read-only key to anything that only needs to retrieve data, such as a log-shipping job or a dashboard, so that it cannot modify your policies or projects.

## Request

### Path parameters

- `policyId` (string, required)

## Response

### 200

Policy deleted

- `status` (enum, optional) — Response status
  - Allowed values: `ok`
- `message` (string, optional) — Human-readable response message
- `id` (string, optional) — Policy ID

## Errors

### 403 Forbidden Error

Your API key is read-only and this endpoint writes, Policies V2 is not enabled for your organization, or your organization has reached its maximum number of policies.

- `status` (enum, optional) — Response status
  - Allowed values: `error`
- `error` (string, optional) — Short machine-readable error identifier
- `message` (string, optional) — Human-readable error message
- `code` (integer, optional) — HTTP status code
- `request_id` (string, optional) — Unique identifier for the request

### 404 Not Found Error

No policy with this ID exists in your organization

- `status` (enum, optional) — Response status
  - Allowed values: `error`
- `error` (string, optional) — Short machine-readable error identifier
- `message` (string, optional) — Human-readable error message
- `code` (integer, optional) — HTTP status code
- `request_id` (string, optional) — Unique identifier for the request

### 409 Conflict Error

The policy is still assigned to one or more projects

- `status` (enum, optional) — Response status
  - Allowed values: `error`
- `error` (string, optional) — Short machine-readable error identifier
- `message` (string, optional) — Human-readable error message
- `code` (integer, optional) — HTTP status code
- `request_id` (string, optional) — Unique identifier for the request

## Examples

**Response**

```json
{
  "status": "ok",
  "message": "policy created",
  "id": "policy-123456-random-g74j7"
}
```

**SDK Code**

```python
import requests

url = "https://platform.lakera.ai/api/v1/policies/policy-123456-random-g74j7"

headers = {"Authorization": "Bearer <token>"}

response = requests.delete(url, headers=headers)

print(response.json())
```

```javascript
const url = 'https://platform.lakera.ai/api/v1/policies/policy-123456-random-g74j7';
const options = {method: 'DELETE', headers: {Authorization: 'Bearer <token>'}};

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"
	"net/http"
	"io"
)

func main() {

	url := "https://platform.lakera.ai/api/v1/policies/policy-123456-random-g74j7"

	req, _ := http.NewRequest("DELETE", url, nil)

	req.Header.Add("Authorization", "Bearer <token>")

	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://platform.lakera.ai/api/v1/policies/policy-123456-random-g74j7")

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

request = Net::HTTP::Delete.new(url)
request["Authorization"] = 'Bearer <token>'

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.delete("https://platform.lakera.ai/api/v1/policies/policy-123456-random-g74j7")
  .header("Authorization", "Bearer <token>")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('DELETE', 'https://platform.lakera.ai/api/v1/policies/policy-123456-random-g74j7', [
  'headers' => [
    'Authorization' => 'Bearer <token>',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://platform.lakera.ai/api/v1/policies/policy-123456-random-g74j7");
var request = new RestRequest(Method.DELETE);
request.AddHeader("Authorization", "Bearer <token>");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Authorization": "Bearer <token>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://platform.lakera.ai/api/v1/policies/policy-123456-random-g74j7")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "DELETE"
request.allHTTPHeaderFields = headers

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()
```