Quick Start
Documentation for EchoBot API, links: Official website: https://echobot.ai/ EchoBot portal: https://portal.echobot.ai/
Get your API keys
Your API requests are authenticated using API keys. Any request that doesn't include an API key will return an error.
You can generate an API key from the EchoBot portal in the API section of the account page. Or at this link: https://portal.echobot.ai/account?currentTab=apikey. To create an API key click on the create button on the top right.

The API is accessible to the Starter, Premium and Enterprise plans.
Official Endpoint
The best way to interact with our API is through our official endpoint: https://portal.echobot.ai/api/openapi
baseUrl: "https://portal.echobot.ai/api/openapi"
headers: {
// Example Key
apikey: "echobot-r5lbdhot32hvcfd1wg12"
}Make your first request
To make your first request, send an authenticated request to the completions endpoint. This will generate a response based on a prompt or list of conversation messages.
Application Conversation
POST https://portal.echobot.ai/api/openapi/v1/chat/completions
Send a chat message
Headers
Bearer *
String
You can generate an API key from the EchoBot portal in the account's API section.
It is in this format: f"{echobot_token}-{echobot_botId}"
Request Body
chatId*
string
When undefined (not passed in), the context function provided by EchoBot is not used, and the context is built entirely from the incoming messages. - When '' is null, it means the first conversation in the new window. The response value will have a newChatId - When it is a non-empty string, it means that the chatId is used for the conversation and the history is automatically fetched from the EchoBot database.
stream
boolean
Weather to stream the response of not
messages
list
List of messages, this is the same format as OpenAI chat completions.
"rawSearch": [
{
"id": "19339",
"q": "Who is the director of the movie Journey to Bell Bud?" .
"a": "The director of the movie Journey to Suzumiya is Makoto Shinkai." .
"source": ""
},
{
"id": "8099",
"q": "Who is the main character of this work?" .
"a": "The main character of this work is a young girl named Suzumiya." .
"source": "Manual modification"
}
],
"newChatId": "648f0fc12e0d47315f3bc30e",
"id": "",
"model": "gpt-3.5-turbo-16k",
"usage": {
"prompt_tokens": 0,
"completion_tokens": 0,
"total_tokens": 373
},
"choices": [
{
"message": [
{
"role": "assistant",
"content": "The director of the movie Reiya no Trip is Makoto Shinkai."
}
],
"finish_reason": "stop",
"index": 0
}
]
}unAuthorization - API key authentication error,
insufficientQuota - insufficient credit balance
unAuthModel - no rights to use the model
unAuthKb - no rights to use the knowledge baseevent: chatResponse
data: {"newChatId": "648f0fc12e0d47315f3bc30e","quoteLen":8}
event: answer
data: {"id":"","object":"","created":0,"choices":[{"delta":{"content":""},"index":0,"finish_reason":null}]}
event: answer
data: {"id":"","object":"","created":0,"choices":[{"delta":{"content":"How"},"index":0,"finish_reason":null}]}
event: answer
data: {"id":"","object":"","created":0,"choices":[{"delta":{"content":"can"},"index":0,"finish_reason":null}]}
event: answer
data: {"id":"","object":"","created":0,"choices":[{"delta":{"content":"I"},"index":0,"finish_reason":null}]}
event: answer
data: {"id":"","object":"","created":0,"choices":[{"delta":{"content":"help"},"index":0,"finish_reason":null}]}
event: answer
data: {"id":"","object":"","created":0,"choices":[{"delta":{"content":"you"},"index":0,"finish_reason":null}]}
event: answer
data: {"id":"","object":"","created":0,"choices":[{"delta":{"content":"today?"},"index":0,"finish_reason":null}]}
data: [DONE]Take a look at how you might call this method using our official endpoint, or via curl:
curl --location --request POST 'https://portal.echobot.ai/api/openapi/v1/chat/completions' \
--header 'Authorization: Bearer apikey-botId' \
--header 'Content-Type: application/json' \
--data-raw '{
"chatId":"",
"stream":false,
"messages": [
{
"content": "Hi!",
"role": "user"
}
]
}'// TypeScript API stream example
type EchoBotWebChatProps = {
chatId?: string; // undefined: nonuse history, '': new chat, 'xxxxx': use history
appId?: string;
};
type EchoBotShareChatProps = {
password?: string;
shareId?: string;
};
export type Props = CreateChatCompletionRequest &
EchoBotWebChatProps &
EchoBotShareChatProps & {
messages: MessageItemType[];
};
export type ChatResponseType = {
newChatId: string;
quoteLen?: number;
};
export enum sseResponseEventEnum {
answer = 'answer',
chatResponse = 'chatResponse'
}
interface StreamFetchProps {
data: Props;
onMessage: (text: string) => void;
abortSignal: AbortController;
}
export const streamFetch = ({ data, onMessage, abortSignal }: StreamFetchProps) =>
new Promise<ChatResponseType & { responseText: string }>(async (resolve, reject) => {
try {
const response = await window.fetch('/api/openapi/v1/chat/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer echobot-z51pkjqm9nrk03a1rx2funoy-642adec15f04d67d4613efdb'
},
signal: abortSignal.signal,
body: JSON.stringify({
...data,
stream: true
})
});
if (!response?.body) {
throw new Error('Request Error');
}
const reader = response.body?.getReader();
const decoder = new TextDecoder('utf-8');
// response data
let responseText = '';
let newChatId = '';
let quoteLen = 0;
const read = async () => {
try {
const { done, value } = await reader.read();
if (done) {
if (response.status === 200) {
return resolve({
responseText,
newChatId,
quoteLen
});
} else {
return reject('Exceptions in the response process~');
}
}
const chunk = decoder.decode(value);
const chunkLines = chunk.split('\n\n').filter((item) => item);
const chunkResponse = chunkLines.map((item) => {
const splitEvent = item.split('\n');
if (splitEvent.length === 2) {
return {
event: splitEvent[0].replace('event: ', ''),
data: splitEvent[1].replace('data: ', '')
};
}
return {
event: '',
data: splitEvent[0].replace('data: ', '')
};
});
chunkResponse.forEach((item) => {
// parse json data
const data = (() => {
try {
return JSON.parse(item.data);
} catch (error) {
return item.data;
}
})();
if (item.event === sseResponseEventEnum.answer && data !== '[DONE]') {
const answer: string = data?.choices[0].delta.content || '';
onMessage(answer);
responseText += answer;
} else if (item.event === sseResponseEventEnum.chatResponse) {
const chatResponse = data as ChatResponseType;
newChatId = chatResponse.newChatId;
quoteLen = chatResponse.quoteLen || 0;
}
});
read();
} catch (err: any) {
if (err?.message === 'The user aborted a request.') {
return resolve({
responseText,
newChatId,
quoteLen
});
}
reject(getErrText(err, 'Request Exception'));
}
};
read();
} catch (err: any) {
console.log(err, '====');
reject(getErrText(err, 'Request Exception'));
}
});
//============================================================
// Stream requests, get data
const { newChatId, quoteLen } = await streamFetch({
data: {
messages, // Question, [{role:"user",content:"EchoBot What is it?"}]
chatId, // ID of the conversation
appId: modelId, // ID of the application
model: '' // Fixed fill-in-the-blank
},
onMessage: (text: string) => {
console.log(text)
},
abortSignal // Interrupt request, optional
});
```Last updated