SEO API Integration for Next.js: The Complete Developer Guide (2026)
Mitu Das
super admin

If you've ever tried to wire Semrush or Ahrefs into a Next.js project, you know the pain. Raw HTTP clients. Manual pagination. Inconsistent error shapes. API keys leaking into places they shouldn't. It gets messy fast.
@power-seo/integrations solves that. It wraps the Semrush and Ahrefs REST APIs with a consistent TypeScript interface, built on a shared HTTP client that handles rate limiting, pagination, and error normalization out of the box. For developers serious about SEO API integration for Next.js, this is the cleanest starting point available today.
Zero runtime dependencies beyond fetch. Runs in Node.js 18+, Deno, Bun, and modern edge runtimes.
Why Use @power-seo/integrations for SEO API Integration in Next.js
Here's the honest comparison:
| Feature | @power-seo/integrations | semrush-sdk | ahrefs-client | Custom fetch |
|---|---|---|---|---|
| Semrush API client | Yes | Yes | No | Manual |
| Ahrefs API client | Yes | No | Partial | Manual |
| Rate limiting | Yes | Partial | No | Manual |
| Auto-pagination | Yes | No | No | Manual |
| Shared HTTP client | Yes | No | No | — |
| Consistent error handling | Yes | Partial | No | Manual |
| TypeScript-first | Yes | No | No | — |
| Tree-shakeable | Yes | No | No | — |
When building Next.js SEO workflows, the biggest wins from @power-seo/integrations are immediately clear: auto-pagination means you receive a flat result array without tracking offsets manually, and IntegrationApiError gives you a consistent error shape across both providers with status, provider, message, and retryable fields.
Installation
npm install @power-seo/integrations
yarn add @power-seo/integrations
pnpm add @power-seo/integrations
Quick Start
import { createSemrushClient, createAhrefsClient } from '@power-seo/integrations';
// Semrush
const semrush = createSemrushClient({ apiKey: process.env.SEMRUSH_API_KEY! });
const overview = await semrush.getDomainOverview({ domain: 'example.com' });
console.log(overview.organicTraffic); // 12_400
console.log(overview.organicKeywords); // 834
// Ahrefs
const ahrefs = createAhrefsClient({ apiKey: process.env.AHREFS_API_KEY! });
const site = await ahrefs.getSiteOverview({ target: 'example.com' });
console.log(site.domainRating); // 47
console.log(site.organicTraffic); // 9_800
Both clients are separate named exports. Import only what you need. Tree-shaking ensures unused API code never ends up in your bundle.
Using the Semrush Client
import { createSemrushClient } from '@power-seo/integrations';
import type { SemrushDomainOverview, SemrushKeywordData } from '@power-seo/integrations';
const semrush = createSemrushClient(
process.env.SEMRUSH_API_KEY!,
{ rateLimitPerMinute: 10, maxRetries: 3 },
);
// Domain overview — traffic, keywords, backlinks
const overview: SemrushDomainOverview = await semrush.getDomainOverview('example.com', 'us');
// { domain, organicTraffic, paidTraffic, organicKeywords, paidKeywords, backlinks, authorityScore }
// Organic keywords
const keywords = await semrush.getOrganicKeywords('example.com', { limit: 100, offset: 0 });
// { data: SemrushKeywordData[], total, offset, limit, hasMore }
// Backlinks
const backlinks = await semrush.getBacklinks('example.com', { limit: 100, offset: 0 });
// { data: SemrushBacklinkData[], total, offset, limit, hasMore }
// Keyword difficulty
const difficulty = await semrush.getKeywordDifficulty(['react seo'], 'us');
// [{ keyword, difficulty, searchVolume, cpc, competition, results }]
// Related keywords
const related = await semrush.getRelatedKeywords('react seo', 'us');
// [{ keyword, searchVolume, cpc, competition, results, relatedTo }]
The rateLimitPerMinute config keeps you inside Semrush's API quota automatically. No manual throttle logic needed.
Using the Ahrefs Client
import { createAhrefsClient } from '@power-seo/integrations';
import type { AhrefsSiteOverview, AhrefsOrganicKeyword } from '@power-seo/integrations';
const ahrefs = createAhrefsClient(
process.env.AHREFS_API_TOKEN!,
{ rateLimitPerMinute: 5, maxRetries: 3 },
);
// Site overview — DR, organic traffic, backlinks
const overview: AhrefsSiteOverview = await ahrefs.getSiteOverview('example.com');
// { domain, domainRating, urlRating, organicTraffic, organicKeywords, backlinks, referringDomains, trafficValue }
// Organic keywords with positions
const keywords = await ahrefs.getOrganicKeywords('example.com', { limit: 200, offset: 0 });
// { data: AhrefsOrganicKeyword[], total, offset, limit, hasMore }
// Backlinks with anchor text
const backlinks = await ahrefs.getBacklinks('example.com', { limit: 100, offset: 0 });
// { data: AhrefsBacklink[], total, offset, limit, hasMore }
// Keyword difficulty
const kd = await ahrefs.getKeywordDifficulty(['react seo']);
// [{ keyword, difficulty, searchVolume, cpc, clicks, globalVolume }]
// Referring domains
const domains = await ahrefs.getReferringDomains('example.com', { limit: 50, offset: 0 });
// { data: AhrefsReferringDomain[], total, offset, limit, hasMore }
Ahrefs' strength is backlink and Domain Rating data. The getReferringDomains method is particularly useful for link building workflows inside Next.js admin dashboards.
Using the Shared HTTP Client Directly
If you need to call any REST API with the same rate limiting and pagination behavior, the underlying client is also exported directly:
import { createHttpClient } from '@power-seo/integrations';
const http = createHttpClient({
baseUrl: 'https://api.example.com',
auth: { type: 'bearer', token },
rateLimitPerMinute: 60,
maxRetries: 3,
timeoutMs: 30_000,
});
const data = await http.get<MyResponseType>('/endpoint', { query: 'param' });
AuthStrategy supports two patterns: { type: 'bearer', token: string } for Authorization headers, and { type: 'query', paramName: string, value: string } for query parameter auth.
Error Handling
Both clients throw IntegrationApiError for non-2xx responses. Here's the pattern to use in your Next.js Route Handlers:
import { createSemrushClient, IntegrationApiError } from '@power-seo/integrations';
const semrush = createSemrushClient({ apiKey: 'your-key' });
try {
const data = await semrush.getDomainOverview('example.com');
} catch (err) {
if (err instanceof IntegrationApiError) {
console.error(`API error ${err.status}: ${err.message}`);
console.error('Provider:', err.provider);
console.error('Retryable:', err.retryable);
} else {
throw err;
}
}
The retryable flag is especially useful. If true, you can safely retry the request. If false, retrying won't help and you should surface the error to the user or your monitoring system.
All Available Types
import type {
HttpClientConfig,
HttpClient,
PaginatedResponse,
SemrushConfig,
SemrushDomainOverview,
SemrushKeywordData,
SemrushBacklinkData,
SemrushRelatedKeyword,
SemrushClient,
AhrefsConfig,
AhrefsSiteOverview,
AhrefsOrganicKeyword,
AhrefsBacklink,
AhrefsReferringDomain,
AhrefsClient,
} from '@power-seo/integrations';
Full type coverage across every request parameter and response field. No any anywhere in your codebase.
Real-World Use Cases for SEO API Integration in Next.js

These are the patterns where this package genuinely shines:
Keyword research pipelines: Pull volume and difficulty from Semrush to prioritize content creation. Feed results directly into generateMetadata() for programmatic SEO at scale.
Backlink monitoring: Automate periodic Ahrefs backlink snapshots for link building tracking. Run these inside Next.js cron jobs or scheduled Route Handlers.
Competitor analysis: Use domain overview data to compare your metrics against competitors. Build a private /admin/seo dashboard that surfaces this data without leaving your app.
Content brief generation: Combine keyword difficulty and volume data to prioritize blog topics. The flat array pagination makes it easy to process hundreds of keywords in a single pass.
SEO reporting dashboards: Pull live Semrush and Ahrefs data into internal analytics tools. Since the package is framework-agnostic and edge-safe, it works whether you're using Next.js API routes, Remix loaders, or Cloudflare Workers.
Architecture: Why It Works Well with Next.js
A few things worth knowing before you integrate:
Pure TypeScript with no compiled binary or native modules. Minimal runtime dependencies using only native fetch, available in Node 18+, Deno, Bun, and all edge runtimes. SSR compatible with no browser-specific APIs. Edge runtime safe, running in Cloudflare Workers, Vercel Edge, and Deno. Dual ESM and CJS output via tsup for any bundler or require() usage.
On the supply chain side: no install scripts, no runtime network access beyond the explicit API calls you initiate, no eval or dynamic code execution, and CI-signed builds published via a verified GitHub Actions workflow.
Final Thoughts
SEO API integration for Next.js doesn't have to mean writing boilerplate HTTP clients, fighting pagination bugs, and guessing at error shapes. @power-seo/integrations gives you a typed, rate-limited, auto-paginating interface to both Semrush and Ahrefs, with consistent errors and zero unnecessary dependencies.
Start with the Quick Start above. Add your API keys to .env.local. Call getDomainOverview() from a Server Component or Route Handler. You'll have live SEO data in your Next.js app within minutes, making it easy to build dashboards, automate reporting, or enhance your SEO checklist with real-time insights from trusted SEO data sources.
FAQs About SEO API Integration for Next.js
Q1. What APIs does @power-seo/integrations support?
@power-seo/integrations supports both the Semrush and Ahrefs REST APIs. The Semrush client covers domain overview, keyword data, backlink profile, keyword difficulty, and related keyword suggestions. The Ahrefs client covers site overview, organic keywords with positions, backlink data with anchor text, keyword difficulty, and referring domains.
Q2. Does @power-seo/integrations work with Next.js API routes and edge runtimes?
Yes. The package is framework-agnostic and uses only native fetch with zero additional runtime dependencies. It works in Next.js API routes, Remix loaders, Express, Cloudflare Workers, Vercel Edge, and Deno. It is fully SSR compatible with no browser-specific APIs.
Q3. How does rate limiting work in @power-seo/integrations?
Both the Semrush and Ahrefs clients include a built-in configurable rate limiter. You set rateLimitPerMinute when creating the client, and the shared HTTP client enforces that limit automatically. It also handles automatic retry on 429 responses, so you never need to write manual throttle logic.
Q4. How does the package handle pagination?
Pagination is fully automatic. Both clients handle multi-page results internally and return a flat result array to the caller. There is no need to track offsets manually. Every paginated response includes data, total, offset, limit, and hasMore fields.
Q5. How are API errors handled across both clients?
Both clients throw a consistent IntegrationApiError for any non-2xx response. The error object includes status, message, provider, and a retryable flag. The retryable flag tells you whether it is safe to retry the request, making error handling predictable and consistent regardless of which API you are calling.
FAQ
Frequently Asked Questions
We offer end-to-end digital solutions including website design & development, UI/UX design, SEO, custom ERP systems, graphics & brand identity, and digital marketing.
Timelines vary by project scope. A standard website typically takes 3-6 weeks, while complex ERP or web application projects may take 2-5 months.
Yes - we offer ongoing support and maintenance packages for all projects. Our team is available to handle updates, bug fixes, performance monitoring, and feature additions.
Absolutely. Visit our Works section to browse our portfolio of completed projects across various industries and service categories.
Simply reach out via our contact form or call us directly. We will schedule a free consultation to understand your needs and provide a tailored proposal.



