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

POST https://your-agent-domain.com/api/v1/users/{user_id}/anonymize

Redacts detected personal data in this user's message-adjacent text with regex, then an optional hosted redaction service when the Agent has that option on. Conversation rows, identifiers, 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/users/anonymize-user

## Authentication

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

## Request

### Path parameters

- `user_id` (string, required) — The user's external id or internal id

## Response

### 200

Anonymize progress for the user

- `data` (object, optional) — Result of scrubbing or anonymizing a user's message-adjacent text. Rows and identifiers are kept.
  - `id` (string, optional) — Internal user id (UUID).
  - `mode` (enum, optional)
    - Allowed values: `scrub`, `anonymize`
  - `redact_requested_at` (string, optional, nullable) — When the erase request was stamped. The hourly cron finishes leftover rows.
  - `messages_redacted` (integer, optional) — Message rows rewritten in this request.
  - `remaining` (integer, optional) — Message rows still waiting. Zero means this request finished the user.

## Errors

### 403 Forbidden Error

Forbidden - Invalid or missing API key

- `any`

### 404 Not Found Error

User not found

- `any`

### 500 Internal Server Error

Internal Server Error

- `any`

## Examples

**Response**

```json
{
  "data": {
    "id": "string",
    "mode": "scrub",
    "redact_requested_at": "string",
    "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.users.anonymizeUser({
        userId: "user_id",
    });
}
main();

```

```python
from apologist import ApologistAgentClient

client = ApologistAgentClient(
    api_key="YOUR_API_KEY_HERE",
)

client.users.anonymize_user(
    user_id="user_id",
)

```

```java
package com.example.usage;

import ai.apologist.AgentClient;
import ai.apologist.resources.users.requests.AnonymizeUserRequest;

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

        client.users().anonymizeUser(
            "user_id",
            AnonymizeUserRequest
                .builder()
                .build()
        );
    }
}
```

```ruby
require "apologist"

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

client.users.anonymize_user(user_id: "user_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.Users.AnonymizeUserAsync(
            new AnonymizeUserRequest {
                UserId = "user_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.AnonymizeUserRequest{
        UserID: "user_id",
    }
    client.Users.AnonymizeUser(
        context.TODO(),
        request,
    )
}

```

```php
<?php

namespace Example;

use Apologist\AgentClient;

$client = new AgentClient(
    apiKey: 'YOUR_API_KEY_HERE',
);
$client->users->anonymizeUser(
    'user_id',
);

```

```swift
import Foundation

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

let request = NSMutableURLRequest(url: NSURL(string: "https://your-agent-domain.com/api/v1/users/user_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()
```