Skip to Content
TyphAI automatizations coming soon! 🎉
Text ProcessingText Classification API

📊 Text Classification API Documentation

📌 Overview

The Text Classification API in TyphAI NLP Suite enables you to categorize text into predefined labels. This API is ideal for tasks like spam detection, topic categorization, and content moderation. The response includes the predicted category, a confidence score, an explanation (reason), and identified keywords.


🛠️ Endpoint

POST https://typhai-nlp-suite.p.rapidapi.com/api/v1/text-classifications

📥 Request Parameters

ParameterTypeRequiredDescription
textstringThe input text to classify.
categoriesarrayA list of possible categories for classification.

📤 Response Example

{ "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "text": "The stock market is crashing today!", "classification": "Finance", "confidence": 0.92, "reason": "The text contains financial terminology related to the stock market.", "keywords": ["stock market", "crashing"] }

🚀 Usage Examples

1️⃣ cURL Request

curl -X POST "https://typhai-nlp-suite.p.rapidapi.com/api/v1/text-classifications" \ -H "Content-Type: application/json" \ -H "X-RapidAPI-Host: typhai-nlp-suite.p.rapidapi.com" \ -H "X-RapidAPI-Key: YOUR_RAPIDAPI_KEY" \ -d '{"text": "The stock market is crashing today!", "categories": ["Finance", "Technology", "Sports", "Politics"]}'

2️⃣ Fetch API (JavaScript)

fetch( "https://typhai-nlp-suite.p.rapidapi.com/api/v1/text-classifications", { method: "POST", headers: { "Content-Type": "application/json", "X-RapidAPI-Host": "typhai-nlp-suite.p.rapidapi.com", "X-RapidAPI-Key": "YOUR_RAPIDAPI_KEY", }, body: JSON.stringify({ text: "The stock market is crashing today!", categories: ["Finance", "Technology", "Sports", "Politics"], }), } ) .then((response) => response.json()) .then((data) => console.log(data)) .catch((error) => console.error(error));

3️⃣ Axios Request (JavaScript)

import axios from "axios"; const options = { method: "POST", url: "https://typhai-nlp-suite.p.rapidapi.com/api/v1/text-classifications", headers: { "Content-Type": "application/json", "X-RapidAPI-Host": "typhai-nlp-suite.p.rapidapi.com", "X-RapidAPI-Key": "YOUR_RAPIDAPI_KEY", }, data: { text: "The stock market is crashing today!", categories: ["Finance", "Technology", "Sports", "Politics"], }, }; axios .request(options) .then((response) => console.log(response.data)) .catch((error) => console.error(error));

🎮 Try It Yourself

const TestTextClassificationAPI = () => { const [apiKey, setApiKey] = useState(""); const [text, setText] = useState(""); const [categories, setCategories] = useState(""); const [response, setResponse] = useState(null); const [loading, setLoading] = useState(false); const handleRequest = async () => { if (!apiKey) { alert("Please enter your RapidAPI Key."); return; } setLoading(true); try { const res = await axios.post( "https://typhai-nlp-suite.p.rapidapi.com/api/v1/text-classifications", { text, categories: categories.split(",") }, { headers: { "Content-Type": "application/json", "X-RapidAPI-Host": "typhai-nlp-suite.p.rapidapi.com", "X-RapidAPI-Key": apiKey, }, } ); setResponse(res.data); } catch (error) { setResponse(error.message); } setLoading(false); }; return ( <div> <h3>Test Text Classification API</h3> <input type="text" placeholder="Enter RapidAPI Key" value={apiKey} onChange={(e) => setApiKey(e.target.value)} /> <input type="text" placeholder="Enter text" value={text} onChange={(e) => setText(e.target.value)} /> <input type="text" placeholder="Categories (comma-separated)" value={categories} onChange={(e) => setCategories(e.target.value)} /> <button onClick={handleRequest} disabled={loading}> {loading ? "Loading..." : "Send Request"} </button> {response && <pre>{JSON.stringify(response, null, 2)}</pre>} </div> ); }; <TestTextClassificationAPI />;

📩 Need Help? Visit our FAQ.

🚀 Start classifying text today with TyphAI NLP Suite on RapidAPI!

Last updated on