This article will take you to get started with Chatmax's API connection.
To connect to Chatmax, you first need to register and log in to the chatmax website, create a project and generate an api_key for authentication.
Chatmax uses a restful API style for programming, and most of the APIs use the POST method. In the chat API, it supports two methods of obtaining return data, streaming and non-streaming.
Chatmax currently has a group of online servers, and more server groups will be updated later.All functions are the same between the servers except for the URL.
We should save the selected URL as a constant, for example, in js, you can name it like this:
const BASE_URL = `https://us-openapi.orionstar.com`
Chatmax's API accepts two content types, 'application/json' and 'multipart/form-data', which correspond to common API calls and file uploads respectively.
'Content-Type': 'application/json',
In terms of API return, you can also fill in 'application/json'
'Accept': 'application/json',
The most important step is to add the header for authentication, please replace the following "bzecaexxxxxxx" with a real and valid api_key.
'orionstar-api-key' : 'bzecaexxxxxxxx'
In the end we combine it into a complete header, for example, it looks like this in js:
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'orionstar-api-key': 'bzecaexxxxxxx',
}
Chatmax uses POST to request the API. Here we take the document list API as an example, and use the fetch module to assemble a complete API call:
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'orionstar-api-key': 'bzecaexxxxxxx',
}
const BASE_URL = `https://us-openapi.orionstar.com`
const opts = {
method: 'POST',
headers: headers,
body: JSON.stringify({})
};
const url = BASE_URL + '/v1/ctai/ctai_doc_list'
const rst = await fetch(url, opts)
if (!rst.ok) {
console.log(`Server error: [${rst.status}] [${rst.statusText}] [${rst.url}]`);
}
const rstJson = await rst.json()
console.info('Request Response:',rstJson)
return rstJson
If everything is OK, you will receive the following return results.
{
"ret": "0",
"msg": "",
"stime": "1679921022",
"data": {
"total_count": "8",
"ctai_doc_list": [
{
"ctdoc_id": "test_doc_id",
"ctai_doc": {
"doc_type": "doc",
"doc_url": "http://test.com/a.html",
"doc_name": "test_name ",
"process_status": "end_succ",
"process_code": "0",
"create_time": "1680010349",
"update_time": "1680010352"
},
// other document information objects
}
]
},
"req_id": "test_req_id"
}
In the above return value, except for the data field, other parts are public response parameters, and their meanings are as follows:
parameter | type | Parameter Description |
---|---|---|
ret | string | Result code, string type, success is 0, failure is non-0, the specific error is detailed in the appendix and the specific interface description. |
msg | string | Error message, empty string if successful. |
stime | string | Integer timestamp of the current server, string type, unit is second. |
data | object | Response business parameter information object, different interfaces will have different response business parameters, see the description of response business parameters of each interface for details. |
req_id | string | Log tracking id, when you encounter a problem and need our technical support, please provide this tracking id so that we can track and investigate the cause of the problem. |