Module 06

API Integration for Detection

Detection APIs transform manual analysis into automated pipelines. This module covers connecting to detection services, handling responses, and building production-grade integration workflows.

Detection API Landscape

Major detection services expose REST APIs that accept text input and return structured analysis results. Understanding their common patterns — authentication, rate limiting, response formats — lets you switch between providers or run them in parallel.

REST APIs

Most detection services use standard REST with JSON payloads. Send text via POST, receive scores and metadata in the response body. API keys authenticate each request.

Webhook Callbacks

For large batches, use async processing with webhooks. Submit content, receive a job ID, and get results pushed to your endpoint when analysis completes.

Building a Detection Pipeline

A production pipeline needs more than API calls. You need input validation, rate limit handling, retry logic, result caching, and error reporting. Here is a reference architecture:

// Reference: Detection API pipeline async function detectContent(text, options = {}) { // 1. Validate input if (text.length < 50) return { skip: true, reason: 'too_short' }; // 2. Check cache const hash = sha256(text); const cached = await cache.get(hash); if (cached && !options.force) return cached; // 3. Call detection API with retry const result = await retry( () => detectionAPI.analyze({ text, model: 'latest' }), { maxRetries: 3, backoff: 'exponential' } ); // 4. Normalize and cache result const normalized = normalizeScores(result); await cache.set(hash, normalized, { ttl: 86400 }); return normalized; }

Handling Rate Limits

Every detection API enforces rate limits. Exceeding them results in 429 responses and potentially suspended access. Implement token bucket or leaky bucket rate limiting on your side to stay within provider quotas.

Provider PatternTypical LimitStrategy
Per-second cap10-50 req/secToken bucket with queue
Daily quota1,000-50,000 req/dayCounter with graceful degradation
Concurrent limit5-20 parallelSemaphore-based concurrency control

Security Note

Never embed API keys directly in client-side code. Use environment variables and server-side proxies. Rotate keys periodically and monitor for unauthorized usage.

The API integration patterns here build on the batch processing concepts from Common Detection Errors — particularly around handling edge cases and interpreting scores correctly. For a comparison of available tools to integrate, see our AI Detection Tools Compared guide.