Skip to content

Get information about detectors

The API provides a self-documentation resource to programmatically discover available detectors and their features. It has this path:

detectors

Therefore, the complete URL is:

https://nlapi.expert.ai/v2/detectors

It must be requested with the GET method.
It returns the list of available detectors along with the supported languages and, possibly, the Web address of a specific OpenAPI contract.

In the reference section of this manual you will find all the information you need to use this resource, specifically:

Note

Even if you consume the API through a ready-to-use client that hides low-level requests and responses, knowing the output format helps you understand and navigate the results.

Here is an example of obtaining detectors information:

This example code uses expertai-nlapi, the open-source Python client corresponding to the nlapi-python GitHub project.

The client gets user credentials from two environment variables:

EAI_USERNAME
EAI_PASSWORD

Set those variables with your account credentials before running the sample program below.

The program prints the list of detectors with the language they support.

from expertai.nlapi.cloud.client import ExpertAiClient
client = ExpertAiClient()

output = client.detectors()

# Detectors

print("Available detectors:\n")

for detector in output.detectors:
    print(detector.name)
    print("\tLanguages:")
    for language in detector.languages:
        print("\t\t{}".format(language.code))
    print("\tContract: {}".format(detector.contract))

This example code uses @expertai/nlapi, the open-source NodeJS client corresponding to the nlapi-nodejs GitHub project.

The client gets user credentials from two environment variables:

EAI_USERNAME
EAI_PASSWORD

Set those variables with your account credentials before running the sample program below.

The program prints the list of detectors with the language they support.

import {NLClient} from "@expertai/nlapi";

var nlClient = new NLClient();

nlClient.detectors().then((result) => {
    console.log("Available detectors:");

    for (const detector of result.detectors) {
        console.log(detector.name)
        console.log("\tLanguages:")
        for (const language of detector.languages) {
            console.log("\t\t" + language.code);
        }
    }
})

This example code uses nlapi-java-sdk, the open-source Java client corresponding to the nlapi-java GitHub project.

The client gets user credentials from two environment variables:

EAI_USERNAME
EAI_PASSWORD

Set those variables with your account credentials before running the sample program below.

The program prints the JSON response.

import ai.expert.nlapi.security.Authentication;
import ai.expert.nlapi.security.Authenticator;
import ai.expert.nlapi.security.BasicAuthenticator;
import ai.expert.nlapi.security.DefaultCredentialsProvider;
import ai.expert.nlapi.v2.API;
import ai.expert.nlapi.v2.message.TaxonomiesResponse;
import ai.expert.nlapi.v2.InfoAPI;
import ai.expert.nlapi.v2.InfoAPIConfig;

public class Main {

    public static Authentication createAuthentication() throws Exception {
        DefaultCredentialsProvider credentialsProvider = new DefaultCredentialsProvider();
        Authenticator authenticator = new BasicAuthenticator(credentialsProvider);
        return new Authentication(authenticator);
    }

    public static void main(String[] args) {
        try {
            InfoAPI infoAPI = new InfoAPI(InfoAPIConfig.builder()
               .withAuthentication(createAuthentication())
               .withVersion(API.Versions.V2)
               .build());

            TaxonomiesResponse taxonomies = infoAPI.getTaxonomies();
            taxonomies.prettyPrint();
        }
        catch(Exception ex) {
            ex.printStackTrace();
        }
    }
}

The following curl command gets the taxonomies documentation resource of the API's REST interface.
Run the command from a shell after replacing token with the actual authorization token.

curl -X GET https://nlapi.expert.ai/v2/taxonomies \
    -H 'Authorization: Bearer token'

The server returns a JSON object.

The following curl command gets the detectors documentation resource of the API's REST interface.
Open a command prompt in the folder where you installed curl and run the command after replacing token with the actual authorization token.

curl -X GET https://nlapi.expert.ai/v2/detectors -H "Authorization: Bearer token"

The server returns a JSON object.