npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@anvia/grok

v0.2.7

Published

Grok provider adapter for Anvia.

Readme

@anvia/grok

Grok provider adapter for Anvia.

Use this package when you want Anvia agents, extractors, pipelines, image generation, or model listing to run on xAI Grok APIs.

Installation

pnpm add @anvia/grok @anvia/core

In this monorepo, the package is available through the workspace:

pnpm --filter @anvia/grok build

Usage

import { AgentBuilder } from "@anvia/core";
import { GrokClient } from "@anvia/grok";

const client = new GrokClient({
  apiKey,
});

const model = client.completionModel("grok-4.3");

const agent = new AgentBuilder("assistant", model)
  .instructions("Answer clearly and concisely.")
  .build();

const response = await agent.prompt("Summarize Anvia in one sentence.").send();

console.log(response.output);

Completion APIs

GrokClient targets https://api.x.ai/v1 by default and uses the Responses adapter by default:

const client = new GrokClient({
  apiKey: process.env.XAI_API_KEY,
});

Use the Chat Completions adapter when a workflow specifically needs that surface:

const chatClient = new GrokClient({
  apiKey: process.env.XAI_API_KEY,
  completionApi: "chat",
});

Provider-specific xAI parameters can be passed through completion additionalParams.

const response = await model.completion({
  chatHistory,
  documents: [],
  tools,
  additionalParams: {
    reasoning: { effort: "high" },
  },
});

Image Generation

import { GROK_IMAGINE_IMAGE, GrokClient } from "@anvia/grok";

const client = new GrokClient({ apiKey });
const imageModel = client.imageGenerationModel(GROK_IMAGINE_IMAGE);

const result = await imageModel.imageGeneration({
  prompt: "A compact robot drawing architecture diagrams on a glass wall.",
  width: 1024,
  height: 1024,
});

console.log(result.mediaType, result.image.byteLength);

The adapter requests base64 responses by default. If xAI returns image URLs, it fetches those URLs and returns bytes to satisfy Anvia's core image generation contract.

Model Listing

const models = await client.listModels();

Use listing for inventory. Keep a separate app allowlist for production-enabled model ids.

Unsupported xAI SDK Surfaces

The xAI Python SDK also exposes native video, tokenizer, files, batch, collections, stored completions, compaction, deferred chat, and telemetry APIs. This package does not implement those in v1 because Anvia core does not currently expose matching provider-neutral contracts.

Exports

  • GrokClient
  • GrokResponsesCompletionModel
  • GrokChatCompletionModel
  • GrokImageGenerationModel
  • model constants such as GROK_4_3, GROK_4_20, and GROK_IMAGINE_IMAGE
  • grok

Development

pnpm --filter @anvia/grok typecheck
pnpm --filter @anvia/grok test
pnpm --filter @anvia/grok build

Package-local typecheck and build scripts build @anvia/openai first so delegated adapter types are available in a fresh worktree. @anvia/openai builds @anvia/core when needed.