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

# Configure Anonymous Sessions

> Learn how to configure anonymous sessions using the Auth0 Management API.

export const ReleaseStageNotice = ({feature, stage, plans, contact, terms}) => {
  const stageTextMap = {
    "beta": "Beta",
    "ea": "Early Access"
  };
  const stageText = stageTextMap[stage] || "a product release stage";
  const prsLink = "/docs/troubleshoot/product-lifecycle/product-release-stages";
  const linkify = (text, url) => {
    return <a href={url} target="_blank" rel="noreferrer" class="link">{text}</a>;
  };
  const includeDetails = (plans, contact, terms) => {
    const hasDetails = terms || plans || contact;
    if (!hasDetails) return null;
    return <span data-as="p">
            {plans && <>This feature is available for {linkify(`${plans} plans`, "https://auth0.com/pricing")}. </>}
            {contact && "To participate, contact " + contact + ". "}
            {terms && <>By using this feature, you agree to the applicable Free Trial terms in Okta's {linkify("Master Subscription Agreement", "https://www.okta.com/legal")}.</>}
        </span>;
  };
  return <Warning>
            <span data-as="p">
                <strong>The {feature} feature is in {linkify(stageText, prsLink)}.</strong>
            </span>

            {includeDetails(plans, contact, terms)}
        </Warning>;
};

<ReleaseStageNotice feature="Anonymous Sessions" stage="beta" terms="true" contact="Auth0 Support" />

To configure anonymous sessions, you can use the Auth0 [Management API](/docs/api/management/v2).

## Prerequisites

To use anonymous sessions:

* You must [have an Auth0 account](https://auth0.com/).
* [Register your Auth0 application](/docs/get-started/auth0-overview/create-applications). If you do not have an Auth0 application, you can get started with the Auth0 React or Next.js [Quickstarts](https://auth0.com/docs/quickstart/spa/react).
* [Register an API (resource server)](/docs/get-started/auth0-overview/set-up-apis).

## Auth0 Management API

### Configure anonymous sessions in your Auth0 tenant

To set the anonymous sessions lifetime and token format, make a `PATCH` request to the [`/api/v2/tenants/settings`](/docs/api/management/v2/tenants/patch-settings) endpoint:

```json theme={null}
{
  "sessions": {
    "anonymous": {
      "lifetime_in_minutes": 1440,
      "token_format": "jwe"
    }
  }
}  
```

### Enable anonymous sessions in your application

To enable anonymous sessions in your Auth0 application, make a `PATCH` request to the [`/api/v2/clients/{id}`](/docs/api/management/v2/clients/patch-clients-by-id) endpoint:

```json theme={null}
{
  "anonymous_sessions": {
    "active": true
  }
}
```

### Enable anonymous access in your API

To enable anonymous sessions in your API, make a `PATCH` request to the [`/api/v2/resource-servers/{id}`](/docs/api/management/v2/resource-servers/patch-resource-servers-by-id) endpoint:

```json theme={null}
{
"allow_anonymous_access": true,
"token_lifetime_for_anonymous_access_tokens": 7200
}
```

## Create an anonymous session

Once anonymous sessions are configured in your tenant, application, and API, you can create an anonymous session by making a `POST` request to the `/anonymous/token` endpoint:

```json theme={null}
{
  "client_id": "YOUR_CLIENT_ID",
  "audience": "YOUR_AUDIENCE",
  "scope": "anon"
}
```

The response includes a `session_token` and an `access_token`:

```json theme={null}
{
  "session_token": "eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIn0...",
  "access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...",
  "token_type": "Bearer",
  "expires_in": 86400
}
```

## Next steps

* [Anonymous Sessions Use Cases](/docs/manage-users/sessions/anonymous-sessions/anonymous-sessions-use-cases) Learn about anonymous sessions use cases.
