Nexus Answers

6 min read

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:

  1. Select Nexus in the top menu. You are presented with the list of current Nexus projects.

  2. Access the project you want to configure by selecting it in the list.

  3. Select the AI Answers tab.

  4. In the API section, select the API toggle switch.

  5. 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.

Note

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:

  1. Select Nexus in the top menu. You are presented with the list of current Nexus projects.

  2. Access the project you want to configure by selecting it in the list.

  3. Select the AI Answers tab.

  4. In the API section, select the Access tab.

  5. 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:

  1. Select Nexus in the top menu. You are presented with the list of current Nexus projects.

  2. Access the project you want to configure by selecting it in the list.

  3. Select the AI Answers tab.

  4. In the API section, select the API keys tab.

  5. Select Create API key. If the project has no keys yet, the button is called Create key.

  6. In the Name field, enter a name that tells you what the key is for. For example, "Support portal".

  7. Select Create API key.

  8. Select Copy to copy the key, and store it somewhere safe.

  9. Select Done.

Important

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:

  1. Select Nexus in the top menu. You are presented with the list of current Nexus projects.

  2. Access the project you want to configure by selecting it in the list.

  3. Select the AI Answers tab.

  4. In the API section, select the API keys tab.

  5. Select Revoke next to the key.

  6. 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

Content-Type

application/json

Authorization

Bearer followed by your API key. Only send this header when the API is set to API key required. Leave it out when the API is Public.

The body has these fields. All of them are required, except history:

Field

Value

tenantId

The tenant ID from the Access tab.

projectId

The project ID from the Access tab.

language

The language code of the content to answer from. For example, en.

message

The question, as plain text.

history

Earlier questions and answers in the conversation, oldest first. Each item has a role, either user or assistant, and a content string. Up to 20 items.

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

answer

The first event. answerId identifies this answer.

text

A piece of the answer in content. Join the pieces in the order they arrive, with nothing between them. A piece can end in the middle of a word.

sources

The topics the answer is based on, in sources. Each has a title. If the project has a source URL, each also has a url with the full address of the topic. Without one, there is no url. See Set the source URL for Nexus Answers.

error

Something went wrong while the answer was being written. Treat the answer as failed.

done

The last event. It can carry a reason, described below.

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

no_match

Nothing in the published content answers the question.

refused

The question was declined. Don't show any text that arrived before this event.

not_available

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

401

The API key is missing or not accepted.

403

Forbidden.

404

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.