Set up JWT Auth and Access Lucy API

Lucy supports both Symmetric and Asymmetric JWT authentication mechanisms to allow third-party applications to securely integrate with its system. This document outlines the setup process for both methods, key generation, configuration, and usage of the API for authentication and other APIs

Prerequisites

  • Admin or SuperAdmin access to the Lucy instance
  • Ability to generate and securely store JWT secrets (Symmetric or Asymmetric)
  • Company ID (cid) provided by the Lucy team

Locate Your Lucy Instance ID

  1. Login to the Lucy instance.
  2. Navigate to Settings.
  3. Note the Instance ID from the URL.

JWT Key Configuration

  • Navigate to: Settings → Security → JWT Configuration → Add Secret Key
  • Click Add Secret Key
  • Provide your JWT secret
  • Choose Symmetric or Asymmetric
  • Important: Once the key is added to Lucy or Answer Engine, it will not be visible again. Store it securely.
  • If Auto provisioning is required, the under Manage Security Features section, Auto Provisioning toggle needs to be enabled
  • If users need to be added in Auth0, then the under Manage Security Features section, Provisioning adds users to Auth0toggle needs to be enabled
    • Required if users expect to access Answer Engine webui in future

Symmetric Key Setup (Recommended for Testing)

  1. Navigate to Settings → Security
  2. Click Add Secret Key
  3. Generate a UUID or a 30+ character string as the secret and store it securely
  4. Do NOT enable the Asymmetric toggle
  5. Use this key to generate JWT tokens (e.g., via jwt.io)
  6. JWT Key generation format with example:

    Header:

    {
      "alg": "HS256",
      "typ": "JWT"
    }

    Payload Data:

    {
      "mode": "api",
      "firstname": "first_name",
      "lastname": "last_name",
      "email": "valid email id",
      "iat": 1752074171, ---- time in Unix Timestamp (Seconds): Refer https://www.epochconvert.com/
      "exp": 1752160571, ---- time in Unix Timestamp (Seconds): Refer https://www.epochconvert.com/
      "cid": "Lucy_instance_id"
    }

Sign JWT : Secret :

Provide the generated UUID earlier in the section shown in below screen shot from jwt.io

  1. Delete this key from Lucy after testing is complete

Asymmetric Key Setup (Recommended for Production)

  • Generate Key Pair

# Private Key
openssl genpkey -algorithm RSA -out private_key.pem -pkeyopt rsa_keygen_bits:2048


# Public Key
openssl rsa -pubout -in private_key.pem -out public_key.pem
  • Only the key content (excluding -----BEGIN PUBLIC KEY----- and -----END PUBLIC KEY----) should be added to Lucy.
  • Navigate to Settings → Security
  • Click Add Secret Key
  • Mark as Asymmetric
  • Paste only the content of public_key.pem (excluding headers/footers)

JWT Token Format

  1. Header:

    {
      "alg": "RS256",
      "cid": "Lucy_instance_id"
    }

    Payload Data:

    {
      "mode": "api",
      "firstname": "first_name",
      "lastname": "last_name",
      "email": "valid email id",
      "iat": 1752074171, ---- time in Unix Timestamp (Seconds): Refer https://www.epochconvert.com/
      "exp": 1752160571 ---- time in Unix Timestamp (Seconds): Refer https://www.epochconvert.com/
    }

Sign JWT : Secret :

Use the private key to sign the JWT token.

Authenticate in Lucy using JWT Token

  • Once the JWT token is generated, use the token as Bearer token in the Header for the below Lucy Authentication API

  • Request Payload 

    curl --location --request POST 'https://ask.lucy.ai/api/qna/start' \
    --header 'Authorization: Bearer JWT_Token'
    • Note: the base URL for all the API is https://ask.lucy.ai/api/qna or the customer specific {customized_url}/api/qna 
    • Postman request screenshot of Request and Response of Authentication (/start) API


  • Response

    • If successfully validated then the caller will simply receive the auth token as part of the response. The body itself will be a string object, that is the auth token. 
    • The auth token will be uses in further API calls such answer API, synopsis API etc
    • If the validation fails then the API will throw following errors-

Failure scenario


Error code


Status code


Invalid header

Invalid cid

Invalid exp

Invalid iat

Invalid mode

Token verification failed

invalid_token

400

Invalid email domain

invalid_email_domain

400

No seats available

no_seats_available

400

Other issues with the JWT token

invalid_token

400

Invalid email address

invalid_email_address

400

Other server errors

 

500 

Accessing Answers Endpoint (Request & response)

Request Payload

curl --location --request GET 'https://ask.lucy.ai/api/qna/answers?q={question/query}&source=lucy&selected_answers_limit=12&researchType=QnA&saveHistory=true&lucy-version=4&companyId={lucy_company_id}&synopsis=false' \
--header 'x-auth-token: {auth_token_returned_fron_start_API}'
  • Please make sure to use the auth_token retrieved from /start API endpoint as header in the API request

Response

  • Answers API will return set of answers along with other properties in JSON Format

  • Here is response screen shot. Capture the value of qnaToken


Accessing Synopsis Endpoint (Request & response)

Request Payload

curl --location --request GET 'https://ask.lucy.ai/api/qna/synopsis?q={question/query}&source=lucy&selected_answers_limit=12&researchType=QnA&saveHistory=true&lucy-version=4&companyId={lucy_company_id}&synopsis=false&qnaToken={token_from_answers_api}' \
--header 'x-auth-token: {auth_token_returned_fron_start_API}'
  • Please make sure to pass retrieved qnaToken from answers API endpoint as query param in Synopsis API
  • Please make sure to use the auth_token retrieved from /start API endpoint as header in the API request

Response

  • Synopsis API endpoint will return the same answers for the question/query along with a property called shortAnswer which contains the Synopsis

  • Here is the sample response

Accessing Explore more questions Endpoint (Request & response)

Request Payload

curl --location --request POST 'https://ask.lucy.ai/api/qna/get-question-suggestions-to-explore' \
--header 'x-auth-token: {auth_token_returned_fron_start_API}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "content": "{shortAnswer_from_synopsis_api}",
    "numberOfQuestions": 3
}'
  • Please make sure to use the auth_token retrieved from /start API endpoint as header in the API request
  • payload should have below key value as raw data (JSON format)
    • content: shortAnswer_from_synopsis_api : STRING
    • numberOfQuestions : can be any number (ideally 10) : INETEGER

Response

  • Explore more questions Endpoint will return number of questions based on the request payload as JSON array of strings

  • Here is a sample response

 




Was this article helpful?