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/
Send queries to the api.ai platform.
<a name=“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. |
{
"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"
}
{
"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"
}
}
}
}
<a name=“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 |
{ "apiKey": "...",
"text": "...",
"language": "..."
}
{
"callback":"success",
"contextWrites":{
"#":{
"to": {
wav audio file encoded with base64
}
}
}
}
<a name=“getContextx”/>
Method description
Field | Type | Description |
---|---|---|
apiKey | credentials | Access token obtained fron API.AI |
sessionId | String | Session Id |
{
"apiKey": "...",
"sessionId": "..."
}
{
"callback":"success",
"contextWrites":{
"#":{
"to":[{
"name": "greetings",
"parameters": {
"name": "Sam"
},
"lifespan": 3
}]
}
}
}
<a name=“getContext”/>
Method description
Field | Type | Description |
---|---|---|
apiKey | credentials | Access token obtained fron API.AI |
sessionId | String | Session Id |
contextName | String | Context name. |
{
"apiKey": "...",
"sessionId": "..."
}
{
"callback":"success",
"contextWrites":{
"#":{
"to":[{
"name": "greetings",
"parameters": {
"name": "Sam"
},
"lifespan": 3
}]
}
}
}
<a name=“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. |
{
"apiKey": "token",
"sessionId": "1234567890",
"name": "test",
"lifeSpan": "3",
"parameters": {
"name": "Sam",
"value": "test"
}
}
{
"callback":"success",
"contextWrites":{
"#":{
"to":{
"names": [
"greetings"
],
"status": {
"code": 200,
"errorType": "success"
}
}
}
}
}
<a name=“clearContexts”/>
Method description
Field | Type | Description |
---|---|---|
apiKey | credentials | Access token obtained fron API.AI. |
sessionId | String | Session Id |
{
"apiKey": "...",
"sessionId": "..."
}
{
"callback":"success",
"contextWrites":{
"#":{
"to":{
"names": [
"greetings"
]
...,
"status": {
"code": 200,
"errorType": "success"
}
}
}
}
}
<a name=“deleteContext”/>
Method description
Field | Type | Description |
---|---|---|
apiKey | credentials | Access token obtained fron API.AI. |
sessionId | String | Session Id |
contextName | String | Context name. |
{
"apiKey": "...",
"sessionId": "...",
"contextName": "..."
}
{
"callback":"success",
"contextWrites":{
"#":{
"to":{
"names": [
"greetings"
],
"status": {
"code": 200,
"errorType": "success"
}
}
}
}
}