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

# Logout User

> Invalidate access token and end user session

## Overview

Invalidate the current access token and end the user's session. After logout:

* Access token becomes invalid immediately
* All subsequent requests with this token will fail with 401 Unauthorized
* User must login again to get a new access token

<Note>
  For OAuth clients: Use `DELETE /v1/auth/oauth/revoke` to revoke OAuth authorization instead.
</Note>

## Request

### Headers

<ParamField header="x-client-key" type="string" required>
  Your public API client key
</ParamField>

<ParamField header="Authorization" type="string" required>
  Bearer token to invalidate

  **Format**: `Bearer ACCESS_TOKEN`
</ParamField>

## Response

```json theme={null}
{
  "success": true
}
```

## Code Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://dev.api.baanx.com/v1/auth/logout" \
    -H "x-client-key: your-client-key" \
    -H "Authorization: Bearer YOUR_ACCESS_TOKEN"
  ```

  ```javascript JavaScript theme={null}
  async function logout() {
    const accessToken = localStorage.getItem('access_token');

    const response = await fetch('https://dev.api.baanx.com/v1/auth/logout', {
      method: 'POST',
      headers: {
        'x-client-key': 'your-client-key',
        'Authorization': `Bearer ${accessToken}`
      }
    });

    if (response.ok) {
      // Clear stored tokens
      localStorage.removeItem('access_token');
      localStorage.removeItem('refresh_token');
      localStorage.removeItem('user_id');

      // Redirect to login page
      window.location.href = '/login';
    }
  }
  ```

  ```python Python theme={null}
  import requests

  def logout(access_token: str):
      response = requests.post(
          'https://dev.api.baanx.com/v1/auth/logout',
          headers={
              'x-client-key': 'your-client-key',
              'Authorization': f'Bearer {access_token}'
          }
      )

      if response.status_code == 200:
          # Clear session
          session.clear()
          print('Logged out successfully')
  ```
</CodeGroup>

<Tip>
  Always call logout on the server side before clearing tokens on the client to ensure the token is properly invalidated.
</Tip>
