Interaction API

This page details on how you can interact with Character.

Interacting with a Character

POST https://api.convai.com/character/getResponse

Users can implement a chatbot session for the end-users to converse with their character. The users can maintain the context of a conversation by maintaining the session-id in the API requests made.

Please remember to go through the list of "Important Points to Remember" mentioned at the end. They contain key information on the constraints and requirements to execute a successful API call to this endpoint.

Headers

NameTypeDescription

CONVAI-API-KEY*

String

The unique api-key provided for every user.

Request Body

NameTypeDescription

userText*

String

The query or input of the user interacting with the charater.

charID*

String

The ID of the character that the user is interacting with.

sessionID*

String

Used to identify a session of conversation to maintain the context.

voiceResponse*

Boolean

To generate an audio file for the response in the voice of the character.

audio*

File

The audio file containing the query of the user, in base64 format.

sample_rate

String

Sample rate of the audio file being sent.

{
    "charID": "<character id sent in the request body>",
    "text": "<response generated by the language model to the query>",
    "audio": null / "<base64 encoded audio>"
    "sample_rate": null / "<sample rate of the audio in Hz>"
    "sessionID": "<your session id. In case of a new session, it returns a newly generated value or returns the old one>"
}

Important Points to Remember:

  • The API endpoint expects the request body to contain only one type of input (either text input, via userText, or audio input via file). Including both types of input or none will result in an error.

  • We strictly adhere to OpenAI’s Content Policy for API usage and expect the user to respect the rules as well, to prevent the generation of toxic and inappropriate content. Repeated violations will result in the API key being blacklisted.

  • Please note that the body of the request should be form-data. This is to maintain consistency of format while uploading audio files.

  • Sending -1 as the session ID value starts a new chat session. Use the returned session ID in subsequent getResponse requests to ensure conversation context is maintained.

  • While sending an audio file, make sure that it should have a bit depth of at least 16 bits or higher.

Here are some sample codes to demonstrate the request format for the endpoint -->

Request with text only:

import requests
import json
import base64

url = "https://api.convai.com/character/getResponse"

payload={
    'userText': 'What is your name ?',
    'charID': '<your character id>',
    'sessionID': '-1',
    'voiceResponse': 'True'
}

headers = {
  'CONVAI-API-KEY': '<your api key>'
}

response = requests.request("POST", url, headers=headers, data=payload)

data = response.json()

character_response = data["text"]

decode_string = base64.b64decode(data["audio"])

with open('audioResponse.wav','wb') as f:
  f.write(decode_string)

Request with audio only:

import requests
import json
import base64

url = "https://api.convai.com/character/getResponse"

payload={
		'charID': '<your character id>',
		'sessionID': '-1',
		'responseLevel': '5',
		'voiceResponse': 'True'}
files=[
  ('file',('audio.wav',open('<path to the audio file audio.wav>','rb'),'audio/wav'))
]
headers = {
  'CONVAI-API-KEY': '<your api key>'
}

response = requests.request("POST", url, headers=headers, data=payload, files=files)
data = response.json()

character_response = data["text"]

decode_string = base64.b64decode(data["audio"])

with open('audioResponse.wav','wb') as f:
  f.write(decode_string)

Last updated