Polyweave

@polyweave/xai (1.0.2)

Published 2026-07-10 15:59:03 +00:00 by Dvorak

Installation

@polyweave:registry=https://hub.kl1.tenere.ai/api/packages/Polyweave/npm/
npm install @polyweave/xai@1.0.2
"@polyweave/xai": "1.0.2"

About this package

xAI (Grok)

xAI Grok adapter for Polyweave. Chat, image generation, and 1M token context window.

Published as @polyweave/xai.

Synopsis

import { createXAIAdapter } from '@polyweave/xai';
import { createTextFrame, createImageFrame, createFrameSink } from '@polyweave/core';

var adapter = createXAIAdapter({ apiKey: process.env.XAI_API_KEY, model: 'grok-4.3' });

adapter.source.pipe(createFrameSink(function(frame) {
  if (frame.type === 'TEXT') console.log(frame.content.text);
  if (frame.type === 'IMAGE') console.log('Image:', frame.content.url);
}));

adapter.sink.write(createTextFrame('What is the meaning of life?'));

Install

npm install @polyweave/xai

Description

xAI Grok adapter with OpenAI-compatible chat completions and image generation. Supports Grok's 1M token context window, tool/function calling, and streaming SSE.

Models: grok-4.3, grok-4.20-reasoning, grok-4.20-non-reasoning, grok-4.20-multi-agent, grok-build-0.1, grok-imagine-image.

Dynamic pricing is available via GET https://api.x.ai/v1/models (auth required). The static costs.js file serves as fallback.

API

createXAIAdapter(config)

Parameter Type Default Description
config.apiKey string process.env.XAI_API_KEY API key
config.baseURL string https://api.x.ai/v1 Base URL override
config.model string grok-4.3 Default model
config.budget number 0 Budget cap
config.name string null Node name for PARAM targeting
config.timeout number 120000 Request timeout in ms

Returns an IFrameDuplex with source and sink.

Frame Protocol

Inbound Outbound
TEXT, IMAGE, AUDIO TEXT, IMAGE, TOOL_CALL, RECEIPT, ERROR, END
PARAM
COST_CHECK COST

PARAM Keys

model, max_tokens, temperature, stream, system, tools, tool_choice, image_model, size, n, prompt, budget, apiKey

Tests

npm test

Covers adapter construction, frame buffering, and PARAM accumulation.

Requirements

Node.js 18 or later. ESM only.

Caveats

Voice API endpoints not yet implemented in the adapter. Image generation uses POST /v1/images/generations with per-image cost tracking. IMAGE frames without a task PARAM default to vision mode (routed to chat).

See Also

License

MIT

Dependencies

Development Dependencies

ID Version
@rigor/core *

Peer Dependencies

ID Version
@polyweave/core *
@polyweave/costs *

Keywords

polyweave xai grok llm image-gen voice adapter
Details
npm
2026-07-10 15:59:03 +00:00
4
John Dvorak
SEE LICENSE IN LICENSE
8.0 KiB
Assets (1)
xai-1.0.2.tgz 8.0 KiB
Versions (5) View all
1.0.8 2026-07-11
1.0.5 2026-07-11
1.0.4 2026-07-10
1.0.3 2026-07-10
1.0.2 2026-07-10