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

# Release

> End your link to an account once it is empty: what must be settled first, and what happens after.

`POST /v1/partner/accounts/{accountId}/release` ends your link to an account. The account stays an ordinary Kash user, but you can no longer act for it: from then on every route answers it `404 ACCOUNT_NOT_FOUND`, and no further webhooks arrive for it.

Users have no Kash login yet, so a released account's funds would be out of their reach. The API therefore refuses to release an account that still holds anything.

## Empty the account first

**1. Close its positions**

Sell open positions, or wait for their markets to resolve. `GET /v1/portfolio/positions` with `Kash-Account` lists them. Winnings are paid in automatically when a market resolves.

**2. Withdraw the USDC**

Read `maxAmountAtomic` from the [withdrawal quote](https://docs.kash.bot/developer-docs/partner-integration/withdrawals.md#quote-first) and withdraw it. Wait for `withdrawal.completed`.

**3. Wait two minutes**

Anything that finished in the last two minutes still blocks a release, while the chain catches up.

**4. Release**

Call release. The answer is `200` with the account in `released`.

A suspended account cannot withdraw. To empty one that still holds USDC, reactivate it, withdraw, then release.

```bash theme={null}
curl -X POST "$KASH_API/partner/accounts/$ACCOUNT_ID/release" \
  -H "X-API-Key: $KASH_PARTNER_KEY" \
  -H "Idempotency-Key: release-hsp-user-8841"
```

## When a release is refused

`409 RELEASE_REQUIRES_EMPTY_ACCOUNT` while the account:

* holds USDC;
* holds a position in a market that has not resolved;
* holds a winning position it has not redeemed;
* holds a position in a cancelled market;
* has a trade, redemption, payout, withdrawal, or other transfer or charge on its wallet that has not finished, including a payout the API makes when a market resolves and a withdrawal that failed and returned its USDC;
* had any of those finish less than two minutes ago.

A losing position in a resolved market is worth nothing and does not stop a release. Holdings are read from the chain. The `detail` says what was found first:

| Found | `detail` |
| - | - |
| USDC | "The account still holds USDC. Withdraw it to the registered destination, then release." |
| A withdrawal not final | "A withdrawal for this account is not final yet. Wait until it completes, then release." |
| A position | "The account still holds open positions. Sell or redeem them, withdraw the USDC, then release." |
| A trade not final | "A trade for this account is not final yet. Wait until it completes, withdraw what it leaves, then release." |
| A redemption or payout not final | "A redemption or payout for this account is not final yet. Wait until it completes, withdraw the USDC, then release." |
| A transfer or charge not final | "A transfer, payment or charge on this account is not final yet. Wait until it completes, withdraw what it leaves, then release." |
| Something finished recently | "A trade, redemption, payout, withdrawal or transfer for this account finished less than two minutes ago. Wait two minutes, then release." |

`503 DEPENDENCY_UNAVAILABLE` when the holdings cannot be read from the chain, when the account-changes switch cannot be read, or when the account kept changing while it was being released. `503 ROUTE_DISABLED` when account changes are switched off. Nothing changed; retry.

## Accounts with no wallet

An account in `provisioning` or `provisioning_failed` has no wallet, so it holds nothing and is released without a chain read. Releasing a `provisioning_failed` account is how you clear it before creating the user's account again.

## After a release

* You receive [`account.released`](https://docs.kash.bot/developer-docs/partner-integration/webhooks#account-events).
* The account answers `404 ACCOUNT_NOT_FOUND` everywhere and is no longer listed.
* No further webhooks arrive for it, apart from a destination change made before the release that is delivered after it, since webhooks are not ordered.
* The `externalId` is free: creating it again makes a new account with a new `accountId`.
* A retry of the release with the same `Idempotency-Key` replays the stored `200`. Without the key, a second release answers `404`.

## Next

> [card] [Webhooks](https://docs.kash.bot/developer-docs/partner-integration/webhooks.md)
>
> Every event your endpoint receives.

> [card] [Errors](https://docs.kash.bot/developer-docs/partner-integration/errors.md)
>
> Every code a partner integration can meet.


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