grok-search-cli 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +161 -66
- package/README.zh.md +159 -65
- package/dist/cli.js +99 -554
- package/dist/index.js +2 -0
- package/dist/search-DcS355m9.js +573 -0
- package/dist/src/args.d.ts +4 -0
- package/dist/src/cli.d.ts +1 -0
- package/dist/src/config.d.ts +35 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/openrouter.d.ts +38 -0
- package/dist/src/openrouter.test.d.ts +1 -0
- package/dist/src/output.d.ts +19 -0
- package/dist/src/providers.d.ts +12 -0
- package/dist/src/search.d.ts +34 -0
- package/dist/src/skill.d.ts +2 -0
- package/dist/src/types.d.ts +121 -0
- package/package.json +34 -7
package/README.md
CHANGED
|
@@ -1,55 +1,117 @@
|
|
|
1
1
|
# grok-search-cli
|
|
2
2
|
|
|
3
|
-
[
|
|
3
|
+
[简体中文](./README.zh.md)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](https://github.com/timzhong1024/grok-search-cli)
|
|
6
|
+
[](https://www.npmjs.com/package/grok-search-cli)
|
|
7
|
+
[](https://www.npmjs.com/package/grok-search-cli)
|
|
8
|
+
[](./LICENSE)
|
|
9
|
+
[](https://nodejs.org/)
|
|
6
10
|
|
|
7
|
-
## Get Started
|
|
8
11
|
|
|
9
|
-
|
|
12
|
+
Make Grok's access to X and high-value public sources such as GitHub and arXiv available in any agent or shell workflow.
|
|
13
|
+
|
|
14
|
+
This CLI makes that capability directly usable in agent workflows, with fresher information for fast-moving topics and far less operational overhead than building and maintaining a custom search stack.
|
|
15
|
+
|
|
16
|
+
## Quick Start
|
|
17
|
+
|
|
18
|
+
Install the package:
|
|
10
19
|
|
|
11
20
|
```bash
|
|
21
|
+
# Install the CLI globally
|
|
12
22
|
pnpm add -g grok-search-cli
|
|
13
23
|
```
|
|
14
24
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
#
|
|
19
|
-
|
|
25
|
+
Run a health check:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
# Check whether your config is ready
|
|
29
|
+
grok-search doctor
|
|
20
30
|
```
|
|
21
31
|
|
|
22
|
-
|
|
32
|
+
If no config exists yet, the CLI creates:
|
|
33
|
+
|
|
34
|
+
```text
|
|
35
|
+
~/.config/grok-search-cli/config.json
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
In most cases, you only need to set an API key from [xAI](https://x.ai/api):
|
|
39
|
+
|
|
40
|
+
```json
|
|
41
|
+
{
|
|
42
|
+
"XAI_API_KEY": "your_xai_api_key"
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
If you are using a non-official provider, see [Configuration](#configuration).
|
|
47
|
+
|
|
48
|
+
Run a query:
|
|
23
49
|
|
|
24
50
|
```bash
|
|
51
|
+
# Run a first search
|
|
25
52
|
grok-search "latest xAI updates"
|
|
26
53
|
```
|
|
27
54
|
|
|
28
|
-
If you do not want a global install
|
|
55
|
+
If you do not want a global install, you can run it with `npx`:
|
|
29
56
|
|
|
30
57
|
```bash
|
|
58
|
+
# Run without a global install
|
|
59
|
+
npx grok-search-cli doctor
|
|
31
60
|
npx grok-search-cli "latest xAI updates"
|
|
32
61
|
```
|
|
33
62
|
|
|
34
|
-
|
|
63
|
+
## What You Can Ask
|
|
35
64
|
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
XAI_MODEL=x-ai/grok-4-fast:online
|
|
65
|
+
```bash
|
|
66
|
+
# Search current discussion on X
|
|
67
|
+
grok-search "What are people saying about xAI on X right now?"
|
|
40
68
|
```
|
|
41
69
|
|
|
42
|
-
|
|
70
|
+
```bash
|
|
71
|
+
# Verify a fresh rumor or claim
|
|
72
|
+
grok-search "Somebody said xAI open-sourced model X today. Is that true?"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
# Search papers and repos together
|
|
77
|
+
grok-search "Find the latest arXiv papers and GitHub repos about browser-use agents"
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
# Constrain web results to specific domains
|
|
82
|
+
grok-search "latest AI SDK updates" \
|
|
83
|
+
--allowed-domains=ai-sdk.dev,vercel.com
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
# Constrain X results by handle and date
|
|
88
|
+
grok-search "latest xAI status on X" \
|
|
89
|
+
--allowed-handles=xai,elonmusk \
|
|
90
|
+
--from-date=2026-04-01
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
# Return machine-readable JSON
|
|
95
|
+
grok-search "latest xAI updates" --json
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Why Use It
|
|
99
|
+
|
|
100
|
+
- Research what is happening now, not what the base model remembers
|
|
101
|
+
- Search the web and X in one call
|
|
102
|
+
- Return clean terminal output or JSON for agents
|
|
103
|
+
- Work with xAI, OpenRouter, or compatible gateways
|
|
43
104
|
|
|
44
105
|
## Use With Agents
|
|
45
106
|
|
|
46
107
|
This repo ships with an installable skill:
|
|
47
108
|
|
|
48
109
|
```bash
|
|
49
|
-
|
|
110
|
+
# Install the bundled skill with the skills CLI
|
|
111
|
+
npx skills add timzhong1024/grok-search-cli --skill grok-search-cli
|
|
50
112
|
```
|
|
51
113
|
|
|
52
|
-
For Codex,
|
|
114
|
+
For Codex, a matching preset is included at [agents/codex.yaml](./agents/codex.yaml).
|
|
53
115
|
|
|
54
116
|
Trigger it with:
|
|
55
117
|
|
|
@@ -57,83 +119,115 @@ Trigger it with:
|
|
|
57
119
|
Spawn a grok-research researcher agent with gpt-5.4-mini and low reasoning, then use grok-search for high-freshness web+X research.
|
|
58
120
|
```
|
|
59
121
|
|
|
60
|
-
|
|
122
|
+
The bundled skill can also be printed to `stdout` and redirected:
|
|
61
123
|
|
|
62
|
-
|
|
124
|
+
```bash
|
|
125
|
+
# Print the bundled skill and save it manually
|
|
126
|
+
grok-search skill > ~/.codex/skills/grok-search-cli/SKILL.md
|
|
127
|
+
```
|
|
63
128
|
|
|
64
|
-
|
|
65
|
-
2. OpenRouter is also a solid option. Its web plugin can use native xAI search for xAI models, including both Web Search and X Search.
|
|
66
|
-
3. If you use a third-party proxy, verify search support yourself. Many proxies only expose `/chat/completions`, and search only works if the proxy provider has enabled web search on their side.
|
|
129
|
+
## Configuration
|
|
67
130
|
|
|
68
|
-
|
|
131
|
+
`process.env` takes priority over `~/.config/grok-search-cli/config.json`, so shell env is the easiest way to override config temporarily.
|
|
69
132
|
|
|
70
|
-
|
|
133
|
+
By default, the CLI uses the official xAI endpoint and the built-in default model `grok-4-1-fast-non-reasoning`.
|
|
71
134
|
|
|
72
|
-
|
|
135
|
+
| Field | Required | Default behavior | When you might override it |
|
|
136
|
+
| --- | --- | --- | --- |
|
|
137
|
+
| `XAI_API_KEY` | Yes | No default | Required in all cases |
|
|
138
|
+
| `XAI_MODEL` | No | Uses `grok-4-1-fast-non-reasoning` | When you want a different Grok model |
|
|
139
|
+
| `XAI_BASE_URL` | No | Uses the official xAI endpoint | When routing through OpenRouter or another compatible gateway |
|
|
73
140
|
|
|
74
|
-
|
|
75
|
-
- `xai.tools.xSearch()`
|
|
141
|
+
If you want to override the model:
|
|
76
142
|
|
|
77
|
-
|
|
143
|
+
```json
|
|
144
|
+
{
|
|
145
|
+
"XAI_API_KEY": "your_xai_api_key",
|
|
146
|
+
"XAI_MODEL": "grok-4-1-fast-non-reasoning"
|
|
147
|
+
}
|
|
148
|
+
```
|
|
78
149
|
|
|
79
|
-
|
|
150
|
+
Important: model IDs are provider-specific. The official xAI model ID, the OpenRouter model ID, and the model ID expected by another compatible gateway may not match. If you switch providers, check the provider's expected model name instead of reusing the previous one unchanged.
|
|
80
151
|
|
|
81
|
-
|
|
152
|
+
### OpenRouter Example
|
|
82
153
|
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
|
|
154
|
+
```json
|
|
155
|
+
{
|
|
156
|
+
"XAI_API_KEY": "your_openrouter_api_key",
|
|
157
|
+
"XAI_MODEL": "x-ai/grok-4.1-fast",
|
|
158
|
+
"XAI_BASE_URL": "https://openrouter.ai/api/v1"
|
|
159
|
+
}
|
|
86
160
|
```
|
|
87
161
|
|
|
88
|
-
|
|
162
|
+
### Other Compatible Gateway Example
|
|
89
163
|
|
|
90
|
-
|
|
164
|
+
```json
|
|
165
|
+
{
|
|
166
|
+
"XAI_API_KEY": "your_proxy_api_key",
|
|
167
|
+
"XAI_MODEL": "grok-4-fast",
|
|
168
|
+
"XAI_BASE_URL": "https://yunwu.ai/v1",
|
|
169
|
+
"XAI_COMPAT_MODE": true
|
|
170
|
+
}
|
|
171
|
+
```
|
|
91
172
|
|
|
92
|
-
|
|
173
|
+
For gateways such as yunwu, set `XAI_COMPAT_MODE=true`.
|
|
93
174
|
|
|
94
|
-
|
|
95
|
-
- tool-specific flags such as `--allowed-domains`, `--allowed-handles`, and `--from-date` are not forwarded; the CLI prints a warning if you pass them
|
|
175
|
+
## Provider Guide
|
|
96
176
|
|
|
97
|
-
|
|
177
|
+
Recommended order:
|
|
98
178
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
179
|
+
1. Use official xAI APIs when possible. This is the most direct and stable path for `web_search` and `x_search`.
|
|
180
|
+
2. OpenRouter is the best fallback when you do not want to use xAI directly. It is the most predictable non-official option here.
|
|
181
|
+
3. Third-party compatible gateways such as yunwu are a compatibility fallback. Verify search support yourself. Many proxies only expose `/chat/completions`, and search only works if the proxy provider has enabled web search on their side.
|
|
102
182
|
|
|
103
|
-
|
|
104
|
-
grok-search "Somebody said xAI open-sourced model X today. Is that true?"
|
|
105
|
-
```
|
|
183
|
+
Recommended model choices:
|
|
106
184
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
185
|
+
| Provider | Recommended model | Why |
|
|
186
|
+
| --- | --- | --- |
|
|
187
|
+
| xAI official | `grok-4-1-fast-non-reasoning` | Default path in this CLI, best support for `web_search` and `x_search` |
|
|
188
|
+
| OpenRouter | `x-ai/grok-4.1-fast` | Best default when routing through OpenRouter |
|
|
189
|
+
| Other compatible gateways such as yunwu | Provider-specific | Use the model ID your gateway actually exposes, for example `grok-4-fast` on yunwu |
|
|
110
190
|
|
|
111
|
-
|
|
112
|
-
grok-search "latest AI SDK updates" \
|
|
113
|
-
--allowed-domains=ai-sdk.dev,vercel.com
|
|
114
|
-
```
|
|
191
|
+
## Search Modes
|
|
115
192
|
|
|
116
|
-
|
|
117
|
-
grok-search "latest xAI status on X" \
|
|
118
|
-
--allowed-handles=xai,elonmusk \
|
|
119
|
-
--from-date=2026-04-01
|
|
120
|
-
```
|
|
193
|
+
### xAI Official
|
|
121
194
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
195
|
+
Use this when you connect directly to xAI.
|
|
196
|
+
|
|
197
|
+
- Supports both web search and X search
|
|
198
|
+
- Supports web domain filters, X handle filters, date filters, and image or video understanding options
|
|
199
|
+
- Best choice when you want the full feature set
|
|
200
|
+
|
|
201
|
+
### OpenRouter
|
|
202
|
+
|
|
203
|
+
Use this when `XAI_BASE_URL` points to `openrouter.ai`.
|
|
204
|
+
|
|
205
|
+
- Supports web search through OpenRouter's server-side search tool
|
|
206
|
+
- Supports web domain filters
|
|
207
|
+
- Does not currently forward X-specific filters such as handles, dates, image, or video options
|
|
208
|
+
|
|
209
|
+
### Other Compatible Gateways
|
|
210
|
+
|
|
211
|
+
Use this when you connect through another OpenAI-compatible gateway.
|
|
212
|
+
|
|
213
|
+
- Uses the gateway's compatibility path
|
|
214
|
+
- Search behavior depends on the gateway
|
|
215
|
+
- Tool-specific filters are not forwarded, so advanced search controls may not be available
|
|
216
|
+
|
|
217
|
+
## CLI Reference
|
|
125
218
|
|
|
126
219
|
```bash
|
|
127
|
-
|
|
220
|
+
# Check whether your config is ready
|
|
221
|
+
grok-search doctor
|
|
128
222
|
```
|
|
129
223
|
|
|
130
|
-
The command prints the bundled skill to `stdout`, so it can also be redirected:
|
|
131
|
-
|
|
132
224
|
```bash
|
|
133
|
-
|
|
225
|
+
# Print the bundled skill to stdout
|
|
226
|
+
grok-search skill
|
|
134
227
|
```
|
|
135
228
|
|
|
136
229
|
```bash
|
|
230
|
+
# Show all CLI options
|
|
137
231
|
grok-search --help
|
|
138
232
|
```
|
|
139
233
|
|
|
@@ -142,6 +236,7 @@ grok-search --help
|
|
|
142
236
|
For local `.env` workflows, `pnpm dev` already runs through `dotenvx`:
|
|
143
237
|
|
|
144
238
|
```bash
|
|
239
|
+
# Run the TypeScript entrypoint through dotenvx in development
|
|
145
240
|
pnpm install
|
|
146
241
|
pnpm dev "latest xAI updates" --verbose
|
|
147
242
|
```
|
package/README.zh.md
CHANGED
|
@@ -2,54 +2,115 @@
|
|
|
2
2
|
|
|
3
3
|
[English](./README.md)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](https://github.com/timzhong1024/grok-search-cli)
|
|
6
|
+
[](https://www.npmjs.com/package/grok-search-cli)
|
|
7
|
+
[](https://www.npmjs.com/package/grok-search-cli)
|
|
8
|
+
[](./LICENSE)
|
|
9
|
+
[](https://nodejs.org/)
|
|
6
10
|
|
|
7
|
-
|
|
11
|
+
把 Grok 对 X 以及 GitHub、arXiv 等高价值公开数据源的访问能力,带到任何 agent 和 shell 工作流里。
|
|
8
12
|
|
|
9
|
-
|
|
13
|
+
这个 CLI 让这套能力可以直接用于 agent 工作流:在处理快速变化的话题时,更容易获得更新鲜的信息,同时显著降低自建和维护搜索能力的成本。
|
|
14
|
+
|
|
15
|
+
## 快速开始
|
|
16
|
+
|
|
17
|
+
先安装:
|
|
10
18
|
|
|
11
19
|
```bash
|
|
20
|
+
# 全局安装 CLI
|
|
12
21
|
pnpm add -g grok-search-cli
|
|
13
22
|
```
|
|
14
23
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
#
|
|
19
|
-
|
|
24
|
+
然后做一次健康检查:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# 检查当前配置是否可用
|
|
28
|
+
grok-search doctor
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
如果本地还没有配置文件,CLI 会自动创建:
|
|
32
|
+
|
|
33
|
+
```text
|
|
34
|
+
~/.config/grok-search-cli/config.json
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
大多数情况下,你只需要填一个从 [xAI](https://x.ai/api) 获取的 API key:
|
|
38
|
+
|
|
39
|
+
```json
|
|
40
|
+
{
|
|
41
|
+
"XAI_API_KEY": "your_xai_api_key"
|
|
42
|
+
}
|
|
20
43
|
```
|
|
21
44
|
|
|
22
|
-
|
|
45
|
+
如果你使用的是非官方提供商,见下方的[配置方式](#配置方式)。
|
|
46
|
+
|
|
47
|
+
然后执行查询:
|
|
23
48
|
|
|
24
49
|
```bash
|
|
50
|
+
# 先跑一个最基本的搜索
|
|
25
51
|
grok-search "latest xAI updates"
|
|
26
52
|
```
|
|
27
53
|
|
|
28
|
-
|
|
54
|
+
如果不想全局安装,也可以通过 `npx` 运行:
|
|
29
55
|
|
|
30
56
|
```bash
|
|
57
|
+
# 不全局安装,直接用 npx 运行
|
|
58
|
+
npx grok-search-cli doctor
|
|
31
59
|
npx grok-search-cli "latest xAI updates"
|
|
32
60
|
```
|
|
33
61
|
|
|
34
|
-
|
|
62
|
+
## 可以怎么搜
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
# 看看现在 X 上都在怎么讨论 xAI
|
|
66
|
+
grok-search "现在 X 上大家都在怎么讨论 xAI?"
|
|
67
|
+
```
|
|
35
68
|
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
XAI_MODEL=x-ai/grok-4-fast:online
|
|
69
|
+
```bash
|
|
70
|
+
# 验证一个刚出现的说法是不是真的
|
|
71
|
+
grok-search "有人说 xAI 今天开源了某个模型,这是真的吗?"
|
|
40
72
|
```
|
|
41
73
|
|
|
42
|
-
|
|
74
|
+
```bash
|
|
75
|
+
# 一次找论文和 GitHub 项目
|
|
76
|
+
grok-search "找最新的 browser-use agents 相关 arXiv 论文和 GitHub 项目"
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
# 把网页搜索限制在指定站点
|
|
81
|
+
grok-search "latest AI SDK updates" \
|
|
82
|
+
--allowed-domains=ai-sdk.dev,vercel.com
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
# 按账号和日期限制 X 搜索范围
|
|
87
|
+
grok-search "latest xAI status on X" \
|
|
88
|
+
--allowed-handles=xai,elonmusk \
|
|
89
|
+
--from-date=2026-04-01
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
# 返回适合 agent 消费的 JSON
|
|
94
|
+
grok-search "latest xAI updates" --json
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## 为什么用它
|
|
98
|
+
|
|
99
|
+
- 查“现在发生了什么”,而不是赌模型记忆有没有过时
|
|
100
|
+
- 一次调用同时看网页和 X
|
|
101
|
+
- 终端可直接读,agent 也能吃 JSON
|
|
102
|
+
- 可接 xAI、OpenRouter 和兼容代理站
|
|
43
103
|
|
|
44
104
|
## 给 Agent 用
|
|
45
105
|
|
|
46
106
|
这个仓库自带一个可安装 skill:
|
|
47
107
|
|
|
48
108
|
```bash
|
|
49
|
-
|
|
109
|
+
# 用 skills CLI 安装仓库自带的 skill
|
|
110
|
+
npx skills add timzhong1024/grok-search-cli --skill grok-search-cli
|
|
50
111
|
```
|
|
51
112
|
|
|
52
|
-
如果是 Codex
|
|
113
|
+
如果是 Codex,仓库里还带了一份可配套使用的 preset,见 [agents/codex.yaml](./agents/codex.yaml)。
|
|
53
114
|
|
|
54
115
|
可直接用这句触发:
|
|
55
116
|
|
|
@@ -57,83 +118,115 @@ npx skills add <owner>/<repo> --skill grok-search-cli
|
|
|
57
118
|
Spawn a grok-research researcher agent with gpt-5.4-mini and low reasoning, then use grok-search for high-freshness web+X research.
|
|
58
119
|
```
|
|
59
120
|
|
|
60
|
-
|
|
121
|
+
内置 skill 也可以直接打印到 `stdout` 后手动安装:
|
|
61
122
|
|
|
62
|
-
|
|
123
|
+
```bash
|
|
124
|
+
# 把内置 skill 打印出来并手动保存
|
|
125
|
+
grok-search skill > ~/.codex/skills/grok-search-cli/SKILL.md
|
|
126
|
+
```
|
|
63
127
|
|
|
64
|
-
|
|
65
|
-
2. OpenRouter 也比较稳。它的 web 插件对 xAI 模型可以走原生 xAI 搜索,包含 Web Search 和 X Search。
|
|
66
|
-
3. 如果使用第三方代理站,需要自己确认搜索能力。很多代理站只暴露 `/chat/completions`,是否真的能搜索,取决于站点是否在内部为你开启了 web search。
|
|
128
|
+
## 配置方式
|
|
67
129
|
|
|
68
|
-
|
|
130
|
+
`process.env` 的优先级高于 `~/.config/grok-search-cli/config.json`,因此在临时覆盖配置时,优先使用 shell 环境变量。
|
|
69
131
|
|
|
70
|
-
|
|
132
|
+
默认情况下,CLI 会使用 xAI 官方地址和内置默认模型 `grok-4-1-fast-non-reasoning`。
|
|
71
133
|
|
|
72
|
-
|
|
134
|
+
| 字段 | 是否必填 | 默认行为 | 什么时候可能要改 |
|
|
135
|
+
| --- | --- | --- | --- |
|
|
136
|
+
| `XAI_API_KEY` | 是 | 无默认值 | 所有场景都必须提供 |
|
|
137
|
+
| `XAI_MODEL` | 否 | 使用 `grok-4-1-fast-non-reasoning` | 当你想切换到其他 Grok 模型时 |
|
|
138
|
+
| `XAI_BASE_URL` | 否 | 使用 xAI 官方地址 | 当你要接 OpenRouter 或其他兼容网关时 |
|
|
73
139
|
|
|
74
|
-
|
|
75
|
-
- `xai.tools.xSearch()`
|
|
140
|
+
如果你想手动覆盖模型,可以这样写:
|
|
76
141
|
|
|
77
|
-
|
|
142
|
+
```json
|
|
143
|
+
{
|
|
144
|
+
"XAI_API_KEY": "your_xai_api_key",
|
|
145
|
+
"XAI_MODEL": "grok-4-1-fast-non-reasoning"
|
|
146
|
+
}
|
|
147
|
+
```
|
|
78
148
|
|
|
79
|
-
|
|
149
|
+
注意:不同服务商使用的 model id 不一定一样。xAI 官方、OpenRouter、以及其他兼容网关,通常都需要各自对应的模型名。切换服务商时,不要直接沿用原来的 model id。
|
|
80
150
|
|
|
81
|
-
|
|
151
|
+
### OpenRouter 示例
|
|
82
152
|
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
|
|
153
|
+
```json
|
|
154
|
+
{
|
|
155
|
+
"XAI_API_KEY": "your_openrouter_api_key",
|
|
156
|
+
"XAI_MODEL": "x-ai/grok-4.1-fast",
|
|
157
|
+
"XAI_BASE_URL": "https://openrouter.ai/api/v1"
|
|
158
|
+
}
|
|
86
159
|
```
|
|
87
160
|
|
|
88
|
-
|
|
161
|
+
### 其他兼容网关示例
|
|
89
162
|
|
|
90
|
-
|
|
163
|
+
```json
|
|
164
|
+
{
|
|
165
|
+
"XAI_API_KEY": "your_proxy_api_key",
|
|
166
|
+
"XAI_MODEL": "grok-4-fast",
|
|
167
|
+
"XAI_BASE_URL": "https://yunwu.ai/v1",
|
|
168
|
+
"XAI_COMPAT_MODE": true
|
|
169
|
+
}
|
|
170
|
+
```
|
|
91
171
|
|
|
92
|
-
|
|
172
|
+
像 yunwu 这类兼容网关,通常需要设置 `XAI_COMPAT_MODE=true`。
|
|
93
173
|
|
|
94
|
-
|
|
95
|
-
- `--allowed-domains`、`--allowed-handles`、`--from-date` 这类 tool 参数不会下传;如果传了,CLI 会打印 warning
|
|
174
|
+
## 服务选择建议
|
|
96
175
|
|
|
97
|
-
|
|
176
|
+
推荐顺序:
|
|
98
177
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
178
|
+
1. 优先使用 xAI 官方服务。这是 `web_search` 和 `x_search` 最直接、最稳定的路径。
|
|
179
|
+
2. 如果不直连 xAI,优先用 OpenRouter。这是这里最稳的非官方选项。
|
|
180
|
+
3. 第三方兼容网关,例如 yunwu,更适合作为兼容兜底。很多代理站只暴露 `/chat/completions`,是否真的能搜索,取决于站点是否在内部为你开启了 web search。
|
|
102
181
|
|
|
103
|
-
|
|
104
|
-
grok-search "有人说 xAI 今天开源了某个模型,这是真的吗?"
|
|
105
|
-
```
|
|
182
|
+
推荐模型:
|
|
106
183
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
184
|
+
| 服务商 | 推荐模型 | 说明 |
|
|
185
|
+
| --- | --- | --- |
|
|
186
|
+
| xAI 官方 | `grok-4-1-fast-non-reasoning` | 这是当前 CLI 的默认模型,也是 `web_search` 和 `x_search` 支持最完整的路径 |
|
|
187
|
+
| OpenRouter | `x-ai/grok-4.1-fast` | 通过 OpenRouter 接入时,优先用这个 |
|
|
188
|
+
| 其他兼容网关,例如 yunwu | 以网关实际支持的 model id 为准 | 比如 yunwu 示例里使用 `grok-4-fast` |
|
|
110
189
|
|
|
111
|
-
|
|
112
|
-
grok-search "latest AI SDK updates" \
|
|
113
|
-
--allowed-domains=ai-sdk.dev,vercel.com
|
|
114
|
-
```
|
|
190
|
+
## 搜索模式
|
|
115
191
|
|
|
116
|
-
|
|
117
|
-
grok-search "latest xAI status on X" \
|
|
118
|
-
--allowed-handles=xai,elonmusk \
|
|
119
|
-
--from-date=2026-04-01
|
|
120
|
-
```
|
|
192
|
+
### xAI 官方
|
|
121
193
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
194
|
+
直接连接 xAI 官方服务时使用。
|
|
195
|
+
|
|
196
|
+
- 同时支持 Web Search 和 X Search
|
|
197
|
+
- 支持网页域名过滤、X 账号过滤、日期过滤,以及图片或视频理解选项
|
|
198
|
+
- 这是能力最完整的模式
|
|
199
|
+
|
|
200
|
+
### OpenRouter
|
|
201
|
+
|
|
202
|
+
当 `XAI_BASE_URL` 指向 `openrouter.ai` 时使用。
|
|
203
|
+
|
|
204
|
+
- 支持通过 OpenRouter 的服务端搜索工具进行网页搜索
|
|
205
|
+
- 只支持网页域名过滤
|
|
206
|
+
- **不支持**配置 X 专属配置,例如账号、日期、以及图片或视频理解选项
|
|
207
|
+
|
|
208
|
+
### 其他兼容网关
|
|
209
|
+
|
|
210
|
+
当你通过其他 OpenAI-compatible 网关接入时使用。
|
|
211
|
+
|
|
212
|
+
- 使用网关提供的兼容调用路径
|
|
213
|
+
- 是否真的搜索、怎么搜索,由中转站决定
|
|
214
|
+
- 不支持所有搜索高级配置
|
|
215
|
+
|
|
216
|
+
## CLI 参考
|
|
125
217
|
|
|
126
218
|
```bash
|
|
127
|
-
|
|
219
|
+
# 检查当前配置是否可用
|
|
220
|
+
grok-search doctor
|
|
128
221
|
```
|
|
129
222
|
|
|
130
|
-
这个命令会把内置 skill 直接打印到 `stdout`,所以也可以重定向保存:
|
|
131
|
-
|
|
132
223
|
```bash
|
|
133
|
-
|
|
224
|
+
# 把内置 skill 打印到 stdout
|
|
225
|
+
grok-search skill
|
|
134
226
|
```
|
|
135
227
|
|
|
136
228
|
```bash
|
|
229
|
+
# 查看完整命令帮助
|
|
137
230
|
grok-search --help
|
|
138
231
|
```
|
|
139
232
|
|
|
@@ -142,6 +235,7 @@ grok-search --help
|
|
|
142
235
|
本地如果要走 `.env`,`pnpm dev` 已经默认走 `dotenvx`:
|
|
143
236
|
|
|
144
237
|
```bash
|
|
238
|
+
# 开发时通过 dotenvx 运行 TypeScript 入口
|
|
145
239
|
pnpm install
|
|
146
240
|
pnpm dev "latest xAI updates" --verbose
|
|
147
241
|
```
|