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

groq-cascade

v1.0.1

Published

Resilient multi-model fallback chain for the Groq API. When one model fails, the next one tries. Users always get a response.

Readme

npm version npm downloads License: MIT

groq-cascade

A resilient multi-model fallback chain for the Groq API. When one model fails, it tries the next. Users always get a response.

Built from production infrastructure at zambo.dev, powering 17 AI products since 2026.


The problem

AI apps that call a single model break in production:

  • Rate limits hit at peak hours
  • Models go offline during maintenance
  • Context windows exceeded on edge cases
  • Empty responses returned silently

Most engineers handle this with a try/catch that shows users an error. This is worse.


The solution

A cascade that tries 6 models in order. If model 1 fails for any reason, it falls to model 2. Down the chain until something works. If everything fails, you can define a hardcoded fallback so users still get something.

llama-3.3-70b-versatile  ← try first (best quality)
  ↓ fails
llama-3.1-8b-instant     ← fast, high availability
  ↓ fails
llama-4-scout-17b        ← Meta's latest
  ↓ fails
gemma2-9b-it             ← Google, different infra
  ↓ fails
qwen-qwq-32b             ← Alibaba, different limits
  ↓ fails
mixtral-8x7b-32768       ← Mistral, long context
  ↓ fails
"your hardcoded fallback" ← always works

Install

npm install groq-cascade
# or
pnpm add groq-cascade

Usage

Basic

import { groqCascade } from "groq-cascade";

const result = await groqCascade({
  apiKey: process.env.GROQ_API_KEY,
  system: "You are a helpful assistant.",
  user: "Summarize this document in 3 bullet points.",
  fallback: "I'm having trouble right now. Please try again in a moment.",
});

console.log(result.text);   // the response
console.log(result.model);  // which model answered
console.log(result.attempts); // how many models were tried

JSON responses

import { groqCascadeJson } from "groq-cascade";

const { data, model } = await groqCascadeJson<{ score: number; reason: string }>({
  apiKey: process.env.GROQ_API_KEY,
  system: "Return only valid JSON.",
  user: "Score this idea from 0-100 and explain why: autonomous drone delivery",
});

console.log(data.score, data.reason);

Custom model list

import { groqCascade } from "groq-cascade";

const result = await groqCascade({
  apiKey: process.env.GROQ_API_KEY,
  user: "Quick question: what's 2+2?",
  models: ["llama-3.1-8b-instant", "gemma2-9b-it"], // just use fast models
  maxTokens: 64,
  temperature: 0,
  fallback: "4",
});

Log failures (monitoring)

const result = await groqCascade({
  apiKey: process.env.GROQ_API_KEY,
  user: "...",
  onModelFailure: (model, error) => {
    console.warn(`[cascade] ${model} failed:`, error);
    // send to Datadog, Sentry, etc.
  },
});

API

groqCascade(options)Promise<CascadeResult>

| Option | Type | Default | Description | |---|---|---|---| | apiKey | string | required | Groq API key | | user | string | required | User message | | system | string | — | System prompt | | messages | CascadeMessage[] | — | Full messages array (overrides system + user) | | models | string[] | 6-model default | Models to try in order | | maxTokens | number | 1024 | Max tokens per attempt | | temperature | number | 0.4 | Sampling temperature | | minLength | number | 40 | Min response chars before treating as failure | | timeoutMs | number | 12000 | Per-model timeout in ms | | fallback | string | — | Returned if all models fail (instead of throwing) | | onModelFailure | fn(model, err) | — | Called on each failure |

groqCascadeJson<T>(options)Promise<{ data: T, model: string, attempts: number }>

Same options. Automatically strips markdown code fences and parses JSON. Throws if no valid JSON found.


License

MIT

Built by Brennan Zambo · @zambodotdev