@jmcombs/pi-grok-search
Pi extension that performs real-time web search via the xAI Grok API.
Package details
Install @jmcombs/pi-grok-search from npm and Pi will load the resources declared by the package manifest.
$ pi install npm:@jmcombs/pi-grok-search- Package
@jmcombs/pi-grok-search- Version
2.1.0- Published
- Sep 13, 2026
- Downloads
- 86/mo · 12/wk
- Author
- jmcombs
- License
- MIT
- Types
- extension
- Size
- 38 KB
- Dependencies
- 1 dependency · 3 peers
Pi manifest JSON
{
"extensions": [
"./index.ts"
],
"image": "https://raw.githubusercontent.com/jmcombs/pi-extensions/main/assets/grok-search/preview.png"
}Security note
Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.
README
@jmcombs/pi-grok-search
Real-time web search for the Pi coding agent via the xAI Grok Agent Tools API. Registers
grok_searchfor the model and/grok_setupfor credentials.
Quick Start
Get live Grok search in under a minute:
Install:
pi install npm:@jmcombs/pi-grok-searchAuthenticate. Either works:
/login xai # SuperGrok / X Premium OAuth — preferred if you already subscribe /grok_setup # pick OAuth if Pi already has it, or onboard an API keyAsk for something past the model's cutoff. The agent calls
grok_searchon its own.
See the Pi packages documentation for git, local path, project-scoped install, and filtering options.
What It Adds
- Tool:
grok_search— Grok-powered web search (query) viaPOST https://api.x.ai/v1/responseswithtools: [{ type: "web_search" }]. - Command:
/grok_setup— if xAI OAuth is already inauth.json, a setup card offers Use xAI OAuth or Use an API key instead. Otherwise it runs the@jmcombs/pi-1passwordonboarding dialog. Input never reaches the model.
How It Works
Each grok_search call sends a Bearer token. Which token is a persisted preference,
because OAuth and an API key can both exist:
grokSearch.credentialin~/.pi/agent/settings.json(oauthorapi_key), written by/grok_setup.- OAuth — Pi's
/login xaiSuperGrok / X Premium entry (auth.jsonxaiwithtype: "oauth"). Used when the preference isoauthor unset. Expired access tokens are refreshed automatically. - API key —
resolveSecret("xai_search"), thenresolveSecret("xai")(API-key shaped only), thenresolveSecret("grok"). Used when the preference isapi_key, or when no OAuth is present.
If nothing resolves, first use auto-runs API-key onboarding. If you chose OAuth in
/grok_setup but the token is gone, the tool errors and asks for /login xai or
/grok_setup — it will not silently switch to an API key.
flowchart TD
A["/grok_setup"] --> B{"xAI OAuth in auth.json?"}
B -- "Yes" --> C["Setup card: use OAuth<br/>or override with an API key"]
C -- "Use OAuth" --> D["Persist grokSearch.credential=oauth"]
C -- "API key" --> E["1Password onboardSecret → grok id"]
B -- "No" --> E
E --> F["Persist grokSearch.credential=api_key"]
D --> G["Each grok_search call"]
F --> G
G --> H{"preference"}
H -- "oauth / unset + OAuth present" --> I["Bearer OAuth access token"]
H -- "api_key / no OAuth" --> J["xai_search ?? xai ?? grok"]
/grok_setup never overwrites the shared xai provider entry. API-key onboarding
writes the grok id.
/grok_setup
/grok_setup
- OAuth already present — the card states that SuperGrok / X Premium was discovered and can be used. Keep it, or override with an API key.
- API-key path — the 1Password dialog: vault → item → field when
opis configured, masked manual entry otherwise. Stored undergrokso thexaiprovider credential stays untouched.
The chosen source is saved as grokSearch.credential in settings.json.
After Setup
Talk to the agent normally. It will call grok_search when it needs current web
information.
Configuration
Preference
{
"grokSearch": {
"credential": "oauth"
}
}
"api_key" forces the API-key chain even if OAuth is still logged in.
xAI OAuth
Written by /login xai (do not hand-edit tokens):
{
"xai": {
"type": "oauth",
"access": "…",
"refresh": "…",
"expires": 0
}
}
API key
Provider-shaped entries in ~/.pi/agent/auth.json. Highest precedence first:
xai_search, then xai (API-key shape only), then grok. Literal or
!op read 'op://…':
{
"grok": {
"type": "api_key",
"key": "!op read 'op://Personal/xAI/credential'"
}
}
The !-prefixed value is resolved by the shell at lookup time.
Behavior Notes
- Uses the xAI Responses + Agent Tools API (
web_search). - Honors Pi's abort signal — Esc cancels the HTTP request.
- Missing credentials and 401 / 429 / other non-2xx responses return as tool
content(with status), never via a returnedisError(which Pi ignores).
Requirements
- Pi
>= 0.80.8(credentials via the@jmcombs/pi-1passwordAPI andExtensionAPI) - Node
>= 22.19.0 - xAI OAuth (
/login xaiSuperGrok / X Premium) or an xAI API key - Optional: the
op(1Password) CLI for vault-backed API-key onboarding
Development
This package lives in the pi-extensions monorepo.
See CONTRIBUTING.md at the repo root for project conventions.
# From the repo root
npm ci
npm run check
npm run test -- packages/grok-search
To try local changes against a real Pi session:
pi -e ./packages/grok-search
Tests do not mock the xAI API. index.test.ts checks registration shape;
auth.test.ts / setup.test.ts exercise real temp auth.json / settings.json
and the setup card. Live search is pi -e.
License
MIT © Jeremy Combs
