Skip to main content

Megacall (Batch Operations)

Run multiple analysis types in a single API call for efficiency.

Why Use Megacall?

A single request is faster than multiple requests for each kind of analysis. It is also more cost effective, as you are charged for fewer API calls than the individual features in the megacall.

Selecting Which Checks to Run

Each analysis type is optional. Only request what you need to minimize latency and cost.

Pass an options object with boolean flags to select analyses:

ParameterAnalysis
includeSpam: trueSpam detection
includeRelevance: trueOn-topic and banned topics check
includeCommentScore: trueFull quality analysis
includeDogwhistle: trueCoded language detection
includePerspectiveAnalyzeComment: truePerspective-compatible analyzeComment scoring
includeLlmDetection: trueAI-generated text detection

Results are null for any analysis not requested.

Basic Usage

const result = await client.megacall({
comment: "This is a test comment",
articleId: articleId,
includeSpam: true,
includeRelevance: true,
includeCommentScore: true,
includeDogwhistle: true,
});

// Access results (null if not requested)
if (result.spam_check) {
console.log(`Is spam: ${result.spam_check.is_spam}`);
}

if (result.relevance_check) {
console.log(`On topic: ${result.relevance_check.on_topic.on_topic}`);
}

if (result.comment_score) {
console.log(`Overall score: ${result.comment_score.overall_score}`);
}

if (result.dogwhistle_check) {
console.log(`Dogwhistles detected: ${result.dogwhistle_check.detection.dogwhistles_detected}`);
}

With Additional Parameters

const result = await client.megacall({
comment: "Comment text here",
articleId: articleId,
includeSpam: true,
includeRelevance: true,
includeDogwhistle: true,
bannedTopics: ["politics", "religion"],
sensitiveTopics: ["controversial topic"],
dogwhistleExamples: ["known coded phrase"],
});

Handling Stale Article Contexts

Article context IDs are tied to the API key that created them. If you rotate your key, previously stored IDs no longer resolve, and megacall raises ArticleContextNotFoundError (or ArticleContextNotFoundException in PHP). Regenerate the context, store the new ID, and retry the call.

import { RespectifyClient, ArticleContextNotFoundError } from "@respectify/client";

async function evaluateWithRetry(comment: string, articleUrl: string, articleId: string) {
try {
return await client.megacall({ comment, articleId, includeCommentScore: true });
} catch (err) {
if (!(err instanceof ArticleContextNotFoundError)) throw err;
const fresh = await client.initTopicFromUrl(articleUrl);
// Store fresh.article_id so later requests reuse it.
return await client.megacall({
comment,
articleId: fresh.article_id,
includeCommentScore: true,
});
}
}
tip

Avoid retry loops — initTopic is a paid call. Retry once, store the new ID, and let later requests reuse it.