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

# Migrating to SDK 2

> Steps for migrating from SDK 1 to SDK 2

## Steps to follow for migrating to SDK 2

### Step 1

Replace the Mindset SDK 1.0 file name `mindset-sdk.js` by `mindset-sdk-2.js`

The `MINDSET-SDK-URL` is also a new URL (not anymore your mindset AI app URL).

```javascript theme={null}
<script src="MINDSET-SDK-URL/mindset-sdk2.js"></script>
```

<Tip>
  Replace `MINDSET-SDK-URL` with the URL provided by Mindset AI.
</Tip>

### Step 2

Add the **`<mindset-agent>`** HTML tag in your HTML body

```javascript theme={null}
<mindset-agent 
    agentUid='YOUR-AGENT-UID'
    style='width: 100%; height: 600px; display: block; background-color: rgb(255, 255, 255);">
</mindset-agent>
```

### Step 3

Remove the javascript code that uses the SDK 1.0 methods (`initApp()` and `render()` or `startAgentThread()`). Your existing script should look like this:

```javascript theme={null}
mindset.initApp({ 
    appUid: "YOUR-APP-UID", 
    authToken: data.authToken,     
    containerId: "agent-div",      
    loadingText: "Please wait ..." 
})

mindset.startAgentThread({
    agentUid: "YOUR-AGENT-UID",  
    initialQuestion: "Some text to send to the agent"
});
```

### Step 4

Wrap your existing code in charge of fetching the `authToken` from your back-end script into an `async` method:

```javascript theme={null}
<script>
    async function getAuthToken() {
        const currentUserId = 'session123'
        const userAuthTokenServerUrl = `YOUR-BACKEND-API-RETURNING-AUTHTOKEN`
        // e.g. https://mycompany-backend/api/getusertoken/${currentUserId}

        try {
            const headers = {
                "accept": "application/json",
                "Content-Type": "application/json"
            };
            const response = await fetch(userAuthTokenServerUrl, {
                method: 'POST',
                headers: headers,
                body: JSON.stringify({"currentUserId": `${currentUserId}`})
            });
            if (!response.ok) {
                throw new Error(`HTTP error! status: ${response.status}`);
            }
            const responseData = await response.json();
            return responseData.authToken;
        } catch (error) {
            console.log('Error fetching auth token:', error);
            throw error;
        }
    }
</script>
```

### Step 5

Pass your function to the `mindset.init()` method

```javascript theme={null}
<script>
    mindset.init({fetchAuthentication: getAuthToken, appUid: "YOUR-APP-UID"})
</script>
```

<Tip>
  Please check a full example of an SDK 2 front-end page here: [Front-end full example](front-end#front-end-page-full-example)
</Tip>

If you would like further information on how details of the parameters are passed, please take a look at our API specifications [here](https://docs.mindset.ai/sdk-api/api/sdk-users/generate-an-auth-token-for-a-given-user-identifier).
