Ahrefs API
Access real-time Ahrefs SEO data directly through the Ahrefs API to analyze websites, research keywords, track rankings, and make data-driven SEO decisions.
First-Time Setup
If this is your first time using the Ahrefs API, read references/setup.md for complete setup instructions. You'll need:
- - An Ahrefs account (Enterprise plan for full API access, or Lite+ for limited free test queries)
- An API key from your Ahrefs workspace
After setup, return here for usage guidance.
Core Capabilities
Ahrefs API provides access to:
- 1. Site Explorer - Domain metrics, backlinks, organic traffic, referring domains
- Keywords Explorer - Search volume, keyword difficulty, SERP analysis, related keywords
- Rank Tracker - Position tracking, visibility metrics, competitor rankings (requires pre-configured projects)
- Site Audit - Technical SEO issues, crawl data, site health (requires pre-configured projects)
- SERP Overview - Top 100 SERP results for any keyword
- Batch Analysis - Process up to 100 targets per request
- Brand Radar - Brand performance stats
For detailed capability reference, see references/capabilities.md.
Authentication
All API requests require an API key passed via the Authorization header:
CODEBLOCK0
Store your API key securely. Consider using environment variables:
CODEBLOCK1
Usage Workflow
1. Understand the Request
Identify what SEO data is needed:
- - Domain/URL analysis → Site Explorer endpoints
- Keyword data → Keywords Explorer endpoints
- Position tracking → Rank Tracker endpoints (requires project)
- Technical SEO → Site Audit endpoints (requires project)
- SERP data → SERP Overview endpoints
2. Make API Requests
Use curl or similar tools to call the Ahrefs API. Base URL: INLINECODE2
Example - Get domain overview:
CODEBLOCK2
Example - Keyword metrics:
CODEBLOCK3
3. Process and Present Results
- - Parse JSON responses
- Extract relevant metrics
- Present data in clear, actionable formats
- Highlight key insights and opportunities
- Suggest next steps based on findings
Common Workflows
Keyword Research + Cross-Reference
- 1. User provides keyword list
- Make batch API calls to Keywords Explorer
- Parse and consolidate metrics (volume, difficulty, CPC)
- Present analysis with prioritization recommendations
See references/workflows.md for detailed workflow patterns with example API calls.
Competitive Analysis
- 1. Identify target domain and competitors
- Call Site Explorer for each domain
- Compare metrics (DR, organic traffic, referring domains)
- Analyze top organic keywords
- Identify content gaps
- Provide actionable recommendations
Site Audit Review
Note: Requires pre-configured Site Audit project in Ahrefs web interface.
- 1. Call Site Audit API for project data
- Identify critical issues by severity
- Prioritize fixes by impact
- Provide technical recommendations
API Limits & Best Practices
Rate Limiting
- - 60 requests per minute by default
- API returns HTTP 429 if limit exceeded
- Implement exponential backoff for retries
API Unit Consumption
- - Each request consumes API units from your monthly allowance
- Cost depends on the number of rows returned (minimum 50 units per request)
- Track usage in Account settings → Limits and usage
- Enterprise plans include units; additional units can be purchased
Optimization Tips
- - Batch requests when possible (up to 100 targets)
- Limit result rows using
limit parameter - Select specific columns with
select parameter to reduce costs - Cache results when appropriate
- Use date ranges to limit historical data
Plan-Specific Access
- - Enterprise: Full API access
- Lite/Standard/Advanced: Limited free test queries (check your plan for specifics)
Error Handling
Common HTTP status codes:
- -
200 OK - Success - INLINECODE6 - Invalid parameters
- INLINECODE7 - Invalid or missing API key
- INLINECODE8 - Insufficient permissions or plan limits
- INLINECODE9 - Rate limit exceeded
- INLINECODE10 - Ahrefs server issue
Always check response status and handle errors gracefully.
When API Key is Missing
If the API key is not configured:
- 1. Provide setup instructions from references/setup.md
- Guide through API key generation in Ahrefs Account settings
- Explain how to securely store the key (environment variables recommended)
- Test the connection with a simple API call
Resources
- - API Documentation: https://docs.ahrefs.com/docs/api/reference/introduction
- API Key Management: https://app.ahrefs.com/account/api-keys
- Pricing & Limits: https://ahrefs.com/pricing
- Limits & Usage Tracking: https://app.ahrefs.com/account/limits-and-usage/web
Ahrefs API
通过Ahrefs API直接访问实时Ahrefs SEO数据,用于分析网站、研究关键词、跟踪排名,并做出数据驱动的SEO决策。
首次设置
如果您是首次使用Ahrefs API,请阅读references/setup.md获取完整的设置说明。您需要准备:
- - 一个Ahrefs账户(企业版可获取完整API访问权限,Lite+版可进行有限的免费测试查询)
- 从Ahrefs工作区获取的API密钥
完成设置后,请返回此处查看使用指南。
核心功能
Ahrefs API提供以下数据访问:
- 1. 站点浏览器 - 域名指标、外链、自然流量、引荐域名
- 关键词浏览器 - 搜索量、关键词难度、SERP分析、相关关键词
- 排名追踪器 - 排名追踪、可见性指标、竞争对手排名(需要预先配置项目)
- 站点审计 - 技术SEO问题、爬取数据、站点健康度(需要预先配置项目)
- SERP概览 - 任意关键词的前100个SERP结果
- 批量分析 - 每次请求最多处理100个目标
- 品牌雷达 - 品牌表现统计
详细功能参考,请参见references/capabilities.md。
身份认证
所有API请求都需要通过Authorization标头传递API密钥:
bash
Authorization: Bearer YOURAPIKEY
请安全存储您的API密钥。建议使用环境变量:
bash
export AHREFSAPIKEY=your-api-key-here
使用流程
1. 理解请求
确定需要哪些SEO数据:
- - 域名/URL分析 → 站点浏览器端点
- 关键词数据 → 关键词浏览器端点
- 排名追踪 → 排名追踪器端点(需要项目)
- 技术SEO → 站点审计端点(需要项目)
- SERP数据 → SERP概览端点
2. 发起API请求
使用curl或类似工具调用Ahrefs API。基础URL:https://api.ahrefs.com/v3
示例 - 获取域名概览:
bash
curl -X GET https://api.ahrefs.com/v3/site-explorer/domain-overview?target=example.com \
-H Authorization: Bearer $AHREFSAPIKEY
示例 - 关键词指标:
bash
curl -X GET https://api.ahrefs.com/v3/keywords-explorer/overview?keyword=seo+tools&country=us \
-H Authorization: Bearer $AHREFSAPIKEY
3. 处理并呈现结果
- - 解析JSON响应
- 提取相关指标
- 以清晰、可操作的格式呈现数据
- 突出关键洞察和机会
- 根据发现结果提出后续步骤建议
常见工作流程
关键词研究 + 交叉参考
- 1. 用户提供关键词列表
- 批量调用关键词浏览器API
- 解析并整合指标(搜索量、难度、CPC)
- 呈现分析结果并附上优先级建议
详细工作流程模式及示例API调用,请参见references/workflows.md。
竞争分析
- 1. 确定目标域名和竞争对手
- 对每个域名调用站点浏览器
- 比较指标(域名评级、自然流量、引荐域名)
- 分析主要自然关键词
- 识别内容差距
- 提供可操作的建议
站点审计审查
注意: 需要在Ahrefs网页界面中预先配置站点审计项目。
- 1. 调用站点审计API获取项目数据
- 按严重程度识别关键问题
- 按影响程度确定修复优先级
- 提供技术建议
API限制与最佳实践
速率限制
- - 默认每分钟60次请求
- 超出限制时API返回HTTP 429
- 重试时实现指数退避策略
API单位消耗
- - 每次请求消耗月度配额中的API单位
- 成本取决于返回的行数(每次请求最低50个单位)
- 在账户设置 → 限制与用量中追踪使用情况
- 企业版包含单位配额;可额外购买单位
优化技巧
- - 尽可能批量请求(最多100个目标)
- 使用limit参数限制结果行数
- 使用select参数选择特定列以降低成本
- 适当缓存结果
- 使用日期范围限制历史数据
套餐专属访问权限
- - 企业版:完整API访问权限
- Lite/Standard/Advanced版:有限的免费测试查询(请查看您的套餐了解详情)
错误处理
常见HTTP状态码:
- - 200 OK - 成功
- 400 Bad Request - 参数无效
- 401 Unauthorized - API密钥无效或缺失
- 403 Forbidden - 权限不足或超出套餐限制
- 429 Too Many Requests - 超出速率限制
- 500 Internal Server Error - Ahrefs服务器问题
务必检查响应状态并妥善处理错误。
API密钥缺失时的处理
如果未配置API密钥:
- 1. 提供references/setup.md中的设置说明
- 指导在Ahrefs账户设置中生成API密钥
- 解释如何安全存储密钥(推荐使用环境变量)
- 通过简单的API调用测试连接
资源
- - API文档:https://docs.ahrefs.com/docs/api/reference/introduction
- API密钥管理:https://app.ahrefs.com/account/api-keys
- 定价与限制:https://ahrefs.com/pricing
- 限制与用量追踪:https://app.ahrefs.com/account/limits-and-usage/web