# How to Use an Agent by calling the API

After the agent is published as an API service, it can be used by calling the API.

## Domain name
The system domain name is `https://chat.tate-a-tate.com/im`

## Authentication
Add Authorization to the head of request. The specific rules for generating Authorization are as follows:

The data structure is as follows:

```
{
"timestamp":1716884882,
"secretKey":"99970215-333f-4982-b627-1c5ee1f523fa",
"signature":"afd6e7bc00ef17e0c817c501a8060d67",
"alg":"simple"
}
```

| Field Name | Instruction | Is it required |
| --- | --- | --- |
| timestamp | Current timestamp, in seconds. Cannot exceed 3600 seconds of the current time. | View detailed algorithm description |
| secretKey | Secret key | True |
| signature | Signature | View detailed algorithm description |
| alg | Specific encryption algorithm, currently only supports simple algorithm | View detailed algorithm description |

## Simple encryption

| Field name | Instruction | Is it required |
| --- | --- | --- |
| timestamp | Current timestamp, in seconds. Cannot exceed 30 seconds of the current time. | false |
| secretKey | Secret key | true |
| signature | Signature | View detailed algorithm description |
| alg | Specific encryption algorithm, currently only supports simple algorithm | View detailed algorithm description |
|

signature=secretKey

alg=simple

Authorization is the above data structure encoded in base64.

## Send message interface
Interface address: `/admin/v1/msg/send`

Request method: `POST`

## Request Parameters

|  | Parameter Description | Request Type | Required | Data Type | Value |
| --- | --- | --- | --- | --- | --- |
| bot_id | Agent unique ID | header | true | string | a1cc0e70-6264-49bd-9356<br>-a2da46849dae |
| Authorization | Authorization code | header | true | String | ewogICAgInRpbWVzdGFt<br>cCI6MTcxNjg4NDg4MiwK<br>ICAgICJzaWduYXR1cmUi<br>OiJhZmQ2ZTdiYzAwZWY<br>xN2UwYzgxN2M1MDFhO<br>DA2MGQ2NyIsCiAgICAiY<br>WxnIjoibWQ1Igp9 |
| outsiderSendMsgDTO | External message Information API<br>Request DTO Object | body | true | OutsiderSendMsgDTO |  |
| conversationId | Session ID |  | false | string |  |
| msg | Message content |  | true | string |  |
| msgType | Normal text, msgType=1 |  | true | integer(int32) |  |
| parentMsgId | Parent message ID，Edit message pass Parent message<br>send message ID, Regenerate pass<br>the current message<br>ID; For example, New messages<br>Pass value 0 |  | true | string |  |
| reqModel | Request mode，Stream: Streaming call，Sync: Synchronous call |  | true | string |  |
| userAction | User action：new、edit、retry |  | true | string |  |

## Request example:

```
{
  "conversationId": "",
  "msg": "Hello",
  "msgType": 1,
  "parentMsgId": "0",
  "reqModel": "sync",
  "userAction": "new"
}
```

## Response parameters:
Not available yet

## Response example:

```
{
   "success": true,
   "message": "OK",
   "method": null,
   "object": {
       "parentMsgId": "1704724844387651584",
       "msgId": "1704724844387651585",
       "msgContent": "Hello",
       "msgSource": "",
       "msgDeveloperInfo": "",
       "predictQuestion": null,
       "dialogTitle": null,
       "msgType": 1,
       "timestamp": 1695273049,
       "conversationId": "01_1081413754_171834167",
       "isFinal": 1
   },
   "code": "1",
   "request_id": "314e1af0613543bdb0e375ee133b45b2.86.16952730497130059"
}
```

## Status code

| Status code | Instruction |
| --- | --- |
| 200 | OK |
| 201 | Created |
| 401 | Unauthorized |
| 403 | Forbidden |
| 404 | Not Found |
