{"id":428,"date":"2026-11-20T17:35:43","date_gmt":"2026-11-20T17:35:43","guid":{"rendered":"https:\/\/sripuwath.com\/index.php\/2026\/11\/20\/akismet-introducing-the-official-akismet-javascript-sdk\/"},"modified":"2026-11-20T17:35:43","modified_gmt":"2026-11-20T17:35:43","slug":"akismet-introducing-the-official-akismet-javascript-sdk","status":"publish","type":"post","link":"https:\/\/sripuwath.com\/index.php\/2026\/11\/20\/akismet-introducing-the-official-akismet-javascript-sdk\/","title":{"rendered":"Akismet: Introducing the official Akismet JavaScript SDK"},"content":{"rendered":"<div class=\"wp-block-jetpack-markdown\">\n<p>Spam doesn\u2019t care what your site runs on. A contact form on a Next.js app or a comment box on a Cloudflare Worker gets the same junk a WordPress blog does. After the <a href=\"https:\/\/akismet.com\/blog\/introducing-the-official-akismet-php-sdk\/\">PHP SDK<\/a> in June, we\u2019re excited to release the official JavaScript SDK for Akismet.<\/p>\n<h2>Who is this for?<\/h2>\n<p><code>@automattic\/akismet<\/code> is a TypeScript client for the Akismet API. It\u2019s for developers adding spam protection to comments, contact forms, or signups in a JavaScript backend.<\/p>\n<ul>\n<li>It covers the whole <a href=\"https:\/\/github.com\/Automattic\/akismet-api\">Akismet API<\/a>.<\/li>\n<li>It runs on Node.js 22 and later, and on Bun, Deno, and Cloudflare Workers.<\/li>\n<li>It comes with typechecked examples for Express, Fastify, Hono, Next.js, and plain <code>node:http<\/code>.<\/li>\n<\/ul>\n<h2>A two-minute quick start<\/h2>\n<pre><code class=\"language-bash\">npm install @automattic\/akismet\n<\/code><\/pre>\n<p>Then check each submission in the route that receives it. In a Next.js app, that\u2019s <code>app\/api\/comments\/route.ts<\/code>:<\/p>\n<pre><code class=\"language-ts\">import {\n  Akismet, AkismetError, ContentType, SpamVerdict,\n} from '@automattic\/akismet';\n\nconst akismet = new Akismet({\n  apiKey: process.env.AKISMET_API_KEY!,\n  site: 'https:\/\/your-site.com',\n  isTest: process.env.AKISMET_TEST_MODE === '1', \/\/ Disable learning\n});\n\nexport async function POST(request: Request) {\n  const { comment, name, email } = await request.json();\n  try {\n    const result = await akismet\n      .forRequest(request, { trustedProxyHops: 1 })\n      .check({\n        body: comment,\n        authorName: name,\n        authorEmail: email,\n        type: ContentType.Comment,\n      });\n    console.log(result.verdict);\n    if (result.verdict === SpamVerdict.Discard) {\n      \/\/ Akismet is sure it's spam. Drop it.\n    } else if (result.isSpam) {\n      \/\/ Hold it for moderation.\n    } else {\n      \/\/ Publish it.\n    }\n  } catch (error) {\n    if (!(error instanceof AkismetError)) throw error;\n    \/\/ Safe to log: the SDK redacts the API key.\n    console.error(error);\n    \/\/ Akismet failed or rejected the input. Hold it for review.\n  }\n  return new Response(null, { status: 202 });\n}\n<\/code><\/pre>\n<\/div>\n<div class=\"wp-block-jetpack-markdown\">\n<p><code>site<\/code> is the front page of your site. Check out the <a href=\"https:\/\/github.com\/Automattic\/akismet-sdk-js\/blob\/trunk\/README.md\">README<\/a> for details on how the the <a href=\"https:\/\/github.com\/Automattic\/akismet-sdk-js\/blob\/trunk\/README.md#client-ip\">Client IP<\/a> is configured.<\/p>\n<\/div>\n<figure class=\"wp-block-jetpack-videopress jetpack-videopress-player\">\n<div class=\"jetpack-videopress-player__wrapper\">\n<div class=\"jetpack-video-wrapper\"><\/div>\n<\/div>\n<\/figure>\n<div class=\"wp-block-jetpack-markdown\">\n<p>Every framework follows the same flow: check the submission, then act on the verdict. You can check out some <a href=\"https:\/\/github.com\/Automattic\/akismet-sdk-js\/tree\/trunk\/examples\">examples<\/a> for Express, Fastify, Hono, <code>node:http<\/code>, and Next.js Server Actions.<\/p>\n<h2>What\u2019s in 1.0<\/h2>\n<ul>\n<li><strong>Spammers can\u2019t fake their IP.<\/strong> Trust only the headers from proxies you allow.<\/li>\n<li><strong>Your API key stays out of your logs.<\/strong> Log every error worry free.<\/li>\n<li><strong>You can tell Akismet when it gets one wrong.<\/strong> Keep the content you checked and its verdict, when a moderator finds missed spam or a false positive, report it. Akismet learns from those reports, check out the <a href=\"https:\/\/github.com\/Automattic\/akismet-sdk-js\/blob\/trunk\/README.md#feedback\">README<\/a> for how.<\/li>\n<\/ul>\n<h2>Get started<\/h2>\n<p>The Akismet SDK is open source under the MIT license.<\/p>\n<ul>\n<li>Find it on <a href=\"https:\/\/www.npmjs.com\/package\/@automattic\/akismet\">npm<\/a>.<\/li>\n<li>Read the code and docs on <a href=\"https:\/\/github.com\/Automattic\/akismet-sdk-js\">GitHub<\/a>.<\/li>\n<li>Building with an AI coding agent? Tell it to read the <code>SKILL.md<\/code> that ships with <code>@automattic\/akismet<\/code>.<\/li>\n<\/ul>\n<p>You\u2019ll need an Akismet API key. The <a href=\"https:\/\/akismet.com\/pricing\/\">Personal plan<\/a> is name-your-price for personal sites and blogs, and commercial sites need a paid plan sized to their traffic. Your code stays the same whichever plan you\u2019re on.<\/p>\n<p>Found a bug, or something that doesn\u2019t fit your stack? <a href=\"https:\/\/github.com\/Automattic\/akismet-sdk-js\/issues\">Open an issue<\/a> on GitHub.<\/p>\n<\/div>\n<p class=\"wp-block-paragraph\">\n<\/p>","protected":false},"excerpt":{"rendered":"<p>Spam doesn\u2019t care what your site runs on. A contact form on a Next.js app or a comment box on a Cloudflare Worker gets the same junk a WordPress blog [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-428","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/sripuwath.com\/index.php\/wp-json\/wp\/v2\/posts\/428","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sripuwath.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sripuwath.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sripuwath.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sripuwath.com\/index.php\/wp-json\/wp\/v2\/comments?post=428"}],"version-history":[{"count":0,"href":"https:\/\/sripuwath.com\/index.php\/wp-json\/wp\/v2\/posts\/428\/revisions"}],"wp:attachment":[{"href":"https:\/\/sripuwath.com\/index.php\/wp-json\/wp\/v2\/media?parent=428"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sripuwath.com\/index.php\/wp-json\/wp\/v2\/categories?post=428"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sripuwath.com\/index.php\/wp-json\/wp\/v2\/tags?post=428"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}