Skip to main content

Comprehend-it API

The Comprehend-it API provides a zero-shot text classification service using a natural language inference (NLI) model. It processes input text and classifies it into specified labels, returning a probability score for each label.


Endpoint

POST https://comprehend-it.p.rapidapi.com/predictions/ml-zero-nli-model


Headers

NameTypeDescription
X-RapidAPI-KeyStringYour RapidAPI key.
X-RapidAPI-HostStringcomprehend-it.p.rapidapi.com
Content-TypeStringapplication/json

Request Body

{
"labels": ["label1", "label2", "label3"],
"text": "Your input text here.",
"threshold": 0.5
}
  • labels (required): List of categories for classification.
  • text (required): The text to classify.
  • threshold (optional): Minimum score threshold for label inclusion.

Response

{
"outputs": {
"label1": 0.85,
"label2": 0.10,
"label3": 0.05
}
}

Each label is associated with a probability score indicating the model's confidence.


Error Codes

Status CodeDescription
200OK – Request successful.
400Bad Request – Invalid or incomplete input.
401Unauthorized – Invalid API key.
404Not Found – Invalid endpoint or payload.
413Payload Too Large – Exceeds 30 KB limit.
500Internal Server Error – Server-side issue.

Example Usage

import requests

url = "https://comprehend-it.p.rapidapi.com/predictions/ml-zero-nli-model"
headers = {
"Content-Type": "application/json",
"X-RapidAPI-Key": "YOUR_API_KEY",
"X-RapidAPI-Host": "comprehend-it.p.rapidapi.com"
}
payload = {
"labels": ["positive", "negative", "neutral"],
"text": "I love this product!",
"threshold": 0.5
}

response = requests.post(url, json=payload, headers=headers)
print(response.json())

Additional Information

  • Input Size Limit: The maximum payload size is 30 KB.
  • Label Flexibility: You can specify any set of labels relevant to your classification task.
  • Use Cases: Sentiment analysis, topic classification, intent detection, etc.

For more details, refer to the Comprehend-it API Documentation.