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

# Anonymize Chat Completion

POST https://your-agent-domain.com/api/v1/chat/completions/{id}/anonymize

Redacts detected personal data in this chat completion's message-adjacent text with regex, then an optional hosted redaction service when the Agent has that option on. Conversation rows, identifiers, likes, flags, and analytics identity stay in place. Repeat calls finish leftover rows and skip text that is already redacted.

Reference: https://docs.apologist.ai/agent-api/api-reference/chat-completions/anonymize-completion

## Authentication

- `x-api-key` header (required) — API key for authentication
- `Authorization` header (bearer token, required) — Bearer token authentication

## Request

### Path parameters

- `id` (string, required) — The numeric id or UUID of the chat completion

## Response

### 200

Anonymize progress for the chat completion

- `data` (object, optional) — Result of scrubbing or anonymizing a chat completion's message-adjacent text. Rows and identifiers are kept.
  - `id` (string, optional) — Chat completion id (UUID).
  - `mode` (enum, optional)
    - Allowed values: `scrub`, `anonymize`
  - `messages_redacted` (integer, optional) — Message rows rewritten in this request.
  - `remaining` (integer, optional) — Message rows still waiting. Zero means this request finished the completion.

## Errors

### 403 Forbidden Error

Forbidden - Invalid or missing API key

- `any`

### 404 Not Found Error

Chat completion not found

- `any`

### 500 Internal Server Error

Internal Server Error

- `any`

## Examples

**Response**

```json
{
  "data": {
    "id": "string",
    "mode": "scrub",
    "messages_redacted": 1,
    "remaining": 1
  }
}
```

**SDK Code**

```typescript
import { ApologistAgentClient } from "apologist";

async function main() {
    const client = new ApologistAgentClient({
        apiKey: "YOUR_API_KEY_HERE",
    });
    await client.chat.anonymizeCompletion({
        id: "id",
    });
}
main();

```

```python
from apologist import ApologistAgentClient

client = ApologistAgentClient(
    api_key="YOUR_API_KEY_HERE",
)

client.chat.anonymize_completion(
    id="id",
)

```

```java
package com.example.usage;

import ai.apologist.AgentClient;
import ai.apologist.resources.chat.requests.AnonymizeCompletionRequest;

public class Example {
    public static void main(String[] args) {
        AgentClient client = AgentClient
            .builder()
            .apiKey("YOUR_API_KEY_HERE")
            .build();

        client.chat().anonymizeCompletion(
            "id",
            AnonymizeCompletionRequest
                .builder()
                .build()
        );
    }
}
```

```ruby
require "apologist"

client = Apologist::AgentClient.new(api_key: "YOUR_API_KEY_HERE")

client.chat.anonymize_completion(id: "id")

```

```csharp
using Apologist;
using System.Threading.Tasks;

public partial class Examples
{
    public async Task Example() {
        var client = new AgentClient(
            apiKey: "YOUR_API_KEY_HERE"
        );

        await client.Chat.AnonymizeCompletionAsync(
            new AnonymizeCompletionRequest {
                Id = "id"
            }
        );
    }

}

```

```go
package example

import (
    context "context"

    apgsdkgo "github.com/apologist-project/apg-sdk-go"
    client "github.com/apologist-project/apg-sdk-go/client"
    option "github.com/apologist-project/apg-sdk-go/option"
)

func do() {
    client := client.NewApologistAgentClient(
        option.WithAPIKey(
            "YOUR_API_KEY_HERE",
        ),
    )
    request := &apgsdkgo.AnonymizeCompletionRequest{
        ID: "id",
    }
    client.Chat.AnonymizeCompletion(
        context.TODO(),
        request,
    )
}

```

```php
<?php

namespace Example;

use Apologist\AgentClient;

$client = new AgentClient(
    apiKey: 'YOUR_API_KEY_HERE',
);
$client->chat->anonymizeCompletion(
    'id',
);

```

```swift
import Foundation

let headers = ["x-api-key": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://your-agent-domain.com/api/v1/chat/completions/id/anonymize")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
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()
```