Call a LUIS app using Node.js

Pass utterances to a LUIS endpoint and get intent and entities back.

Before you begin

You need a Cognitive Services API key to make calls to the sample LUIS app we use in this walkthrough. To get an API key follow these steps:

  1. You first need to create a Cognitive Services API account in the Azure portal. If you don't have an Azure subscription, create a free account before you begin.
  2. Log in to the Azure portal at
  3. Follow the steps in Creating Subscription Keys using Azure to get a key.
  4. Go back to the LUIS website and log in using your Azure account.

Understand what LUIS returns

To understand what a LUIS app returns, you can paste the URL of a sample LUIS app into a browser window. The sample app you'll use is an IoT app that detects whether the user wants to turn on or turn off lights.

  1. The endpoint of the sample app is in this format:<YOUR_API_KEY>&verbose=false&q=turn%20on%20the%20bedroom%20light Copy the URL and substitute your subscription key for the value of the subscription-key field.
  2. Paste the URL into a browser window and press Enter. The browser displays a JSON result that indicates that LUIS detects the HomeAutomation.TurnOn intent and the HomeAutomation.Room entity with the value bedroom.

    JSON result detects the intent TurnOn

  3. Change the value of the q= parameter in the URL to turn off the living room light, and press Enter. The result now indicates that the LUIS detected the HomeAutomation.TurnOff intent and the HomeAutomation.Room entity with value living room.

    JSON result detects the intent TurnOff

Consume a LUIS result using the Endpoint API with Node.js

You can use Node.js to access the same results you saw in the browser window in the previous step.

  1. Copy the following code snippet:

    var request = require('request');
    var querystring = require('querystring');
    function getLuisIntent(utterance) {
        var endpoint =
        // Set the LUIS_APP_ID environment variable 
        // to df67dcdb-c37d-46af-88e1-8b97951ca1c2, which is the ID
        // of a public sample application.    
        var luisAppId = process.env.LUIS_APP_ID;
        // Set the LUIS_SUBSCRIPTION_KEY environment variable
        // to the value of your Cognitive Services subscription key
        var queryParams = {
            "subscription-key": process.env.LUIS_SUBSCRIPTION_KEY,
            "timezoneOffset": "0",
            "verbose":  true,
            "q": utterance
        var luisRequest =
            endpoint + luisAppId +
            '?' + querystring.stringify(queryParams);
            function (err,
                response, body) {
                if (err)
                else {
                    var data = JSON.parse(body);
                    console.log(`Query: ${data.query}`);
                    console.log(`Top Intent: ${data.topScoringIntent.intent}`);
    // Pass an utterance to the sample LUIS app
    getLuisIntent('turn on the left light');
  2. Set the LUIS_APP_ID environment variable as described in the code comments.

  3. Set the LUIS_SUBSCRIPTION_KEY environment variable to your Cognitive Services subscription key.

  4. Run the code. It displays the same values that you saw earlier in the browser window.

Next steps