Ahrefs CLI for AI Agents

Use Composio Universal CLI with Ahrefs. Get domain rating trend for competitor site, list all broken backlinks for your website, and more using natural language, with authentication handled for you.

Ahrefs logoAhrefs
Api KeyOauth2

Ahrefs is an SEO and marketing platform for site audits, keyword research, and competitor insights. It helps you improve search rankings and drive organic traffic.

46 Tools

Introduction

CLIs are eating MCPs. The industry is converging on the very same idea. MCPs for all their merit can be token hungry, slow, and unreliable for complex tool chaining. However, coding agents have become incredibly good at working with CLIs, and in fact they are far more comfortable working with CLI tools than MCP.

With Composio's Universal CLI, your coding agents can talk to over 1500+ SaaS applications. With Ahrefs, agents can analyze backlinks and referring domains, research keywords and search volume, track domain rating, find organic competitors, and check top pages, and more — all without worrying about authentication.

This guide walks you through Composio Universal CLI and explains how you can connect it with coding agents like Claude Code, Codex, OpenCode, etc, for end-to-end Ahrefs automation.

Also integrate Ahrefs with

What is Universal CLI and why use it?

The idea behind building the universal CLI is to give agents a single command interface to interact with all your external applications. Here's what you'll get with it:

  • Agent-friendly: Coding agents like Claude Code, Codex, and OpenCode can use CLI tools natively — no MCP setup required.
  • Authentication handled: Connect once via OAuth or API Key, and all CLI commands work with your credentials automatically.
  • Tool discovery: Search, inspect, and execute 20,000+ tools across 1500+ apps from one interface.
  • Trigger support: Use triggers to listen for events across your apps, powered by real-time webhooks or polling under the hood.
  • Type generation: Generate typed schemas for autocomplete and type safety in your projects.

Prerequisites

Install the Composio CLI, authenticate, and initialize your project:

bash
# Install the Composio CLI
curl -fsSL https://composio.dev/install | bash

# Authenticate with Composio
composio login

During login you'll be redirected to sign in page, finish the complete flow and you're all set.

Composio CLI authentication flow

Connecting Ahrefs to Coding Agents via Universal CLI

Once it is installed, it's essentially done. Claude Code, Codex, OpenCode, OpenClaw, or any other agent will be able to access the CLI. A few steps to give agents access to your apps.

  1. Launch your Coding Agent — Claude Code, Codex, OpenCode, anything you prefer.
  2. Prompt it to "Authenticate with Ahrefs"
  3. Complete the authentication and authorization flow and your Ahrefs integration is all set.
  4. Start asking anything you want.

Universal CLI Commands for Ahrefs

You can also manually execute CLI commands to interact with your Ahrefs.

Connect your Ahrefs account

Link your Ahrefs account and verify the connection:

bash
# Connect your Ahrefs account (opens OAuth flow)
composio connected-accounts link ahrefs

# Verify the connection
composio connected-accounts list --toolkits ahrefs

Discover Ahrefs tools

Search and inspect available Ahrefs tools:

bash
# List all available Ahrefs tools
composio tools list --toolkit ahrefs

# Search for Ahrefs tools by action
composio tools search "ahrefs"

# Inspect a tool's input schema
composio tools info AHREFS_BACKLINKS_STATS_RETRIEVAL

Common Ahrefs Actions

Backlinks stats retrieval — Retrieves comprehensive backlink statistics for a specified website or url using ahrefs' site explorer tool

bash
composio tools execute AHREFS_BACKLINKS_STATS_RETRIEVAL \
  --date "<string>" \
  --target "<string>"

Batch Url Analysis — Performs a batch analysis on multiple urls or domains using ahrefs' powerful seo metrics

bash
composio tools execute AHREFS_BATCH_URL_ANALYSIS \
  --select "<array>" \
  --targets "<array>"

Domain rating for site explorer — Retrieves the domain rating (dr) for a specified domain

bash
composio tools execute AHREFS_DOMAIN_RATING_FOR_SITE_EXPLORER \
  --date "<string>" \
  --target "<string>"

Domain rating history — Retrieves the historical domain rating (dr) data for a specified domain over time

bash
composio tools execute AHREFS_DOMAIN_RATING_HISTORY \
  --target "<string>" \
  --date_from "<string>"

Generate Type Definitions

Generate typed schemas for Ahrefs tools to get autocomplete and type safety in your project:

bash
# Auto-detect language
composio generate --toolkits ahrefs

# TypeScript
composio ts generate --toolkits ahrefs

# Python
composio py generate --toolkits ahrefs

Tips & Tricks

  • Always inspect a tool's input schema before executing: composio tools info <TOOL_NAME>
  • Pipe output with jq for better readability: composio tools execute TOOL_NAME -d '{}' | jq
  • Set COMPOSIO_API_KEY as an environment variable for CI/CD pipelines
  • Use composio dev logs tools to inspect execution logs and debug issues

Next Steps

  • Try asking your coding agent to perform various Ahrefs operations
  • Explore cross-app workflows by connecting more toolkits
  • Set up triggers for real-time automation
  • Use composio generate for typed schemas in your projects
TOOLS

Supported Tools

Every Ahrefs action and event your agent gets out of the box.

Backlinks stats retrieval

Retrieves comprehensive backlink statistics for a specified website or URL using Ahrefs' Site Explorer tool.

Batch Url Analysis

Performs a batch analysis on multiple URLs or domains using Ahrefs' powerful SEO metrics.

Domain rating for site explorer

Retrieves Ahrefs Domain Rating and Ahrefs Rank for a specified domain or URL on a requested date.

Domain rating history

Retrieves the historical Domain Rating (DR) data for a specified domain over time.

Explore keywords overview

Retrieves keyword-level overview metrics from Ahrefs' Keywords Explorer for specified keywords or an existing keyword list in a country.

Explore keyword volume by country

Retrieves monthly search volume data across countries for a specified keyword using Ahrefs' Keywords Explorer.

Explore linked domains of a site

Retrieves a list of external domains that the specified target website or URL links to, using Ahrefs' Site Explorer functionality.

Explore matching terms for keywords

The keywords_explorer_matching_terms endpoint retrieves a list of keyword phrases that match or contain the specified keyword from Ahrefs' vast database.

Fetch all backlinks

Retrieves a comprehensive list of backlinks for a specified website or URL using Ahrefs' Site Explorer tool.

Fetch broken backlinks data

Retrieves a list of broken backlinks for a specified website using Ahrefs' Site Explorer tool.

Fetch competitors overview

Retrieves a Rank Tracker competitor overview for a project, including comparative keyword ranking and organic search performance data.

Fetch rank tracker overview

Retrieves an Ahrefs Rank Tracker overview for a project, date and device, with ranking and search-performance metrics.

Fetch site explorer referring domains

Retrieves a list of domains that have backlinks pointing to a specified target website.

Fetch total search volume history

Retrieves historical total search volume for keywords associated with a target domain or URL using Ahrefs Site Explorer.

Get content helper topics

Retrieve topics covered by top-ranking pages for a keyword.

Get domain rating free

Retrieve the free Ahrefs Domain Rating for a domain or URL.

Get domain rating top domains

Retrieves domains ordered by Ahrefs Domain Rating.

Get serp overview

Retrieves a SERP overview for one keyword in a specified country, optionally at a historical date.

Get site audit projects

Lists Site Audit projects associated with the authenticated Ahrefs account, with project and crawl status details.

Get site explorer AI responses count

Retrieve AI response citation and page counts for a site.

Get site explorer country metrics

Retrieves country-specific Site Explorer metrics for a target website or URL, including organic traffic and keyword metrics.

Get site explorer crawled pages

Retrieve crawled pages and crawl metadata for a target URL.

Get site explorer linked anchors external

Retrieves anchor text data for external links going out from a target website using Ahrefs Site Explorer.

Get url rating history

Retrieves the historical URL Rating data for a specified URL over time.

Linked anchors explorer

Retrieves information about internal linked anchors for a specified website using the Ahrefs API.

List best by external links

Retrieves pages from a specified website using Ahrefs' Site Explorer best-by-external-links report.

Pages by traffic overview

Retrieves a list of pages from a specified website, ordered by their estimated organic search traffic.

Post Domain Rating Free

Retrieve Domain Rating scores for up to 1,000 target URLs.

Retrieve anchor data

Retrieves anchor text data for a specified website or URL using Ahrefs' Site Explorer tool.

Retrieve best by internal links

Retrieves pages ranked by internal links for a specified website using Ahrefs' Site Explorer.

Retrieve crawler ip ranges

Retrieves the list of IP address ranges used by Ahrefs' web crawler (AhrefsBot).

Retrieve organic competitors

Retrieves organic search competitors for a target domain or URL, with keyword overlap and performance metrics.

Retrieve organic keywords

Retrieves organic keywords data for a specified website using Ahrefs' Site Explorer tool.

Retrieve outlinks stats

Retrieves outgoing-link statistics for a specified website or URL using Ahrefs Site Explorer.

Retrieve paid pages data

Retrieves information about paid pages (PPC advertising) for a specified website using Ahrefs' Site Explorer tool.

Retrieve public crawler ips

Retrieves a list of IP addresses currently used by AhrefsBot, Ahrefs' web crawler.

Retrieve related terms

Retrieves related keyword ideas for a given keyword or keyword list in a specified country.

Retrieve site explorer keywords history

Retrieves historical keyword performance data for a specified website or domain using Ahrefs' Site Explorer.

Retrieve site explorer metrics

Retrieves Site Explorer SEO metrics for a target domain or URL on a specified date, including backlink, referring-page and crawled-page counts.

Retrieve site explorer metrics history

Retrieves historical Site Explorer traffic metrics for a target website or URL over a specified period, including estimated organic and paid traffic and cost.

Retrieve site explorer pages history

Retrieves historical page counts for a target domain or URL from Ahrefs Site Explorer over a specified period.

Retrieve site explorer referring domains history

Retrieves the historical data of referring domains for a specified website or URL over time.

Retrieve subscription limits and usage

Retrieves an Ahrefs account's subscription limits and remaining API usage allowance.

Retrieve top pages from site explorer

Retrieves data about the top-performing pages of a specified website using Ahrefs' Site Explorer tool.

Retrieve volume history

Retrieves the historical search volume data for a specified keyword using Ahrefs' Keywords Explorer tool.

Search suggestions explorer

Retrieves search suggestions for keywords or an existing keyword list using Ahrefs Keywords Explorer.

FAQ

Frequently asked questions

The Composio Universal CLI is a single command-line interface that lets coding agents and developers interact with 1500+ SaaS applications. It handles authentication, tool discovery, action execution, and trigger setup — all from the terminal, without needing to configure MCP servers.

Any coding agent that can run shell commands works with the Composio CLI — including Claude Code, Codex, OpenCode, OpenClaw, and others. Once the CLI is installed, agents automatically discover and use the composio commands to interact with Ahrefs and other connected apps.

MCP servers require configuration and can be token-heavy for complex workflows. The CLI gives agents a direct, lightweight interface — no server setup needed. Agents simply call composio commands like any other shell tool. It's faster to set up, more reliable for multi-step tool chaining, and works natively with how coding agents already operate.

All sensitive data such as tokens, keys, and configuration is fully encrypted at rest and in transit. Composio is SOC 2 Type 2 compliant and follows strict security practices so your Ahrefs data and credentials are handled as safely as possible. You can also bring your own OAuth credentials for full control.

Start with Ahrefs.It takes 30 seconds.

Managed auth, hosted MCP servers, and every Ahrefs tool your agent needs.Free to start.

Start building