L1 + L2 Usage Guide
Last updated
Last updated
After purchasing the product, open the usage tab and there will be an `access token`, which is the value of x-product-api-key. If "-" means it has not been initialized yet, press the `Refresh` button to initialize it. The `Refresh` button is also used to reset the `access token`, at which point the old value will expire.
The `access token` is shared by all products you purchase.
This API enables users to pass payload from the API /call that the publisher defined.
Endpoint
Header
Path
Body
Response
Case 1: method is a task that needs to be processed asynchronously. These tasks are considered to take a considerable amount of time to process and cannot respond immediately in this api's response.
Then, this Api will respond with a `taskId` and `status: "Pending"`. We will be able to use this `taskId` to check the result of this request using the Refresh result api. Refer to this example below with a Gif Generator app:
Example Request:
Example response:
Method `text2gif` will create a gif file from the data received in the payload. This job will definitely take a long time to process. If the system waits for it to finish processing and return it to the user, it will create a bottleneck that clogs the system. Therefore, the system will return a `taskId` as the task identifier for this request as `status: "Pending"` to indicate that this task has been recorded and is in process.
Explain further why we save app usage history in 2 ways. There will be 2 api to get app usage results with normal methods (Refresh result, Get use app histories) and 2 api to get app usage results with chat methods (Refresh result, Get use app histories):
With standard methods, the returned results will be updated to the request record previously saved in the database.
With chat methods, the returned results will be saved as a new record in the database. This will help display chat message results easily.
Case 2: Method is a job that can be response immediately (for example: querying data from the database, or updating data into the database,...).
It is simply the opposite of case 1. Then all you want from this api will be in its response.
See the example below with the Role Play Chat Bot app
Example Request:
Example response:
Role Play Chat Bot app allows users to chat with AI bots, each bot will be able to answer one or more areas well that you need answered. The list of bots has been created by the publisher and stored in the database, so when we need to display the list of bots, we just need to query the database and return the list of available bots. This work is quite light and can be answered immediately in the response of this api. That's why it's called immediate response work. Method `listCharacter` is an example of such work.
In short, we will have 2 types of data that we can receive from the response of this api.
Asynchronous: The response will always return `taskId` and `status: "Pending"`. The `Refresh result` api can be used to get the final result
Synchronous (immediate response): The response will return the data defined by the publisher. There is no taskId and no need to use the `Refresh result` api to get the final result.
All Jobs (method + payload) will be defined and recorded by the publisher in the `Request DTO`, `Response DTO` section in the usage tab. They will also define which methods are synchronous and which methods are asynchronous (immediate response).
In cases where an error occurs:
With error validating field `method`, `payload` (invalid, missing): Response returns http error 400 (Bad Request)
Example request:
Example response:
If it does not fall within the above two errors, the request will be forwarded to the AI server for processing. Then, if the input does not satisfy the AI app's validation, the system will still return the error http 400 (Bad Request) with `code` as the error code and `message` as an error returned by the AI app.
For example below with the Gif Generator App, the App has only one method, `text2gif`. Passing the method `gif_gen` is not supported, so AI Server returns the error `"message": "unsupported method gif_gen"` and `"code": "GIF_403"`
Example Request:
Example response:
Regarding the callbackUrl field.
For example, you are developing a Layer 2 app, you have previously purchased a Layer 1 app, and your Layer 2 app needs to use it.
You will still need the Use Product, Refresh result or Refresh result for chat app api to be able to use the layer 1 app.
However, this requires you to proactively retrieve the results (by using the Refresh result or Refresh result for chat app).
To be able to receive results passively, use callbackUrl. Marketplace will proactively call it with the data that is the result of the Layer 1 app.
With the callback api, there are some requirements users need to follow:
Http method: POST
The request header will contain `x-marketplace-token`,please review before proceeding to ensure that the request is coming from Marketplace
If received, please respond with a status of 200
Note:
If it fails or exceeds the timeout (10s), the system will try to call the api callback every 3s up to 3 times.
The payload of the callback api will include the following fields:
This api is used to receive the return results of the asynchronous method received from the response of the `Use product` api. Method has `extra_type` which is not `chat_app`
Endpoint
Header
Path
Response
Continuing the example with Gif Generator above, below is an example result of method `text2gif` for the cases Pending, Completed, Failed
Example Request:
Example response for Pending:
Example response for Success:
Example response for Failed:
This API is used to get the usage history of asynchronous methods (methods that respond immediately will not be included here).
Endpoint
Header
Path
Param
Response
Example Request:
Example Response
Like the refresh result api in section 2, this api is also used to receive the return results of the asynchronous method received from the response of the `Use product` api. But for Method there is `extra_type` which is `chat_app`
Endpoint
Header
Path
Param
Response
Example Request:
Example Response:
This API is used to get the usage history of asynchronous methods (methods that respond immediately will not be included here) with chat applications (eg chat bots).
Endpoint
Header
Path
Param
Response
Example Request:
Example Response:
Endpoint | /api/v1/user/products/{productId}/use |
---|---|
Endpoint | /api/v1/user/products/{productId}/refresh/{taskId} |
---|---|
Endpoint | /api/v1/user/products/{productId}/usage-histories |
---|---|
Endpoint | /api/v1/user/products/{productId}/chat-app/refresh/{taskId} |
---|---|
Endpoint | /api/v1/user/products/{productId}/chat-app/histories |
---|---|
Method
POST
Name
Type
Required
x-product-api-key
String
Y
Name
Type
Description
Required
productId
Integer
Product ID
Y
Name
Type
Description
Required
method
String
Method name
Y
payload
Object
Payload of method
Y
callbackUrl
String
N
Name
Type
Description
Required
code
String
Error code. If code = "0", that mean successful
Y
message
String
Error message. If successful, the message is "success"
Y
data
Object
Y
> taskId
UUID
If the method is asynchronous, this field will be returned
N
> status
String
If the method is asynchronous, this field will be returned and will always be "Pending".
N
> … (any fields)
If the method is an immediate response, the fields will be returned in the format the publisher has defined for this method in the `usage tab`
N
Name
Type
Description
Required
taskId
UUID
Task ID
Y
response
Object
Is the result returned from the corresponding method when using the `Use product` api. The format is defined by the publisher in the response DTO of each method in the `usage tab`
Y
errorCode
Object
Y
> status
String
An error code
Y
> reason
String
Specifically describe the error that occurred
Y
extraType
String
Extra data type. Always is "chat_app"
N
Method
GET
Name
Type
Required
x-product-api-key
String
Y
Name
Type
Description
Required
productId
Integer
Product ID
Y
taskId
UUID
Task ID from the response of api `Use product`
Y
Name
Type
Description
Required
code
String
Error code. If code = "0", that mean successful
Y
message
String
Error message. If successful, the message is "success"
Y
data
Object
Y
> status
String
One of the following values: "Pending", "Completed", "Failed"
Y
> result
Object
Is the result returned from the corresponding method when using the `Use product` api. The format is defined by the publisher in the response DTO of each method in the `usage tab`
N
Method
GET
Name
Type
Required
x-product-api-key
String
Y
Name
Type
Description
Required
productId
Integer
Product ID
Y
Name
Type
Description
Required
page
Integer
Page number to retrieve.If you provide invalid value the default page number will applied
Default Value: 1
N
limit
Integer
Number of records per page
Default Value: 20
Max Value: 100
Note: If provided value is greater than max value, max value will be applied.
N
status
String
Is one of the following values: "Pending", "Completed", "Failed"
N
sortBy
String
Is one of the following values: "id", "createdAt"
N
sortDirection
String
Is one of the following values: "ASC", "DESC"
N
Name
Type
Description
Required
code
String
Error code. If code = "0", that mean successful
Y
message
String
Error message. If successful, the message is "success"
Y
data
Array<Object>
Y
> id
Integer
Unique id of record
Y
> taskId
UUID
Task ID
Y
> result
Object
If status is "Completed", this field will be the data recorded in the `response DTO` of the method the publisher defines in the usage tab. If the status is "Failed", the result will be information about the error
N
>status
String
Is one of the following values: "Pending", "Completed", "Failed"
Y
> dataType
String
Is one of the following values: "META_DATA", "S3_OBJECT", "HYBRID"
N
> createdAt
Date time (ISO)
At point in time which request is created
Y
> input
Object
The input data is the method's payload
Y
meta
Object
Y
> itemCount
Integer
The amount of items on this specific page
Y
> totalItems
Integer
The total amount of items
Y
> itemsPerPage
Integer
The amount of items that were requested per page
Y
> totalPages
Integer
The total amount of pages in this paginator
Y
> currentPage
Integer
The current page this paginator "points" to
Y
Method
GET
Name
Type
Required
x-product-api-key
String
Y
Name
Type
Description
Required
productId
Integer
Product ID
Y
taskId
UUID
Task ID from response of the api `Use product`
Y
Name
Type
Description
Required
from
String
Is one of the following values: "user", "system"
Y
Name
Type
Description
Required
code
String
Error code. If code = "0", that mean successful
Y
message
String
Error message. If successful, the message is "success"
Y
data
Object
Y
> id
Integer
Unique id của bản ghi
Y
> taskId
UUID
Task ID
Y
> sessionId
String
Is the session ID of the app that manages chat by session
N
> from
String
Is one of the following values: "user", "system"
Y
> data
Object
If from is "user", this field is the data in the payload in the `Use product` api, otherwise if from is "system", this field is the data in the response according to the format the publisher defines in the `usage tab`
Y
> dataType
String
Is one of the following values: "META_DATA", "S3_OBJECT", "HYBRID"
N
> createdAt
Date time (ISO)
Time which request is created
Y
Method
GET
Name
Type
Required
x-product-api-key
String
Y
Name
Type
Description
Required
productId
Integer
Product ID
Y
Name
Type
Description
Required
page
Integer
Page number to retrieve.If you provide invalid value the default page number will applied
Default Value: 1
N
limit
Integer
Number of records per page
Default Value: 20
Max Value: 100
Note: If provided value is greater than max value, max value will be applied.
N
sessionId
String
Filter by sessionId
N
sortBy
String
Is one of the following values: "id", "createdAt"
N
sortDirection
String
Is one of the following values: "ASC", "DESC"
N
Name
Type
Description
Required
code
String
Error code. If code = "0", that mean successful
Y
message
String
Error message. If successful, the message is "success"
Y
data
Array<Object>
Y
> id
Integer
Unique id của bản ghi
Y
> taskId
UUID
Task ID
Y
> sessionId
String
Is the session ID of the app that manages chat by session
N
> from
String
Is one of the following values: "user", "system"
Y
> data
Object
If from is "user", this field is the data in the payload in the `Use product` api, otherwise if from is "system", this field is the data in the response according to the format the publisher defines in the `usage tab`
Y
> dataType
String
Is one of the following values: "META_DATA", "S3_OBJECT", "HYBRID"
N
> createdAt
Date time (ISO)
Time which request is created
Y
meta
Object
Y
> itemCount
Integer
The amount of items on this specific page
Y
> totalItems
Integer
The total amount of items
Y
> itemsPerPage
Integer
The amount of items that were requested per page
Y
> totalPages
Integer
The total amount of pages in this paginator
Y
> currentPage
Integer
The current page this paginator "points" to
Y