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

@sarfarajey/vertex-client

v1.0.0

Published

Streaming Vertex AI / Gemini client for edge runtimes — SSE token + tool-call events, retry, context caching. No google-cloud SDK.

Readme

@sarfarajey/vertex-client

Vertex AI / Gemini client built for edge runtimes. No @google-cloud/aiplatform SDK — pure fetch + Web Crypto. Runs in Cloudflare Workers, Vercel Edge, Deno, Bun, and Node 18+.

Includes:

  • Streaming via SSE (token + tool-call events)
  • Function calling
  • Server-side context caching
  • 429 backoff retry on the non-streaming path

Install

npm install @sarfarajey/vertex-client
# pulls @sarfarajey/gcp-edge-auth as a transitive dependency

Single-shot call

import { callVertexAI } from '@sarfarajey/vertex-client';

const text = await callVertexAI({
    serviceAccount: env.SERVICE_ACCOUNT_JSON,
    projectId:      'my-gcp-project',
    systemPrompt:   'You are a concise assistant.',
    userPrompt:     'In 3 bullets, what is RSVP?',
});

Defaults: model: 'gemini-2.5-flash', location: 'us-central1', maxOutputTokens: 1024, temperature: 0.4. Override any of them.

Throws on non-2xx, on MAX_TOKENS truncation, and on empty response.

Streaming

import { callVertexAIStream } from '@sarfarajey/vertex-client';

const events = callVertexAIStream({
    serviceAccount: env.SERVICE_ACCOUNT_JSON,
    projectId:      'my-gcp-project',
    contents: [
        { role: 'user', parts: [{ text: 'Tell me a joke.' }] },
    ],
});

for await (const e of events) {
    if (e.type === 'token')     process.stdout.write(e.text);
    if (e.type === 'tool_call') console.log('\nTOOL:', e.name, e.args);
    if (e.type === 'done')      break;
}

Event shapes:

{ type: 'token',     text: string }
{ type: 'tool_call', name: string, args: object }
{ type: 'done' }

Function calling

const tools = [{
    functionDeclarations: [{
        name: 'get_weather',
        description: 'Get current weather for a city',
        parameters: {
            type: 'object',
            properties: { city: { type: 'string' } },
            required: ['city'],
        },
    }],
}];

for await (const e of callVertexAIStream({
    serviceAccount, projectId,
    contents: [{ role: 'user', parts: [{ text: 'Weather in Tokyo?' }] }],
    tools,
})) {
    if (e.type === 'tool_call') {
        // run the tool, append its result to `contents`, call again…
    }
}

Context caching

For a long system prompt that is reused across many messages, create a cache and pass its resource name to subsequent calls — Gemini bills cached tokens at a discount.

import { createVertexCache, callVertexAIStream } from '@sarfarajey/vertex-client';

const cacheName = await createVertexCache({
    serviceAccount, projectId,
    systemPrompt: longSystemPromptHere,
    ttlSeconds:   600,
});

for await (const e of callVertexAIStream({
    serviceAccount, projectId,
    contents,
    cachedContent: cacheName,  // takes precedence over systemPrompt
})) {
    // ...
}

createVertexCache returns null on failure — degrade gracefully and fall back to inline systemPrompt.

Thinking budget

callVertexAIStream({
    serviceAccount, projectId,
    contents,
    thinkingBudget: 1024, // tokens
});

Auth

Uses @sarfarajey/gcp-edge-auth under the hood. Supply your service account JSON (string or parsed object) — access tokens are cached for the process lifetime by client_email + scope.

License

MIT