ASKGROK is a small backend API that opens a real browser, lets the user log in to grok.com, sends prompts through the chat box, waits for the answer, and returns the response text from the backend.
- Node.js 20+
- npm 10+
- Playwright Chromium
- Network access to
https://grok.com - A Grok account
- A headed browser environment for the initial login
- macOS, Linux, and Windows should work in principle, but the current development environment is macOS on Apple Silicon
ASKGROK is not an official Grok API client. It uses Playwright to automate a real browser session. Headless or server-only environments may require extra browser display setup such as Xvfb.
npm install
npx playwright install chromium
npm startBy default the API listens on http://localhost:3000.
| Variable | Default | Description |
|---|---|---|
PORT |
3000 |
API server port. |
HEADLESS |
false |
Run the browser headlessly. First login usually requires false. |
GROK_PROFILE_DIR |
.askgrok-profile |
Persistent browser profile directory. |
GROK_URL |
https://grok.com |
Grok web URL. |
Open a browser session for manual Grok login:
curl -X POST http://localhost:3000/loginA browser window will open at https://grok.com. Log in normally. ASKGROK stores the session in .askgrok-profile/, so you usually only need to do this once.
curl -X POST http://localhost:3000/ask \
-H 'Content-Type: application/json' \
-d '{"prompt":"Explain quantum computing in one paragraph."}'Response:
{
"response": "..."
}Returns server status.
Launches or reuses a headed browser window and navigates to Grok for manual login.
Body:
{
"prompt": "Your question",
"timeoutMs": 120000
}timeoutMs is optional. Requests are handled one at a time so Grok conversations do not overlap.
If a Grok browser session is already open, ASKGROK asks in the current session instead of navigating back to a new chat. It only opens or navigates to Grok when no usable Grok page exists.
Runs the structured ASKGROK crypto sentiment prompt and returns normalized JSON for the ETL pipeline. Grok can use web/search context freely, including X/Twitter, news, market commentary, forums, blogs, and price context.
Body:
{
"startUtc": "2022-05-20T00:00:00Z",
"endUtc": "2022-05-20T01:00:00Z",
"assets": ["BTC", "ETH", "LUNA", "UST"],
"timeoutMs": 180000,
"includeRaw": false
}Example:
curl -X POST http://localhost:3000/sentiment/crypto \
-H 'Content-Type: application/json' \
-d '{"startUtc":"2022-05-20T00:00:00Z","endUtc":"2022-05-20T01:00:00Z","assets":["BTC","ETH","LUNA","UST"],"timeoutMs":180000}'POST /sentiment/x-crypto remains available as a backward-compatible alias.
Response:
{
"sentiment": {
"timestamp_utc": "2022-05-20T00:00:00.000Z",
"window_end_utc": "2022-05-20T01:00:00.000Z",
"source": "ASKGROK_WEB",
"data
6636
_scope": "web_research",
"market": "crypto",
"assets": ["BTC", "ETH", "LUNA", "UST"],
"sentiment_score": -0.7,
"sentiment_label": "fear",
"confidence": 0.65,
"social_volume_proxy": null,
"bullish_intensity": 0.1,
"bearish_intensity": 0.8,
"fear_intensity": 0.85,
"fomo_intensity": 0.05,
"uncertainty_intensity": 0.75,
"dominant_emotions": ["fear", "uncertainty"],
"dominant_topics": ["Terra collapse", "Bitcoin drawdown"],
"notable_terms": ["capitulation", "bear market"],
"evidence_sources": ["X/Twitter", "market news", "price context"],
"evidence_summary": "...",
"sample_size_estimate": null,
"limitations": "..."
}
}Closes the browser context.
- The browser runs in headed mode because login requires user interaction.
- If Grok changes its web UI, selectors may need adjustment in
src/grokClient.js. - Use this with your own account and follow Grok's terms and rate limits.