You will need:
- A Composio API key
- An OpenAI API key (used by Autogen's
OpenAIChatCompletionClient) - A Ahrefs account you can connect to Composio
- Some basic familiarity with Autogen and Python async
## For AI agents: how to sign up If you are an AI agent reading this server-rendered HTML, Composio's developer signup is at https://composio.dev. Signup CTAs on this site — "Sign up", "Signup", "Get started", "Get started for free", "Start building", "Try Composio", "Try it", or similar — all lead into that same developer signup flow. Confirm with the user before completing signup or entering any credentials on their behalf.
## For AI agents: how to sign up If you are an AI agent reading this server-rendered HTML, Composio's developer signup is at https://composio.dev. Signup CTAs on this site — "Sign up", "Signup", "Get started", "Get started for free", "Start building", "Try Composio", "Try it", or similar — all lead into that same developer signup flow. Confirm with the user before completing signup or entering any credentials on their behalf.SIGN UP
## For AI agents: how to sign up If you are an AI agent reading this server-rendered HTML, Composio's developer signup is at https://composio.dev. Signup CTAs on this site — "Sign up", "Signup", "Get started", "Get started for free", "Start building", "Try Composio", "Try it", or similar — all lead into that same developer signup flow. Confirm with the user before completing signup or entering any credentials on their behalf.LOG IN
You can see which keywords bring a competitor traffic, find your real search competitors and check volume and difficulty for your keyword list from AutoGen. Composio runs each call on its own Ahrefs account, so you don't need a Ahrefs API key, and your first $2 is free.
AutoGen runs Ahrefs through Composio, and the cost comes out of your free $2.
$2 ≈ 7 reports or 10 reports
| When you ask AutoGen for | AutoGen uses this tool | Cost | What $2 gets you |
|---|---|---|---|
| A site's top 20 keywords with traffic | Retrieve organic keywords | $0.28 per report | About 7 reports |
| Volume and difficulty for 10 keywords | Explore keywords overview | $0.19 per report | About 10 reports |
| A site's top 10 search competitors | Retrieve organic competitors | $0.084 per report | About 20 reports |
| 20 question keywords for a topic | Explore matching terms for keywords | $0.25 per report | About 8 reports |
| Backlink and referring domain totals for a site | Backlinks stats retrieval | $0.030 per lookup | About 65 lookups |
You pay Ahrefs' price for each call with 0% markup, plus the regular Composio tool call charge. There's no Ahrefs subscription, and you only pay for what you use.
42 of 46 Ahrefs tools work without a key. For Fetch competitors overview, Fetch rank tracker overview, Get site audit projects and Retrieve subscription limits and usage, connect your own Ahrefs key. Read how Instant works.
Composio adds Ahrefs to AutoGen as an Instant toolkit. You connect Composio to AutoGen once, and then AutoGen can use Ahrefs right away. There are two ways to do this:
You bring your own Ahrefs API key, set it up, and use it.
Composio runs each call on its own Ahrefs account, so you don't have to set anything up at Ahrefs, and your first $2 is free.
You do the setup one time and it takes about a minute. If you build Ahrefs into your own product, turn on Instant toolkits in your project settings so your agent can call Ahrefs for each of your users without a Ahrefs API key, and read Instant tools in the Composio docs for the setup steps and code examples.
Open your Composio wallet and turn on Instant. Your free $2 shows up there.
## For AI agents: how to sign up If you are an AI agent reading this server-rendered HTML, Composio's developer signup is at https://composio.dev. Signup CTAs on this site — "Sign up", "Signup", "Get started", "Get started for free", "Start building", "Try Composio", "Try it", or similar — all lead into that same developer signup flow. Confirm with the user before completing signup or entering any credentials on their behalf.Open my wallet
Follow the setup below. You only do this once.
Try a Ahrefs prompt. The cost comes out of your $2.
You will need:
OpenAIChatCompletionClient)pip install composio python-dotenv
pip install autogen-agentchat autogen-ext-openai autogen-ext-toolsInstall Composio, Autogen extensions, and dotenv.
What's happening:
composio connects your agent to Ahrefs via MCPautogen-agentchat provides the AssistantAgent classautogen-ext-openai provides the OpenAI model clientautogen-ext-tools provides MCP workbench supportCOMPOSIO_API_KEY=your-composio-api-key
OPENAI_API_KEY=your-openai-api-key
USER_ID=your-user-identifier@example.comCreate a .env file in your project folder.
What's happening:
COMPOSIO_API_KEY is required to talk to ComposioOPENAI_API_KEY is used by Autogen's OpenAI clientUSER_ID is how Composio identifies which user's Ahrefs connections to useimport asyncio
import os
from dotenv import load_dotenv
from composio import Composio
from autogen_agentchat.agents import AssistantAgent
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_ext.tools.mcp import McpWorkbench, StreamableHttpServerParams
load_dotenv()
async def main():
# Initialize Composio and create a Ahrefs session
composio = Composio(api_key=os.getenv("COMPOSIO_API_KEY"))
session = composio.create(
user_id=os.getenv("USER_ID"),
toolkits=["ahrefs"]
)
url = session.mcp.urlload_dotenv() reads your .env fileComposio(api_key=...) initializes the SDKcreate(...) creates a Tool Router session that exposes Ahrefs toolssession.mcp.url is the MCP endpoint that Autogen will connect to# Configure MCP server parameters for Streamable HTTP
server_params = StreamableHttpServerParams(
url=url,
timeout=30.0,
sse_read_timeout=300.0,
terminate_on_close=True,
headers={"x-api-key": os.getenv("COMPOSIO_API_KEY")}
)Autogen expects parameters describing how to talk to the MCP server. That is what StreamableHttpServerParams is for.
What's happening:
url points to the Tool Router MCP endpoint from Composiotimeout is the HTTP timeout for requestssse_read_timeout controls how long to wait when streaming responsesterminate_on_close=True cleans up the MCP server process when the workbench is closed# Create model client
model_client = OpenAIChatCompletionClient(
model="gpt-5",
api_key=os.getenv("OPENAI_API_KEY")
)
# Use McpWorkbench as context manager
async with McpWorkbench(server_params) as workbench:
# Create Ahrefs assistant agent with MCP tools
agent = AssistantAgent(
name="ahrefs_assistant",
description="An AI assistant that helps with Ahrefs operations.",
model_client=model_client,
workbench=workbench,
model_client_stream=True,
max_tool_iterations=10
)What's happening:
OpenAIChatCompletionClient wraps the OpenAI model for AutogenMcpWorkbench connects the agent to the MCP toolsAssistantAgent is configured with the Ahrefs tools from the workbenchprint("Chat started! Type 'exit' or 'quit' to end the conversation.\n")
print("Ask any Ahrefs related question or task to the agent.\n")
# Conversation loop
while True:
user_input = input("You: ").strip()
if user_input.lower() in ["exit", "quit", "bye"]:
print("\nGoodbye!")
break
if not user_input:
continue
print("\nAgent is thinking...\n")
# Run the agent with streaming
try:
response_text = ""
async for message in agent.run_stream(task=user_input):
if hasattr(message, "content") and message.content:
response_text = message.content
# Print the final response
if response_text:
print(f"Agent: {response_text}\n")
else:
print("Agent: I encountered an issue processing your request.\n")
except Exception as e:
print(f"Agent: Sorry, I encountered an error: {str(e)}\n")You:agent.run_stream(...) yields streaming messages as the agent thinks and calls toolsexit, quit, or bye ends the loopHere's the complete code to get you started with Ahrefs and AutoGen:
import asyncio
import os
from dotenv import load_dotenv
from composio import Composio
from autogen_agentchat.agents import AssistantAgent
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_ext.tools.mcp import McpWorkbench, StreamableHttpServerParams
load_dotenv()
async def main():
# Initialize Composio and create a Ahrefs session
composio = Composio(api_key=os.getenv("COMPOSIO_API_KEY"))
session = composio.create(
user_id=os.getenv("USER_ID"),
toolkits=["ahrefs"]
)
url = session.mcp.url
# Configure MCP server parameters for Streamable HTTP
server_params = StreamableHttpServerParams(
url=url,
timeout=30.0,
sse_read_timeout=300.0,
terminate_on_close=True,
headers={"x-api-key": os.getenv("COMPOSIO_API_KEY")}
)
# Create model client
model_client = OpenAIChatCompletionClient(
model="gpt-5",
api_key=os.getenv("OPENAI_API_KEY")
)
# Use McpWorkbench as context manager
async with McpWorkbench(server_params) as workbench:
# Create Ahrefs assistant agent with MCP tools
agent = AssistantAgent(
name="ahrefs_assistant",
description="An AI assistant that helps with Ahrefs operations.",
model_client=model_client,
workbench=workbench,
model_client_stream=True,
max_tool_iterations=10
)
print("Chat started! Type 'exit' or 'quit' to end the conversation.\n")
print("Ask any Ahrefs related question or task to the agent.\n")
# Conversation loop
while True:
user_input = input("You: ").strip()
if user_input.lower() in ['exit', 'quit', 'bye']:
print("\nGoodbye!")
break
if not user_input:
continue
print("\nAgent is thinking...\n")
# Run the agent with streaming
try:
response_text = ""
async for message in agent.run_stream(task=user_input):
if hasattr(message, 'content') and message.content:
response_text = message.content
# Print the final response
if response_text:
print(f"Agent: {response_text}\n")
else:
print("Agent: I encountered an issue processing your request.\n")
except Exception as e:
print(f"Agent: Sorry, I encountered an error: {str(e)}\n")
if __name__ == "__main__":
asyncio.run(main())Start a new chat and try this prompt:
Using Ahrefs, show me the top 20 keywords [competitor domain] gets the most US organic traffic from. Give me a table with the keyword, monthly volume, their position, estimated traffic and the ranking URL.
AutoGen runs it on Instant and shows you the result. It doesn't ask you for a Ahrefs key, and the cost comes out of your $2. You can see each call in your wallet.
If you want Fetch competitors overview, Fetch rank tracker overview, Get site audit projects and Retrieve subscription limits and usage, you need your own key. Ask AutoGen to connect your Ahrefs account, and it gives you a Composio link:
Connect my Ahrefs account using Composio.
Open the link, paste your Ahrefs API key and click Connect Account. You can get a key from Ahrefs API keys page. After that, Composio uses your key first and doesn't charge Instant for those calls.
Each prompt runs on Instant, and the cost next to it is about what it takes from your $2.
Lists the 20 keywords that send a site the most search traffic, with volume, position and the page that ranks.
Using Ahrefs, show me the top 20 keywords [competitor domain] gets the most US organic traffic from. Give me a table with the keyword, monthly volume, their position, estimated traffic and the ranking URL.
Finds the sites that compete with you for the same keywords in search, with how much you overlap.
Using Ahrefs, find the top 10 organic search competitors for [your domain] in the US. Show each competitor's domain, Domain Rating, the number of keywords we both rank for and their estimated organic traffic.
Gets search volume, difficulty, CPC and traffic potential for your keywords so you can pick which ones to target.
Using Ahrefs, get US search volume, keyword difficulty, CPC and traffic potential for these keywords, then sort them so the best mix of high volume and low difficulty is at the top: [paste up to 10 keywords].
Lists the question keywords people search around a topic, with volume and difficulty, so you can plan articles or FAQs.
Using Ahrefs, find the 20 highest-volume question keywords in the US that contain "[topic]". Show the volume and keyword difficulty for each one and group them into article ideas.
Finds sites that link to pages on your domain that no longer work, so you can fix or redirect them.
Using Ahrefs, find 20 broken backlinks pointing to [your domain], sorted by the linking site's Domain Rating. Show the linking page, the broken URL on my site, the anchor text and the HTTP status.
Checks the Domain Rating of a list of sites in one go so you can drop weak link prospects early.
Using Ahrefs, get the Domain Rating for each of these sites and sort them from highest to lowest so I can see which ones are worth pitching: [paste up to 100 domains].
See where a keyword has the most monthly search volume.
I want to compare demand for [keyword] across countries. Using Ahrefs, get the top 5 countries by monthly search volume and show each country and its volume. Tell me which country has the highest demand.
Find external domains linked from a competitor site.
I want you to do this: Using Ahrefs, list up to 10 external domains that [competitor domain] links to. Show the linked domain and a source page when returned, then group the domains by likely purpose based on their names and pages.
| Tool | What it does | Works without a key | Cost on Instant |
|---|---|---|---|
| Backlinks stats retrieval | Retrieves comprehensive backlink statistics for a specified website or URL using Ahrefs' Site Explorer tool. | Yes | $0.006 per 10 API units used |
| Batch Url Analysis | Performs a batch analysis on multiple URLs or domains using Ahrefs' powerful SEO metrics. | Yes | $0.006 per 10 API units used |
| Domain rating for site explorer | Retrieves Ahrefs Domain Rating and Ahrefs Rank for a specified domain or URL on a requested date. | Yes | $0.006 per 10 API units used |
| Domain rating history | Retrieves the historical Domain Rating (DR) data for a specified domain over time. | Yes | $0.006 per 10 API units used |
| Explore keywords overview | Retrieves keyword-level overview metrics from Ahrefs' Keywords Explorer for specified keywords or an existing keyword list in a country. | Yes | $0.006 per 10 API units used |
| Explore keyword volume by country | Retrieves monthly search volume data across countries for a specified keyword using Ahrefs' Keywords Explorer. | Yes | $0.006 per 10 API units used |
| 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. | Yes | $0.006 per 10 API units used |
| 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. | Yes | $0.006 per 10 API units used |
| Fetch all backlinks | Retrieves a comprehensive list of backlinks for a specified website or URL using Ahrefs' Site Explorer tool. | Yes | $0.006 per 10 API units used |
| Fetch broken backlinks data | Retrieves a list of broken backlinks for a specified website using Ahrefs' Site Explorer tool. | Yes | $0.006 per 10 API units used |
| Fetch site explorer referring domains | Retrieves a list of domains that have backlinks pointing to a specified target website. | Yes | $0.006 per 10 API units used |
| Fetch total search volume history | Retrieves historical total search volume for keywords associated with a target domain or URL using Ahrefs Site Explorer. | Yes | $0.006 per 10 API units used |
| Get content helper topics | Retrieve topics covered by top-ranking pages for a keyword. | Yes | $0.006 per 10 API units used |
| Get domain rating free | Retrieve the free Ahrefs Domain Rating for a domain or URL. | Yes | $0 per request |
| Get domain rating top domains | Retrieves domains ordered by Ahrefs Domain Rating. | Yes | $0 per request |
| Get serp overview | Retrieves a SERP overview for one keyword in a specified country, optionally at a historical date. | Yes | $0.006 per 10 API units used |
| Get site explorer AI responses count | Retrieve AI response citation and page counts for a site. | Yes | $0.006 per 10 API units used |
| Get site explorer country metrics | Retrieves country-specific Site Explorer metrics for a target website or URL, including organic traffic and keyword metrics. | Yes | $0.006 per 10 API units used |
| Get site explorer crawled pages | Retrieve crawled pages and crawl metadata for a target URL. | Yes | $0.006 per 10 API units used |
| Get site explorer linked anchors external | Retrieves anchor text data for external links going out from a target website using Ahrefs Site Explorer. | Yes | $0.006 per 10 API units used |
| Tool | What it does | Works without a key | Cost on Instant |
|---|---|---|---|
| Get url rating history | Retrieves the historical URL Rating data for a specified URL over time. | Yes | $0.006 per 10 API units used |
| Linked anchors explorer | Retrieves information about internal linked anchors for a specified website using the Ahrefs API. | Yes | $0.006 per 10 API units used |
| List best by external links | Retrieves pages from a specified website using Ahrefs' Site Explorer best-by-external-links report. | Yes | $0.006 per 10 API units used |
| Pages by traffic overview | Retrieves a list of pages from a specified website, ordered by their estimated organic search traffic. | Yes | $0.006 per 10 API units used |
| Post Domain Rating Free | Retrieve Domain Rating scores for up to 1,000 target URLs. | Yes | $0 per request |
| Retrieve anchor data | Retrieves anchor text data for a specified website or URL using Ahrefs' Site Explorer tool. | Yes | $0.006 per 10 API units used |
| Retrieve best by internal links | Retrieves pages ranked by internal links for a specified website using Ahrefs' Site Explorer. | Yes | $0.006 per 10 API units used |
| Retrieve crawler ip ranges | Retrieves the list of IP address ranges used by Ahrefs' web crawler (AhrefsBot). | Yes | $0 per request |
| Retrieve organic competitors | Retrieves organic search competitors for a target domain or URL, with keyword overlap and performance metrics. | Yes | $0.006 per 10 API units used |
| Retrieve organic keywords | Retrieves organic keywords data for a specified website using Ahrefs' Site Explorer tool. | Yes | $0.006 per 10 API units used |
| Retrieve outlinks stats | Retrieves outgoing-link statistics for a specified website or URL using Ahrefs Site Explorer. | Yes | $0.006 per 10 API units used |
| Retrieve paid pages data | Retrieves information about paid pages (PPC advertising) for a specified website using Ahrefs' Site Explorer tool. | Yes | $0.006 per 10 API units used |
| Retrieve public crawler ips | Retrieves a list of IP addresses currently used by AhrefsBot, Ahrefs' web crawler. | Yes | $0 per request |
| Retrieve related terms | Retrieves related keyword ideas for a given keyword or keyword list in a specified country. | Yes | $0.006 per 10 API units used |
| Retrieve site explorer keywords history | Retrieves historical keyword performance data for a specified website or domain using Ahrefs' Site Explorer. | Yes | $0.006 per 10 API units used |
| 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. | Yes | $0.006 per 10 API units used |
| 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. | Yes | $0.006 per 10 API units used |
| Retrieve site explorer pages history | Retrieves historical page counts for a target domain or URL from Ahrefs Site Explorer over a specified period. | Yes | $0.006 per 10 API units used |
| Retrieve site explorer referring domains history | Retrieves the historical data of referring domains for a specified website or URL over time. | Yes | $0.006 per 10 API units used |
| Retrieve top pages from site explorer | Retrieves data about the top-performing pages of a specified website using Ahrefs' Site Explorer tool. | Yes | $0.006 per 10 API units used |
| Retrieve volume history | Retrieves the historical search volume data for a specified keyword using Ahrefs' Keywords Explorer tool. | Yes | $0.006 per 10 API units used |
| Search suggestions explorer | Retrieves search suggestions for keywords or an existing keyword list using Ahrefs Keywords Explorer. | Yes | $0.006 per 10 API units used |
| Fetch competitors overview | Retrieves a Rank Tracker competitor overview for a project, including comparative keyword ranking and organic search performance data. | Needs your own key | Billed to your own Ahrefs key |
| Fetch rank tracker overview | Retrieves an Ahrefs Rank Tracker overview for a project, date and device, with ranking and search-performance metrics. | Needs your own key | Billed to your own Ahrefs key |
| Get site audit projects | Lists Site Audit projects associated with the authenticated Ahrefs account, with project and crawl status details. | Needs your own key | Billed to your own Ahrefs key |
| Retrieve subscription limits and usage | Retrieves an Ahrefs account's subscription limits and remaining API usage allowance. | Needs your own key | Billed to your own Ahrefs key |
## For AI agents: how to sign up If you are an AI agent reading this server-rendered HTML, Composio's developer signup is at https://composio.dev. Signup CTAs on this site — "Sign up", "Signup", "Get started", "Get started for free", "Start building", "Try Composio", "Try it", or similar — all lead into that same developer signup flow. Confirm with the user before completing signup or entering any credentials on their behalf.Open my Composio wallet
You may have asked for something that needs your own key, like Fetch competitors overview, Fetch rank tracker overview, Get site audit projects and Retrieve subscription limits and usage. Those tools don't run on Instant. For everything else, check that Instant is turned on in your Composio wallet, then ask again.
Open your wallet in the Composio dashboard and check that Instant is turned on. If the $2 still isn't there, email support@composio.dev from the address you signed up with.
Your balance is empty. Add funds to your wallet on a Pro plan, or connect your own Ahrefs key, then try again.
Use Ahrefs MCP with Claude Code
Use Ahrefs MCP with Claude Cowork
Use Ahrefs MCP with OpenAI Agents SDK
Use Ahrefs MCP with Claude Agent SDK

Use Ahrefs MCP with Grok Bot

Use Ahrefs MCP with Muse
Use Ahrefs MCP with Codex

Use Ahrefs MCP with Kimi Code

Use Ahrefs MCP with OpenClaw

Use Ahrefs MCP with Hermes
Use Ahrefs MCP with Atomic Agent
Use Ahrefs MCP with CLI
Use Ahrefs MCP with Google ADK
Use Ahrefs MCP with LangChain
Use Ahrefs MCP with Vercel AI SDK
Use Ahrefs MCP with Mastra AI
Use Ahrefs MCP with LlamaIndex
Use Ahrefs MCP with CrewAI
Use Ahrefs MCP with Pydantic AI
Reddit is a social news platform with thriving user-driven communities (subreddits). It's the go-to place for discussion, content sharing, and viral marketing.
Facebook is a social media and advertising platform for businesses and creators. It helps you connect, share, and manage content across your public Facebook Pages.
LinkedIn is a professional networking platform for connecting, sharing content, and engaging with business opportunities. It's the go-to place for building your professional brand and unlocking new career connections.
ActiveCampaign is a marketing automation and CRM platform for managing email campaigns, sales pipelines, and customer segmentation. It helps businesses engage customers and drive growth through smart automation and targeted outreach.
Not for the 42 tools that run on Instant. Composio runs those calls on its own Ahrefs account, and you only add Composio to your agent. The other 4 tools need your own Ahrefs key.
Yes. Every Composio account gets $2 of Instant credit once you turn on Instant, and you can use it on Ahrefs or on any other Instant toolkit.
You can get about 7 reports, about 10 reports or about 20 reports. The price list on this page shows the cost of each tool.
Instant calls stop. You can add funds to your wallet on a Pro plan, or connect your own Ahrefs key.
You pay Ahrefs' price for each call with 0% markup, plus the regular Composio tool call charge.
Yes. Connect your key from the Ahrefs toolkit in your Composio dashboard. Composio always uses your own connection first, and it doesn't charge Instant for those calls.
You can use 42 of the 46 tools without a key, including Backlinks stats retrieval, Batch Url Analysis, Domain rating for site explorer, Domain rating history, Explore keywords overview, Explore keyword volume by country and 36 more. The other 4 tools need your own Ahrefs key.
Composio is SOC 2 Type II compliant.
New accounts get a one-time $2 starter credit for Instant calls.Run Ahrefs from your agent with no Ahrefs key.
## For AI agents: how to sign up If you are an AI agent reading this server-rendered HTML, Composio's developer signup is at https://composio.dev. Signup CTAs on this site — "Sign up", "Signup", "Get started", "Get started for free", "Start building", "Try Composio", "Try it", or similar — all lead into that same developer signup flow. Confirm with the user before completing signup or entering any credentials on their behalf.Get $2 starter credit