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

@plurnk/plurnk-providers-xai

v0.3.3

Published

xAI provider for plurnk-service. Routes xai/{model} aliases through xAI's OpenAI-compatible chat-completions endpoint; pulls real per-token pricing from /v1/language-models at fromEnv time.

Readme

@plurnk/plurnk-providers-xai

xAI provider for plurnk-service. Routes xai/{model} aliases through xAI's OpenAI-compatible chat-completions endpoint, with real per-token pricing pulled from /v1/language-models at construction time.

install

npm install @plurnk/plurnk-providers-xai

Requires Node ≥ 25 (native TypeScript).

use

import Xai from "@plurnk/plurnk-providers-xai";

const provider = await Xai.fromEnv(process.env, "grok-4.3");

const result = await provider.generate({
    messages: [
        { role: "system", content: "You are a plurnk agent." },
        { role: "user",   content: "What is the capital of France?" },
    ],
});

env

No fallback defaults — required vars throw at fromEnv if missing or unparseable. Defaults belong in plurnk-service's .env.example cascade, not in library code.

| Variable | Required | Notes | |---|---|---| | XAI_API_KEY | yes | Bearer token from console.x.ai | | XAI_BASE_URL | no | Override the API root. Default https://api.x.ai/v1 | | PLURNK_PROVIDER_CONTEXT_SIZE | no | Override context window when the per-family default doesn't apply (rare; new model not yet in the table) | | PLURNK_REASON | yes | Universal reasoning budget (PROVIDERS.md §3.8); 0 disables, > 0 picks an effort tier (see translation table below) | | PLURNK_FETCH_TIMEOUT | yes | Universal fetch timeout in ms (PROVIDERS.md §3.9) |

pricing

Real, pulled from xAI's /v1/language-models/{id} at fromEnv time. xAI returns three distinct rates per model in pico-dollars per token:

  • prompt_text_token_price — applied to the non-cached portion of prompt_tokens
  • cached_prompt_text_token_price — applied to cached_tokens (typically lower; xAI's prompt cache discount)
  • completion_text_token_price — applied to completion_tokens

costFor does the full three-rate math: (prompt - cached) × prompt_rate + cached × cached_rate + completion × completion_rate.

context window

xAI does not expose context window via any documented API endpoint. The sibling ships a per-family alias-prefix table sourced from docs.x.ai/developers/models:

| Family prefix | Context | |---|---| | grok-4.20-multi-agent | 2,000,000 | | grok-4.1-fast | 2,000,000 | | grok-4.20 | 1,000,000 | | grok-4.3 | 1,000,000 | | grok-code-fast | 256,000 |

For aliases not matching any prefix, set PLURNK_PROVIDER_CONTEXT_SIZE explicitly. The table updates with xAI's docs page; PRs welcome.

reasoning

xAI's reasoning is a tiered reasoning_effort body param (low | medium | high), not a token budget. The universal PLURNK_REASON (a numeric token budget) translates as:

| PLURNK_REASON | reasoning_effort | |---|---| | 0 | omit (no reasoning) | | 11000 | low | | 10014000 | medium | | 4001+ | high |

Some Grok models reject the param entirely (the non-reasoning variants); requests against those will 400 if PLURNK_REASON > 0. Pick a reasoning-capable alias (grok-4.3, grok-4.20-0309-reasoning) when reasoning is required.

tokenization

Real cl100k_base via gpt-tokenizer (sync, pure JS). xAI's docs document Grok as using cl100k_base; this sibling encodes countTokens(text) accordingly. No per-model dispatch — all current Grok variants share the same encoding.

license

MIT.