Keyword Research with dataforseo-cli
LLM-friendly keyword research CLI. Wraps the DataForSEO API and outputs TSV by default — compact, structured, and optimized for agent context windows.
npm: https://www.npmjs.com/package/dataforseo-cli
GitHub: https://github.com/alexgusevski/dataforseo-cli
Setup
1. Install from npm
CODEBLOCK0
2. Check credentials
CODEBLOCK1
If credentials are already configured, you're good to go. If not, authenticate:
CODEBLOCK2
Credentials are stored in ~/.config/dataforseo-cli/config.json. The locations and languages commands work without credentials (local data).
Commands
status — Check credentials
Check if API credentials are configured without making any API calls.
CODEBLOCK3
Exits 0 if configured, exits 1 if not. Shows login username (not password).
volume — Keyword metrics
Get search volume, CPC, keyword difficulty (0–100), competition level, and 12-month search trend.
CODEBLOCK4
Arguments:
- -
<keywords...> — One or more keywords (required). Batch multiple keywords in one call to save API requests.
Options:
- -
-l, --location <code> — Location code (default: 2840 = US) - INLINECODE8 — Language code (default:
en) - INLINECODE10 — Output as JSON array
- INLINECODE11 /
--human — Output as human-readable table
Example:
CODEBLOCK5
Output (TSV):
CODEBLOCK6
- -
difficulty — 0–100 scale (0-30 easy, 31-60 medium, 61-100 hard) - INLINECODE14 — Cost per click in USD
- INLINECODE15 — LOW / MEDIUM / HIGH
- INLINECODE16 — 12 monthly search volumes, newest first
related — Keyword suggestions
Find related keyword ideas from a seed keyword.
CODEBLOCK7
Arguments:
- -
<seed> — Seed keyword (required, single keyword)
Options:
- -
-l, --location <code> — Location code (default: 2840 = US) - INLINECODE21 — Language code (default:
en) - INLINECODE23 — Max results (default:
50) - INLINECODE25 — Output as JSON array
- INLINECODE26 /
--human — Output as human-readable table
Example:
CODEBLOCK8
Output (TSV):
CODEBLOCK9
competitor — Domain keyword analysis
See what keywords a domain currently ranks for.
CODEBLOCK10
Arguments:
- -
<domain> — Target domain (required, e.g. ahrefs.com)
Options:
- -
-l, --location <code> — Location code (default: 2840 = US) - INLINECODE33 — Language code (default:
en) - INLINECODE35 — Max results (default:
50) - INLINECODE37 — Output as JSON array
- INLINECODE38 /
--human — Output as human-readable table
Example:
CODEBLOCK11
Output (TSV):
CODEBLOCK12
locations — Look up location codes
List all available location codes, or filter by name. Works offline — no API credentials needed.
CODEBLOCK13
Arguments:
- -
[search] — Optional filter by name (e.g. sweden, new york)
Without search — lists all locations:
CODEBLOCK14
With search — filters by name:
CODEBLOCK15
Output (TSV):
CODEBLOCK16
languages — Look up language codes
List all available language codes, or filter by name. Works offline — no API credentials needed.
CODEBLOCK17
Without search — lists all languages:
CODEBLOCK18
With search — filters by name:
CODEBLOCK19
Output (TSV):
CODEBLOCK20
Output Formats
All data commands default to TSV (tab-separated values) — the most token-efficient structured format for LLMs.
| Flag | Description |
|---|
| (default) | TSV — fewest tokens, best for agent pipelines |
| INLINECODE45 |
JSON array — use when you need structured parsing |
|
--table /
--human | Human-readable aligned table — for human review |
Caching
Results are cached in ~/.config/dataforseo-cli/cache/ to avoid duplicate API calls and save costs. Same query + location + language = cache hit.
CODEBLOCK21
Workflow: SEO Article Research
- 1. Start with seed keyword: INLINECODE49
- Expand: INLINECODE50
- Filter: Pick keywords with volume > 100, difficulty < 60
- Check competitors: INLINECODE51
- Write article targeting the best keyword cluster
Tips
- - Batch keywords in
volume — DataForSEO charges per API request, not per keyword - Default location is USA (2840). Always set
--location for local/international SEO - Use
locations and languages without arguments to see all available options - Difficulty scale: 0-30 easy, 31-60 medium, 61-100 hard
使用 dataforseo-cli 进行关键词研究
面向LLM友好的关键词研究命令行工具。封装了DataForSEO API,默认输出TSV格式——紧凑、结构化,并针对智能体上下文窗口进行了优化。
npm: https://www.npmjs.com/package/dataforseo-cli
GitHub: https://github.com/alexgusevski/dataforseo-cli
设置
1. 从npm安装
bash
npm install -g dataforseo-cli
2. 检查凭证
bash
dataforseo-cli status
如果凭证已配置,即可直接使用。如果未配置,请进行身份验证:
bash
使用登录名+密码
dataforseo-cli --set-credentials login=YOUR
LOGIN password=YOURPASSWORD
或使用base64令牌(来自DataForSEO邮件)
dataforseo-cli --set-credentials base64=YOUR
BASE64TOKEN
凭证存储在 ~/.config/dataforseo-cli/config.json 中。locations 和 languages 命令无需凭证即可使用(本地数据)。
命令
status — 检查凭证
检查API凭证是否已配置,无需发起任何API调用。
bash
dataforseo-cli status
已配置则退出码为0,未配置则退出码为1。显示登录用户名(不显示密码)。
volume — 关键词指标
获取搜索量、CPC、关键词难度(0–100)、竞争程度和12个月搜索趋势。
bash
dataforseo-cli volume <关键词...> [选项]
参数:
- - <关键词...> — 一个或多个关键词(必填)。可在一次调用中批量处理多个关键词以节省API请求。
选项:
- - -l, --location <代码> — 地区代码(默认:2840 = 美国)
- --language <代码> — 语言代码(默认:en)
- --json — 以JSON数组格式输出
- --table / --human — 以人类可读表格格式输出
示例:
bash
dataforseo-cli volume seo工具 关键词研究 外链检查
输出(TSV):
keyword volume cpc difficulty competition trend
seo工具 12500 2.35 45 HIGH 14800,13900,12500,12100,11800,12000,12500,13000,12800,12500,12200,11900
- - difficulty — 0–100等级(0-30容易,31-60中等,61-100困难)
- cpc — 每次点击费用(美元)
- competition — LOW / MEDIUM / HIGH
- trend — 12个月搜索量,最新在前
related — 关键词建议
从种子关键词查找相关关键词创意。
bash
dataforseo-cli related <种子词> [选项]
参数:
- - <种子词> — 种子关键词(必填,单个关键词)
选项:
- - -l, --location <代码> — 地区代码(默认:2840 = 美国)
- --language <代码> — 语言代码(默认:en)
- -n, --limit — 最大结果数(默认:50)
- --json — 以JSON数组格式输出
- --table / --human — 以人类可读表格格式输出
示例:
bash
dataforseo-cli related AI智能体 -n 20
输出(TSV):
keyword volume cpc competition difficulty
最佳AI智能体 8100 3.10 0.82 52
AI智能体框架 2400 1.85 0.65 38
competitor — 域名关键词分析
查看某个域名当前排名的关键词。
bash
dataforseo-cli competitor <域名> [选项]
参数:
- - <域名> — 目标域名(必填,例如 ahrefs.com)
选项:
- - -l, --location <代码> — 地区代码(默认:2840 = 美国)
- --language <代码> — 语言代码(默认:en)
- -n, --limit — 最大结果数(默认:50)
- --json — 以JSON数组格式输出
- --table / --human — 以人类可读表格格式输出
示例:
bash
dataforseo-cli competitor semrush.com -n 10
输出(TSV):
keyword position volume cpc difficulty url
外链检查 1 33100 4.50 72 https://ahrefs.com/backlink-checker
locations — 查询地区代码
列出所有可用的地区代码,或按名称筛选。离线工作——无需API凭证。
bash
dataforseo-cli locations [搜索词] [--json]
参数:
- - [搜索词] — 按名称筛选(例如 sweden、new york)
无搜索词 — 列出所有地区:
bash
dataforseo-cli locations
带搜索词 — 按名称筛选:
bash
dataforseo-cli locations sweden
输出(TSV):
code name country type
2752 Sweden SE Country
languages — 查询语言代码
列出所有可用的语言代码,或按名称筛选。离线工作——无需API凭证。
bash
dataforseo-cli languages [搜索词] [--json]
无搜索词 — 列出所有语言:
bash
dataforseo-cli languages
带搜索词 — 按名称筛选:
bash
dataforseo-cli languages swedish
输出(TSV):
name code
Swedish sv
输出格式
所有数据命令默认输出TSV(制表符分隔值)——对LLM最节省令牌的结构化格式。
| 标志 | 描述 |
|---|
| (默认) | TSV — 令牌最少,最适合智能体管道 |
| --json |
JSON数组 — 需要结构化解析时使用 |
| --table / --human | 人类可读对齐表格 — 供人工审查 |
缓存
结果缓存在 ~/.config/dataforseo-cli/cache/ 中,以避免重复API调用并节省成本。相同查询+地区+语言=缓存命中。
bash
dataforseo-cli --print-cache
工作流程:SEO文章研究
- 1. 从种子关键词开始: dataforseo-cli volume 你的主题
- 扩展: dataforseo-cli related 你的主题 -n 30
- 筛选: 选择搜索量 > 100、难度 < 60 的关键词
- 检查竞争对手: dataforseo-cli competitor 竞争对手域名.com -n 20
- 撰写文章 针对最佳关键词集群
提示
- - 在 volume 中批量处理关键词——DataForSEO按API请求收费,而非按关键词收费
- 默认地区为美国(2840)。进行本地/国际SEO时务必设置 --location
- 使用不带参数的 locations 和 languages 查看所有可用选项
- 难度等级:0-30容易,31-60中等,61-100困难