Skip to content

feat(tools): Add GrokApi.ts — direct xAI client with model discovery and live X search#1005

Open
christauff wants to merge 1 commit intodanielmiessler:mainfrom
christauff:feat/grokapi-direct-xai-client
Open

feat(tools): Add GrokApi.ts — direct xAI client with model discovery and live X search#1005
christauff wants to merge 1 commit intodanielmiessler:mainfrom
christauff:feat/grokapi-direct-xai-client

Conversation

@christauff
Copy link
Copy Markdown
Contributor

Summary

  • Adds PAI/Tools/GrokApi.ts — direct xAI API client giving GrokResearcher actual Grok access
  • Adds PAI/Tools/GrokApi.test.ts — 7 unit tests including self-heal verification
  • Updates GrokResearcherContext.md with correct model names and API usage

Problem

GrokResearcher has no actual xAI API integration. It runs on Claude with a contrarian persona but cannot call Grok or access live X/Twitter data. Model names in the context doc are stale.

Solution

GrokApi.ts is a zero-dependency xAI client (native fetch) with:

  • Model discovery: Queries /v1/models on startup, auto-selects best available
  • Self-healing: Stale model names auto-resolve to nearest match
  • x_search: Live X/Twitter via grok-4 + Responses API
  • Cost tracking: Token/USD logging to stderr
bun GrokApi.ts "prompt"                     # Chat (auto-selects best)
bun GrokApi.ts --search "X post query"      # Live X search (auto grok-4)

Requires XAI_API_KEY. Fails gracefully without it.

Test plan

  • 7 unit tests pass (bun test GrokApi.test.ts)
  • Live X search returns post data with citations
  • Model discovery against 14 xAI models
  • Self-heal: invalid model auto-resolves

🤖 Generated with Claude Code

…and live X search

GrokResearcher currently has no actual xAI API integration — it runs on
Claude with a contrarian persona but cannot call Grok or access live X data.

Adds:
- PAI/Tools/GrokApi.ts: Zero-dependency xAI client with model discovery,
  self-healing model selection, x_search via Responses API, cost tracking
- PAI/Tools/GrokApi.test.ts: 7 unit tests
- Updated GrokResearcherContext.md: Correct models and API docs

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant