> ## Documentation Index
> Fetch the complete documentation index at: https://docs.paywithlocus.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Clean up integration tests

> Retire live test users and reset policies while preserving transaction history.

Retire live test users when your integration tests are finished. This revokes their access while preserving the records needed to explain prior charges.

<Note>
  [Sandbox keys](/locus-pro/sandbox) create no live balances or end users and
  need no cleanup.
</Note>

## Prepare a test user for retirement

<Steps>
  <Step title="Stop new activity">
    Stop issuing calls, tokens, and top-ups for the identity.
  </Step>

  <Step title="Wait for pending activity">
    Let in-flight calls settle and hosted checkout sessions complete or expire.
  </Step>

  <Step title="Return the remaining credits">
    Deallocate the balance to the workspace pool.
  </Step>
</Steps>

If retirement returns `409 END_USER_RETIREMENT_BLOCKED`, resolve the conditions listed in the response and retry.

## Retire the user

A workspace owner or admin with `tokens:manage` completes fresh MFA or passkey
verification, then calls:

```http title="Retire a test user" theme={null}
DELETE /api/credits/end-users/{externalUserId}
Authorization: Bearer <dashboard session>
X-Locus-Step-Up: <fresh step-up token>
```

<Warning>
  Retirement leaves the identity inactive. Issuing a new token cannot
  reactivate it. To reuse the identity, [reset its policy](#reset-a-policy-without-retiring-the-user) instead.
</Warning>

Retirement revokes tokens and Agent Connections, cancels cost approvals,
resets the active policy, and freezes the account.

Repeated retirement is safe. Financial and security history remain available.

## Reset a policy without retiring the user

Use this when the identity should remain available for another test:

```http title="Reset a policy" theme={null}
DELETE /api/credits/end-users/{externalUserId}/policy
Authorization: Bearer <dashboard session or scoped secret key>
```

The caller needs `tokens:manage`; dashboard callers must be an owner or admin. The reset waits until no active reservation depends on the policy and preserves its decision history.

The [API reference](/api-reference/introduction) covers permissions, blockers, and responses.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.