xAI Grok Adapter
BoxBrain ships with a ready-made xAI Grok adapter set so you can get started without writing your own provider glue first.
What it includes
createGrokTextModelAdapter
createGrokStructuredModelAdapter
createGrokImageModelAdapter
createGrokAdapters
Provider identifier used by the adapter:
Default base URL:
Bundle setup
Text adapter
The text adapter sends requests to:
It builds a standard message array from:
- optional
system
- required
prompt
Structured-output adapter
The structured adapter also uses:
Behavior:
- if
request.schema exists, it sends response_format: { type: 'json_schema', ... }
- otherwise, it falls back to
response_format: { type: 'json_object' }
- the returned message content is parsed as JSON
This is the adapter used by the current BoxBrain persona, schedule, memory-selection, and conversation-plan flows.
Image adapter
The image adapter sends requests to:
It maps BoxBrain-neutral aspect ratios to xAI payload values like this:
| BoxBrain |
xAI |
square |
1:1 |
portrait |
3:4 |
landscape |
16:9 |
Advanced options
Both the per-capability factories and the bundle helper support:
apiKey
- model name(s)
baseUrl?
fetch?
extraHeaders?
That makes the adapter easy to test or route through custom gateways.
Testing approach used in BoxBrain
The adapter is tested with injected fetch functions instead of a vendor SDK. The test suite asserts:
- URL
- HTTP method
- auth headers
- model selection
- chat messages
- JSON-schema response format
- image aspect-ratio mapping
This keeps the adapter lightweight and deterministic.