Skip to content
A Ruby client for the Akismet API
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib Test that the blatant spam flag is set Feb 19, 2015
test Test that the blatant spam flag is set Feb 19, 2015
.gitignore .gitignore Feb 9, 2015
.travis.yml Require at least Ruby 1.9.3 Feb 10, 2015
.yardopts Add .yardopts file Feb 8, 2015 Version 2.0.0 Feb 14, 2015
Gemfile Gemfile Feb 9, 2015
LICENSE.txt Rename license file Feb 8, 2015 New README Feb 13, 2015
Rakefile New hash literal syntax Feb 10, 2015
akismet.gemspec Require at least Ruby 1.9.3 Feb 10, 2015


A Ruby client for the Akismet API.

Gem Version Build Status

Getting Started


gem install akismet


This README provides an overview of akismet. Full documentation is available at


Sign up at and retrieve your API key from your account page.



Set your API key and app URL (a URL representing your app):

Akismet.api_key = '<your API key>'
Akismet.app_url = ''

Then check whether a comment is spam ...

# request is a Rack::Request
is_spam = Akismet.spam?(request.ip, request.user_agent, text: 'Poppycock!')

... file a spam report ...

Akismet.spam request.ip, request.user_agent, text: 'I earn $2,000 a week ...'

... or flag a false positive ("ham" is not-spam):

Akismet.ham request.ip, request.user_agent, text: '"Viagra" derives from the Sanskrit ...'


To maximize the accuracy of the filter, submit as many of the documented parameters as possible. Also submit environment variables related to the comment as a hash in the env parameter (Akismet suggests these variables):

vars = %w{
  # ...

params = {
  type: 'comment',
  text: 'A new life awaits you in the Off-World colonies.',
  author: 'Eldon',
  author_email: '',
  author_url: '',
  post_url: '',
  post_modified_at:, 1, 1),
  referrer: request.referrer,
  env: request.env.slice(*vars) # slice courtesy of Active Support

is_spam = Akismet.spam?(request.ip, request.user_agent, params)

Blatant Spam

Akismet flags blatant spam that should be deleted without review. This feature is exposed via Akismet.check:

is_spam, is_blatant = Akismet.check(request.ip, request.user_agent, text: 'Buy everything ... now!')

Reusing Connections

Akismet.spam? and friends create a new TCP connection each time you call them. If you have many comments to check or report, use to reuse a single connection: do |client|
  for comment in comments
    is_spam = client.spam?(comment.ip, comment.user_agent, text: comment.text)


In the example above, the object yielded to the block is an Akismet::Client. Akismet::Client underlies the Akismet class methods. Use it on its own to manually open and close connections or override the global API key:

  client ='api-key-2', '')
  client.spam request.ip, request.user_agent, text: 'Bank error in your favor!'


  1. Set the environment variable AKISMET_API_KEY to your API key
  2. rake


Please submit issues and pull requests to jonahb/akismet on GitHub.

You can’t perform that action at this time.