RapidAPI logo

ApiAI

FREE
By serg.osipchuk
Updated 6 months ago
Machine Learning
5.1/10
Popularity Score
579ms
Latency
100%
Success Rate

ApiAI API Overview

Connect to the ApiAI API to build intelligent natural language bots powered by AI. Test an API call in your browser and export the code snippet into your app.

The ApiAI API is free as of 3/1/2017: https://api.ai/pricing/

Contact API Provider
star-blueRate

ApiAI

Api.ai Package

Send queries to the api.ai platform.

  • Domain: api.ai
  • Credentials: apiKey

How to get credentials:

  1. Got to https://console.api.ai
  2. Setting->general, copy access_token.

TOC:

Api.ai.query

Method description

Field Type Description
apiKey credentials Access token obtained from API.AI
query String Natural language text to be processed. Requests can have multiple 'query' parameters.
sessionId String A string token up to 36 symbols long, used to identify the client and to manage session parameters (including contexts) per client.
lang String Language tag, e.g., en, es etc.
context JSON Optional: Array of additional context objects. Should be sent via a POST /query request. Contexts sent in a query are activated before the query.
entities JSON Optional: Array of entities that replace developer defined entities for this request only. The entity(ies) need to exist in the developer console. Entities JSON format follows the format used in the /entities endpoint.
timezone String Optional:Time zone from IANA Time Zone Database
location JSON Optional: Latitude and longitude values. Example: {"latitude": 37.4256293, "longitude":-122.20539}.
resetContexts String Optional: If true, all current contexts in a session will be reset before the new ones are set. False by default.

Request example

{
    "apiKey": "token",
    "query": "and for tomorrow",
    "timezone": "GMT-5",
    "lang": "en",
    "contexts": [{
        "name": "weather",
        "parameters": {
            "city": "London"
        },
        "lifespan": 4
    }, {
        "name": "music",
        "parameters": {
            "city": "London",
            "test": "value"
        },
        "lifespan": 4
    }],
    "sessionId": "1234567890"
}

Response example

{
    "callback":"success",
    "contextWrites":{
        "#":{
            "to":{
                   "id": "9b49f2fb-fdd4-46f1-aa0d-7c4ed2caccdc",
                   "timestamp": "2016-09-08T05:34:23.167Z",
                   "result": {
                     "source": "agent",
                     "resolvedQuery": "my name is Sam and I live in Paris",
                     "action": "",
                     "actionIncomplete": false,
                     "parameters": {
                       "city": "Paris",
                       "user_name": "Sam"
                     },
                     "contexts": [
                       {
                         "name": "greetings",
                         "parameters": {
                           "city": "Paris",
                           "user_name": "Sam",
                           "city.original": "Paris",
                           "user_name.original": "Sam"
                         },
                         "lifespan": 5
                       }
                     ],
                     "metadata": {
                       "intentId": "373a354b-c15a-4a60-ac9d-a9f2aee76cb4",
                       "webhookUsed": "false",
                       "intentName": "greetings"
                     },
                     "fulfillment": {
                       "speech": "Nice to meet you, Sam!"
                     },
                     "score": 1
                   },
                   "status": {
                     "code": 200,
                     "errorType": "success"
                   },
                   "sessionId": "7501656c-b86e-496f-ae03-c2c800b851ff"
                 }
        }
    }
}

Api.ai.textToSpeech

Method description

Field Type Description
apiKey credentials Access token obtained fron API.AI
text String text
language String A single header value is used to identify TTS language. For example: en-US

Request example

{    "apiKey": "...",
    "text": "...",
    "language": "..."
}

Response example

{
    "callback":"success",
    "contextWrites":{
        "#":{
            "to": {
                    wav audio file encoded with base64
                  }
        }
    }
}

Api.ai.getContextx

Method description

Field Type Description
apiKey credentials Access token obtained fron API.AI
sessionId String Session Id

Request example

{    
    "apiKey": "...",
    "sessionId": "..."
}

Response example

{
    "callback":"success",
    "contextWrites":{
        "#":{
            "to":[{
                     "name": "greetings",
                     "parameters": {
                         "name": "Sam"
                     },
                     "lifespan": 3
                 }]
        }
    }
}

Api.ai.getContext

Method description

Field Type Description
apiKey credentials Access token obtained fron API.AI
sessionId String Session Id
contextName String Context name.

Request example

{    
    "apiKey": "...",
    "sessionId": "..."
}

Response example

{
    "callback":"success",
    "contextWrites":{
        "#":{
            "to":[{
                     "name": "greetings",
                     "parameters": {
                         "name": "Sam"
                     },
                     "lifespan": 3
                 }]
        }
    }
}

Api.ai.addContext

Method description

Field Type Description
apiKey credentials Access token obtained fron API.AI.
sessionId String Session Id
name String Context name.
lifeSpan String Optinal: Number of requests after which the context will expire.
parameters JSON Optional: Array of parameters used with the action.

Request example

{
    "apiKey": "token",
    "sessionId": "1234567890",
    "name": "test",
    "lifeSpan": "3",
    "parameters": {
        "name": "Sam",
        "value": "test"
    }
}

Response example

{
    "callback":"success",
    "contextWrites":{
        "#":{
            "to":{
                     "names": [
                         "greetings"
                     ],
                     "status": {
                         "code": 200,
                         "errorType": "success"
                     }
                 }
        }
    }
}

Api.ai.clearContexts

Method description

Field Type Description
apiKey credentials Access token obtained fron API.AI.
sessionId String Session Id

Request example

{    
    "apiKey": "...",
    "sessionId": "..."
}

Response example

{
    "callback":"success",
    "contextWrites":{
        "#":{
            "to":{
                     "names": [
                             "greetings"
                         ]
                         ...,
                     "status": {
                         "code": 200,
                         "errorType": "success"
                     }
                 }
        }
    }
}

Api.ai.deleteContext

Method description

Field Type Description
apiKey credentials Access token obtained fron API.AI.
sessionId String Session Id
contextName String Context name.

Request example

{    
    "apiKey": "...",
    "sessionId": "...",
    "contextName": "..."
}

Response example

{
    "callback":"success",
    "contextWrites":{
        "#":{
            "to":{
                     "names": [
                         "greetings"
                     ],
                     "status": {
                         "code": 200,
                         "errorType": "success"
                     }
                 }
        }
    }
}

Install SDK for NodeJS

Installing

To utilize unirest for node.js install the the npm module:

$ npm install unirest

After installing the npm package you can now start simplifying requests like so:

var unirest = require('unirest');

Creating Request

unirest.post("https://ApiAIserg-osipchukV1.p.rapidapi.com/addContext")
.header("X-RapidAPI-Host", "ApiAIserg-osipchukV1.p.rapidapi.com")
.header("X-RapidAPI-Key", "SIGN-UP-FOR-KEY")
.header("Content-Type", "application/x-www-form-urlencoded")
.end(function (result) {
  console.log(result.status, result.headers, result.body);
});
OAuth2 Authentication
Client ID
Client Secret
OAuth2 Authentication