Getting started overview

Integrating with Unplugg involves a few core steps: account creation, obtaining API credentials, and making an authenticated API call. Unplugg offers APIs for content moderation, PII detection, and toxicity analysis, designed for developers to embed AI-powered content safety features into their applications. The process generally follows standard REST API integration patterns, utilizing HTTP requests and JSON payloads for communication. Unplugg provides SDKs for Python and Node.js to streamline development, abstracting direct HTTP request handling.

This guide focuses on the initial setup and a basic request, covering the necessary steps to get the Unplugg API operational in a development environment. For detailed information on specific API endpoints or advanced features, refer to the official Unplugg documentation.

Quick Reference: Unplugg Getting Started

Step What to Do Where
1. Sign Up Create a new Unplugg account. Unplugg homepage or signup page
2. Get API Keys Locate and copy your API key from the dashboard. Unplugg developer dashboard
3. Choose SDK/Method Decide between a language SDK (Python/Node.js) or direct HTTP. Unplugg documentation for SDKs
4. Install SDK (if applicable) Add the Unplugg library to your project. Your project's package manager (e.g., pip, npm)
5. Make First Request Send a simple text string for moderation. Your code editor/IDE
6. Handle Response Parse the JSON response to interpret moderation results. Your code editor/IDE

Create an account and get keys

To access Unplugg's APIs, you must first create an account. This process typically involves providing an email address and setting a password. Upon successful registration, you will gain access to the Unplugg developer dashboard, which serves as the central hub for managing your API keys, monitoring usage, and accessing documentation.

  1. Navigate to the Unplugg website: Go to Unplugg's official homepage.
  2. Sign Up: Look for a 'Sign Up' or 'Get Started' button. Follow the prompts to create your account, which may include email verification.
  3. Access Dashboard: Once logged in, navigate to your developer dashboard. The exact location of API keys varies but is commonly found under sections like 'API Keys', 'Settings', or 'Developer Tools'.
  4. Generate/Copy API Key: Unplugg typically provides a default API key or an option to generate new ones. Copy this key. It is a sensitive credential and should be stored securely and never exposed in client-side code or public repositories.

Unplugg offers a free tier that includes up to 500 API calls per month, which is sufficient for initial testing and development. For higher usage, paid plans start at $49/month for 50,000 API calls.

Your first request

After obtaining your API key, you can make your first request. This example demonstrates using the Unplugg Content Moderation API to analyze a text string for potentially harmful content. We'll show examples using both Python and Node.js SDKs, as well as a direct cURL command for those preferring raw HTTP requests.

Prerequisites

  • An Unplugg API key.
  • (For SDK examples) Python 3.8+ or Node.js 14+.
  • (For SDK examples) The respective Unplugg SDK installed:
    • Python: pip install unplugg-sdk
    • Node.js: npm install unplugg-sdk

Example 1: Python SDK

This Python example sends a text string to the Content Moderation API and prints the response.


import os
from unplugg_sdk import UnpluggClient
from unplugg_sdk.models.shared import ContentModerationRequest

# Replace with your actual API key or set as environment variable
UNPLUGG_API_KEY = os.getenv("UNPLUGG_API_KEY", "YOUR_UNPLUGG_API_KEY")

client = UnpluggClient(api_key=UNPLUGG_API_KEY)

text_to_moderate = "I hate this product, it's terrible!"

request = ContentModerationRequest(text=text_to_moderate)

try:
    response = client.content_moderation.moderate_text(request)
    if response.content_moderation_response is not None:
        print("Moderation Results:")
        print(f"  Overall Sentiment: {response.content_moderation_response.overall_sentiment}")
        print(f"  Category Scores: {response.content_moderation_response.category_scores}")
        print(f"  Flags: {response.content_moderation_response.flags}")
    else:
        print("No moderation response received.")
except Exception as e:
    print(f"An error occurred: {e}")

Example 2: Node.js SDK

This Node.js example performs the same content moderation task using the Unplugg Node.js SDK.


const { UnpluggClient } = require('unplugg-sdk');

// Replace with your actual API key or set as environment variable
const UNPLUGG_API_KEY = process.env.UNPLUGG_API_KEY || 'YOUR_UNPLUGG_API_KEY';

const client = new UnpluggClient({ apiKey: UNPLUGG_API_KEY });

async function moderateContent() {
  const textToModerate = "This is a dangerous idea that could harm people.";

  try {
    const response = await client.contentModeration.moderateText({
      text: textToModerate,
    });

    if (response.contentModerationResponse) {
      console.log('Moderation Results:');
      console.log(`  Overall Sentiment: ${response.contentModerationResponse.overallSentiment}`);
      console.log(`  Category Scores:`, response.contentModerationResponse.categoryScores);
      console.log(`  Flags:`, response.contentModerationResponse.flags);
    } else {
      console.log('No moderation response received.');
    }
  } catch (error) {
    console.error('An error occurred:', error);
  }
}

moderateContent();

Example 3: cURL (Direct HTTP Request)

For those not using an SDK, a direct HTTP POST request can be made to the API endpoint. This cURL example demonstrates sending a JSON payload with the text to moderate.


curl -X POST \
  https://api.unplugg.com/v1/content-moderation \
  -H "Content-Type: application/json" \
  -H "x-api-key: YOUR_UNPLUGG_API_KEY" \
  -d '{ "text": "This content is hateful and should be blocked." }'

Remember to replace YOUR_UNPLUGG_API_KEY with your actual API key in all examples.

Common next steps

After successfully making your first Unplugg API request, consider these common next steps to further integrate and optimize your content moderation workflow:

  • Explore Other Endpoints: Unplugg offers additional APIs such as PII Detection API and Toxicity Detection API. Explore these to broaden your content safety features.
  • Error Handling: Implement robust error handling in your application to gracefully manage API rate limits, invalid requests, or service unavailability. Refer to the Unplugg error handling documentation for specific error codes and recommended responses.
  • Asynchronous Processing: For large volumes of text or non-real-time moderation needs, consider processing content asynchronously to avoid blocking your application's main thread.
  • Webhooks: Investigate if Unplugg offers webhooks for event-driven notifications, which can be efficient for moderation results that don't require an immediate synchronous response. Webhooks are a common pattern for integrating APIs and services, as detailed in Twilio's webhook security guide.
  • Security Best Practices: Ensure your API key is stored securely, ideally using environment variables or a secrets management service, rather than hardcoding it into your application. Adhere to general API security practices, such as encrypting data in transit.
  • Monitoring and Logging: Integrate logging for API requests and responses to monitor usage, troubleshoot issues, and track moderation effectiveness.
  • Performance Optimization: For high-throughput applications, consider strategies like batching requests (if supported by Unplugg) or optimizing network calls to minimize latency.
  • Review Pricing and Usage: Regularly monitor your API usage through the Unplugg dashboard and review the Unplugg pricing page to ensure your plan aligns with your operational needs.

Troubleshooting the first call

Encountering issues during your first API call is common. Here are some troubleshooting steps:

  • Invalid API Key: Double-check that your API key is correct and has not been truncated or altered. Ensure it's passed correctly in the HTTP header (x-api-key) or through the SDK client initialization. An invalid key typically results in a 401 Unauthorized error.
  • Missing Headers: Verify that the Content-Type: application/json header is set for POST requests, especially when using cURL or direct HTTP clients.
  • Incorrect Endpoint: Confirm that the API endpoint URL (e.g., https://api.unplugg.com/v1/content-moderation) is accurate. Refer to the Unplugg API reference for precise endpoint details.
  • Malformed JSON Payload: Ensure your request body is valid JSON. Syntax errors in the JSON payload will often lead to a 400 Bad Request error. Use a JSON linter to validate your payload if unsure.
  • Network Issues: Check your internet connection. If you are behind a corporate firewall or proxy, ensure that outbound connections to api.unplugg.com are permitted.
  • SDK Specific Errors: If using an SDK, ensure it's properly installed and imported. Consult the specific Unplugg SDK documentation for common issues related to installation or usage.
  • Rate Limiting: While less common for a first call, repeated rapid requests can trigger rate limits, resulting in a 429 Too Many Requests error. Wait a few moments before retrying.
  • Consult Documentation: The Unplugg official documentation provides detailed error codes and explanations, which can be invaluable for diagnosing specific problems.
  • Contact Support: If you've exhausted troubleshooting steps, reach out to Unplugg support through their website for assistance.