imagemoderationapi
Home
Industries
E-commerce Social Media Dating Gaming Healthcare
Use Cases
User Generated Content Profile Verification Marketplace Listings Kids Apps Live Streaming
Detection
NSFW Detection Violence Detection Deepfake Detection Face Detection AI Image Detection
Threats
CSAM Nudity Violence Deepfakes Harassment
SDKs
Python Node.js JavaScript PHP Go
Platforms
WordPress Shopify Discord AWS S3 Firebase
Resources
Pricing Login Compliance Glossary Regions
Try Image Moderation

Node.js SDK

The official Node.js client for the Image Moderation API. Full TypeScript support, Promise-based API, and works seamlessly with Express, Next.js, and NestJS.

View on GitHub
npm install @imagemod/sdk
View on npm

Features

The Node.js SDK provides a modern, TypeScript-first interface to the Image Moderation API with full async/await support.

TypeScript – Complete type definitions for excellent IDE support
Promise-based – Modern async/await API design
ESM & CJS – Works with both module systems
Stream Support – Process large files efficiently with streams
Retry Logic – Built-in retries with exponential backoff
Edge Compatible – Works with Vercel Edge, Cloudflare Workers

Basic Usage

import { ImageModerationClient } from '@imagemod/sdk';

// Initialize the client
const client = new ImageModerationClient({
  apiKey: process.env.IMAGEMOD_API_KEY
});

// Moderate an image by URL
const result = await client.moderate({
  imageUrl: 'https://example.com/image.jpg',
  models: ['nsfw', 'violence', 'text']
});

// Check results
console.log(`NSFW Score: ${result.nsfw.score}`);
console.log(`Is Safe: ${result.isSafe}`);

// Moderate from Buffer
const buffer = fs.readFileSync('image.jpg');
const result2 = await client.moderate({ imageData: buffer });

Express.js Integration

import express from 'express';
import multer from 'multer';
import { ImageModerationClient } from '@imagemod/sdk';

const app = express();
const upload = multer({ storage: multer.memoryStorage() });
const moderator = new ImageModerationClient({ apiKey: process.env.API_KEY });

app.post('/upload', upload.single('image'), async (req, res) => {
  try {
    // Moderate the uploaded image
    const result = await moderator.moderate({
      imageData: req.file.buffer,
      models: ['nsfw', 'violence']
    });

    if (!result.isSafe) {
      return res.status(400).json({
        error: 'Image violates content policy',
        flags: result.flaggedCategories
      });
    }

    // Process the approved image...
    res.json({ success: true, scores: result.scores });
  } catch (error) {
    res.status(500).json({ error: error.message });
  }
});

Next.js API Route

// pages/api/moderate.ts
import type { NextApiRequest, NextApiResponse } from 'next';
import { ImageModerationClient } from '@imagemod/sdk';

const client = new ImageModerationClient({
  apiKey: process.env.IMAGEMOD_API_KEY!
});

export default async function handler(
  req: NextApiRequest,
  res: NextApiResponse
) {
  if (req.method !== 'POST') {
    return res.status(405).json({ error: 'Method not allowed' });
  }

  const { imageUrl } = req.body;

  const result = await client.moderate({
    imageUrl,
    models: ['nsfw', 'violence', 'text']
  });

  res.json({
    isSafe: result.isSafe,
    scores: result.scores,
    detectedText: result.text?.content
  });
}

Batch Processing

// Process multiple images concurrently
const urls = [
  'https://example.com/image1.jpg',
  'https://example.com/image2.jpg',
  'https://example.com/image3.jpg'
];

const results = await Promise.all(
  urls.map(url => client.moderate({ imageUrl: url }))
);

// Or use the batch method for optimized throughput
const batchResults = await client.moderateBatch(
  urls.map(url => ({ imageUrl: url })),
  { concurrency: 5 }
);

Start Building with Node.js

Get your API key and start moderating images in minutes.

Get API Key