- Paligo Documentation
- Nexus
- Nexus Answers
- Set up API access for Nexus Answers
Nexus Answers
Set up API access for Nexus Answers
The Nexus Answers API lets your own applications send questions about a Nexus project's content and get answers back. For example, you can use it to build a Slackbot or add answers to your own support site.
You manage the API in the API section of the AI Answers tab. The section has two tabs. On Access you turn the API on and choose who can connect. On API keys you create and revoke keys.
Turn the API on or off
To turn the API on or off:
Select Nexus in the top menu. You are presented with the list of current Nexus projects.
Access the project you want to configure by selecting it in the list.
Select the AI Answers tab.
In the API section, select the API toggle switch.
If the project has API keys, a confirmation dialog opens. Select Turn on or Turn off.
When you turn the API on, API key required is selected by default.
Your API keys stay in the list while the API is off, so you can still revoke them. None of them are accepted until you turn the API back on.
Choose who can connect
You can only change this while the API is on. To choose who can connect:
Select Nexus in the top menu. You are presented with the list of current Nexus projects.
Access the project you want to configure by selecting it in the list.
Select the AI Answers tab.
In the API section, select the Access tab.
Choose who can connect:
Public: no API key is needed. Any application that knows the API address can connect.
API key required: only applications that send one of this project's API keys can connect.
Your choice is saved as soon as you select it.
Find the API address and IDs
Your developers need three values to send requests. They are all on the Access tab, and each has a Copy button:
API address: where your applications send their questions for this project.
Tenant ID: the same for all your projects.
Project ID: unique to this project.
Every request needs both IDs. To learn how to send a request, see Nexus Answers API reference.
Create an API key
To create an API key:
Select Nexus in the top menu. You are presented with the list of current Nexus projects.
Access the project you want to configure by selecting it in the list.
Select the AI Answers tab.
In the API section, select the API keys tab.
Select Create API key. If the project has no keys yet, the button is called Create key.
In the Name field, enter a name that tells you what the key is for. For example, "Support portal".
Select Create API key.
Select Copy to copy the key, and store it somewhere safe.
Select Done.
The key is only shown once. If you lose it, revoke it and create a new one.
The list shows each key's name and a short part of the key, so you can tell your keys apart.
Revoke an API key
Revoking a key stops applications that use it from getting answers straight away. Your other keys keep working. You can't undo this.
To revoke a key:
Select Nexus in the top menu. You are presented with the list of current Nexus projects.
Access the project you want to configure by selecting it in the list.
Select the AI Answers tab.
In the API section, select the API keys tab.
Select Revoke next to the key.
In the confirmation dialog, select Revoke API key.
Nexus Answers API reference
This page describes how to send a question to the Nexus Answers API and how to read the answer that comes back.
Before you start, turn the API on and copy the API address, tenant ID and project ID from the Access tab. If the API requires a key, you also need one of the project's API keys. See Set up API access for Nexus Answers.
Send a question
Send a POST request to the project's API address, with a JSON body. Use these headers:
Header | Value |
|---|---|
| |
|
|
The body has these fields. All of them are required, except history:
Field | Value |
|---|---|
| The tenant ID from the Access tab. |
| The project ID from the Access tab. |
| The language code of the content to answer from. For example, |
| The question, as plain text. |
| Earlier questions and answers in the conversation, oldest first. Each item has a |
The API doesn't store conversations. To ask a follow-up question, send the earlier questions and answers in history.
For example:
curl -N -X POST "<API address>" \-H "Content-Type: application/json" \-H "Authorization: Bearer <API key>" \-d '{"tenantId": "<tenant ID>","projectId": "<project ID>","language": "en","message": "Can I publish it to more than one channel?","history": [{"role": "user", "content": "How do I publish a topic?"},{"role": "assistant", "content": "To publish a topic, add it to a publication and select Publish."}]}'
Read the answer
The answer comes back as a stream of server-sent events, so your application can show the text while it is still being written. Each event is a line that starts with data:, followed by a JSON object. Its type field says what kind of event it is:
Type | What it contains |
|---|---|
| The first event. |
| A piece of the answer in |
| The topics the answer is based on, in |
| Something went wrong while the answer was being written. Treat the answer as failed. |
| The last event. It can carry a |
When the answer is complete, the done event has no reason. When it has one, the reason tells you why the answer ended:
Reason | Meaning |
|---|---|
| Nothing in the published content answers the question. |
| The question was declined. Don't show any text that arrived before this event. |
| Answers can't be given right now. Try again later. |
For example:
data: {"type": "answer", "answerId": "<answer ID>"}data: {"type": "text", "content": "To publish a topic, add it to "}data: {"type": "text", "content": "a publication and select Publish."}data: {"type": "sources", "sources": [{"url": "https://docs.example.com/en/publish/publish-a-publication", "title": "Publish a publication"}]}data: {"type": "done"}
An answer usually takes 5 to 20 seconds to finish streaming.
Errors
Errors are returned as an HTTP status code before any events are sent:
Status | Meaning |
|---|---|
| The API key is missing or not accepted. |
| Forbidden. |
| The API is turned off for this project, or nothing has been published from it yet. |
Select Nexus in the top menu. You are presented with the list of current Nexus projects.
Access the project you want to configure by selecting it in the list.
Select Nexus in the top menu. You are presented with the list of current Nexus projects.
Access the project you want to configure by selecting it in the list.
Select Nexus in the top menu. You are presented with the list of current Nexus projects.
Access the project you want to configure by selecting it in the list.
Select Nexus in the top menu. You are presented with the list of current Nexus projects.
Access the project you want to configure by selecting it in the list.
