Skip to content

REST API

Use the REST API to query a Denser chatbot from your own product, internal tools or automations. Everything you need is on the chatbot’s API channel: turn the API on, get a key, and run a real request before you write any code.

The API channel of a chatbot: Enable API and the API key on the left, and the Try it panel on the right with the request body, Run request, and the curl to list a user's conversations

  1. Open the chatbot you want to query. On its Playground, select the API tab in the row of channels at the top.

  2. Make sure Enable API is on. While it is off, every request to this chatbot’s API is refused.

  1. In the API Keys tab, click Generate API key. If the chatbot already has a key, you see its first and last characters and a Regenerate key button.

  2. Copy the key and store it somewhere safe, such as your server’s environment variables. It is shown only once: afterwards only its first and last characters are.

A key you generate here is also filled into the request on the right, so you can try it straight away.

The Try it panel holds a ready-made request for this chatbot: its chatbot ID, your key, a question, an example userId and the chatbot’s model.

  1. Edit any field you like, such as the question. If the key shows as zeros, paste your saved key into key.

  2. Click Run request. The response shows the chatbot’s answer, the passages it drew on, and the conversationId and messageId of this exchange.

  3. To ask a follow-up, click Continue conversation, edit the question, and run it again. The chatbot answers with the earlier turns as context.

Test requests are recorded under the user test-user, so you can find them in Chat logs apart from real users. Reset restores the request. On a narrow screen, where the Try it panel is not shown beside the key, open it with Set up API.

Click Copy curl to copy the request as a curl command, ready to run from a terminal or translate to your language:

Terminal window
curl -X POST "https://denser.ai/api/query" \
-H "Content-Type: application/json" \
-d '{
"question": "What can you help me with?",
"chatbotId": "<chatbot-id>",
"key": "<api-key>",
"userId": "<your-user-id>"
}'

Send your own ID for the person asking as userId, and the conversationId from a response to continue that conversation. To read a user’s conversations back, copy the request under List a user’s conversations.

To show the answer word by word as it is written, the way the chat widget does, add "stream": true to the request. The answer then arrives as Server-Sent Events: a delta event for each piece of text, then a done event with the same body as the JSON response.

In the Try it panel, set stream to true and click Run request to watch the answer arrive. Copy curl then adds -N, which stops curl from holding the output back:

Terminal window
curl -N -X POST "https://denser.ai/api/query" \
-H "Content-Type: application/json" \
-d '{
"question": "What can you help me with?",
"chatbotId": "<chatbot-id>",
"key": "<api-key>",
"userId": "<your-user-id>",
"stream": true
}'

See Streaming the answer for every event, and examples in JavaScript and Python.