- ›Keyword research loops fail in production when every tenant shares one API key and there is no audit trail of what the agent queried
- ›AgentSEO (/seo) wraps Keywords Data, Backlinks, and SEO Labs so agents call searchVolume, serpCompetitors, and labs keyword-overview through one governed interface
- ›Scope every loop with naive.forUser(clientId) so Client A's research never bills or logs against Client B
- ›A typical loop is seed keyword → volume check → SERP competitors → Labs overview → store results in your app DB or deliver by email
- ›
When you sell tiers, pair the loop with Customer Billing so seo calls meter per tenant and return 429 rate_limited at quota— see the usage-metered SEO SaaS guide - ›Company → Employee → Primitive: your platform defines policy, each customer's research agent acts on their behalf, /seo is the data primitive
An SEO agent that only drafts blog titles from memory misses the part buyers pay for: fresh keyword volume, live SERP competitors, and difficulty signals tied to each customer account. Naïve gives multi-tenant products the AgentSEO primitive (/seo) so a research loop runs on governed data instead of a shared scraper key in a prompt.
This guide shows a keyword research loop you can run per tenant: seed topic in, structured opportunity out — scoped with naive.forUser(clientId), compatible with usage-metered plans, and wired into the broader autonomous company model (Company → Employee → Primitive).
Loop architecture
| Step | AgentSEO call | Output |
|---|---|---|
| 1. Seed | Your app passes { seedKeyword, locale } | Loop input |
| 2. Volume | searchVolume([seed, ...variants]) | Monthly volume estimates |
| 3. SERP | serpCompetitors([seed]) | Domains ranking today |
| 4. Labs | labs("google", "keyword-overview", { keywords: [seed] }) | Difficulty, related terms |
| 5. Deliver | Store in DB, email brief, or hand to writer agent | Customer-facing artifact |
Each step uses the same tenant scope. If you also run AEO brand tracking, add a parallel branch with /aeo after step 4.
Setup
npm install @usenaive-sdk/serverimport { Naive } from "@usenaive-sdk/server";
const naive = new Naive({ apiKey: process.env.NAIVE_API_KEY! });Provision the customer once:
const client = await naive.users.create({
external_id: "acme_corp_uuid",
email: "seo@acme.example",
label: "Acme Corp",
});Use naive.forUser(client.id) for every SEO call in the loop.
The loop
async function runKeywordResearchLoop(tenantId: string, seed: string) {
const seo = naive.forUser(tenantId).seo;
const volume = await seo.searchVolume([seed, `${seed} software`, `${seed} platform`]);
const competitors = await seo.serpCompetitors([seed]);
const overview = await seo.labs("google", "keyword-overview", { keywords: [seed] });
return {
seed,
volume,
competitors,
overview,
generatedAt: new Date().toISOString(),
};
}- Signatures match the
seosub-client. - CLI equivalent for debugging:
naive seo keywords google search-volume --keywords "<seed>" --location-code 2840. - Credit costs per endpoint are listed on the SEO getting-started page.
Scheduling and orchestration
Run the loop on a cron, a queue worker, or your orchestration employee:
- Cron — nightly refresh for every active tenant.
- Event-driven — customer adds a new seed keyword in your UI.
- CEO agent — kanban task "Research Q3 content cluster" dispatches the loop per brand.
Log each run in your app and optionally attach Naïve audit logs for compliance.
Multi-tenant and metering
For a SaaS product, the loop is identical for every customer; only tenantId changes. When you sell tiers:
- Enable
/seoper tier via Account Kits. - Cap calls per month via Customer Billing quotas — the 2001st
searchVolumereturns429 rate_limited, not a silent overage.
See How to Build a Usage-Metered AI SEO SaaS for the full billing wiring.
Related reading
- Introducing AgentSEO — primitive overview
- Build a multi-tenant AEO platform — SEO + AEO together
- Track brand mentions in AI search — companion AEO loop
- SEO docs
What is an SEO keyword research loop for agents?+
Which AgentSEO endpoints should a research loop use?+
How do I run the loop for many customers?+
How does this relate to AEO and brand tracking?+
How do I get started?+
Building the autonomous company infrastructure.
Keyword volume, backlinks, SERP competitors, and ranked-keyword data for classic search — plus AEO/GEO visibility into whether ChatGPT, Claude, Gemini, and Perplexity actually mention you. The full visibility stack behind one key.
Build a multi-tenant AI SEO/AEO SaaS with Customer Billing: plans enforce quotas at execution time — 429 on overage, forbidden when a primitive is off-tier.
Track how ChatGPT, Claude, Gemini, and Perplexity mention your brand with AgentAEO — LLM responses, mention search, and AI keyword volume per tenant.
A code-first tutorial for building an agentic AEO/GEO product on Naïve — give every brand an AI agent that audits how ChatGPT, Claude, Gemini, and Perplexity answer questions about them, finds the keyword and citation gaps with SEO data, writes answer-optimized content with an OpenRouter model, and publishes to their own connected CMS. Each customer is an isolated tenant user, governed by an Account Kit and a Customer-Billing plan, with usage metered and quota-enforced at execution time and sensitive actions frozen for human approval.