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

# Unlink an account

> Handle Bilt ending a link from the Bilt app, or end a link from your product

Either side can end a link, and both unlink calls are idempotent.

## Before you begin

* If Bilt calls you on unlink, host [Unlink an account](/api-reference/endpoints-you-host/unlink-an-account.md) with the bearer credential you issued to Bilt.
* Store the `linkId` from [Create a link](/api-reference/account-links/create-a-link.md) or [Get a link](/api-reference/account-links/get-a-link.md).
* Get your partner access token. See [Authentication](/partners/authentication.md).

## How it works

When the member disconnects in the Bilt app, Bilt calls you. When your customer disconnects in your product, you call Bilt. Either way the link ends, and both sides converge on the same state.

| Endpoint you host | What Bilt uses it for | Reference |
| - | - | - |
| `POST /bilt/unlink-account` | End the link when the member disconnects in the Bilt app | [Unlink an account](/api-reference/endpoints-you-host/unlink-an-account.md) |

## Steps

### Handle an unlink from the Bilt app

Bilt calls [Unlink an account](/api-reference/endpoints-you-host/unlink-an-account.md) when the member disconnects your product in the Bilt app. It uses the same bearer credential as your other endpoints.

**1. Find the link**

Look the link up by `partnerMemberId`. Return `404 LINK_NOT_FOUND` when there is none. Bilt treats that as a successful unlink.

**2. Check the member**

When Bilt sends `biltMemberId`, check that it matches the stored link. Return `409 MEMBER_ID_MISMATCH` when it does not.

**3. Clean up**

Return `200`. Then delete the stored `biltMemberId`, remove your link records for the member, and stop sending their activity to Bilt.

### End a link from your product

Call [End a link](/api-reference/account-links/end-a-link.md) when your customer disconnects Bilt in your product or closes their account.

* Authenticate with your partner access token, not the credential you issued to Bilt. That credential returns `401`.
* Send the `partnerUserId` and the `linkId` from the create or get response. The `linkId` stops a delayed retry from ending a newer link.
* A `204` means the link is `LINK_REVOKED`, and the member stops earning. A repeat also returns `204`.
* A `404 LINK_NOT_FOUND` means no link of yours has that ID. Clean up and treat it as done.

A `409 INVALID_STATE_TRANSITION` means the link is mid-transition, which happens only for partners Bilt calls on unlink. Wait one to two seconds and resend. If it persists, contact Bilt with the `requestId`.

When your own unlink flow finds no linked account, answer your UI with an error such as `NO_LINKED_ACCOUNT`.

## What can go wrong

* You send the credential you issued to Bilt. Bilt answers [`401`](/partners/errors-and-retries#error-codes).
* No link of yours has that `linkId`. Bilt answers [`404 LINK_NOT_FOUND`](/partners/errors-and-retries#error-codes). Clean up and treat it as done.
* The link is mid-transition. Bilt answers [`409 INVALID_STATE_TRANSITION`](/partners/errors-and-retries#error-codes). Wait one to two seconds and resend.
* Bilt sends a `biltMemberId` that does not match. Answer [`409 MEMBER_ID_MISMATCH`](/api-reference/endpoints-you-host/unlink-an-account).

## Next steps

* After a link ends, the member can link again through either flow, with a new `linkId`. See [Link from the Bilt app](/partners/account-linking/link-from-the-bilt-app.md).
* [Errors and retries](/partners/errors-and-retries.md) covers every error code.


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