Skip to main content

Generate token

Find example source code here.

It is unsafe to use an API KEY directly on the client side so it is better to have a server generate the token in a safe way. The source code below can be used for this purpose.

import { InworldClient } from '@inworld/nodejs-sdk';

const run = async function () {
const token = await getToken();

// Use token here...
};

const getToken = async function() {
// Get key and secret from the integrations page.
const client = new InworldClient()
.setApiKey({
key: process.env.INWORLD_KEY,
secret: process.env.INWORLD_SECRET,
});

return client.generateSessionToken();
}

run();