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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@tarquinen/opencode-auth-provider

v0.1.7

Published

Reuse OpenCode authentication & provider logic for clean AI calls in plugins

Downloads

2,220

Readme

opencode-auth-provider

A reusable runtime that mirrors OpenCode's provider discovery logic so plugins can reuse the credentials stored in ~/.local/share/opencode/auth.json (API keys and OAuth) to run clean AI calls via the Vercel AI SDK.

Features

  • Loads the same opencode.jsonc configuration layers (global + workspace) and merges provider overrides
  • Reads ~/.local/share/opencode/auth.json and environment variables just like the CLI
  • Installs provider SDK packages on-demand (via Bun) and exposes ready-to-use LanguageModel instances
  • Boots the same OAuth auth plugins as the CLI (Anthropic + Copilot by default, plus anything listed in your opencode.jsonc, e.g. opencode-gemini-auth) so refresh logic matches the CLI
  • Keeps models in sync with models.dev and applies the same filtering rules (e.g. experimental flags)

Usage

import { OpencodeAI } from "opencode-auth-provider"
import { generateText } from "ai"

const runtime = new OpencodeAI({ workspaceDir: process.cwd() })

const { providerID, modelID } = await runtime.getDefaultModel()
const model = await runtime.getLanguageModel(providerID, modelID)

const result = await generateText({
  model,
  prompt: "Summarize the most recent changes",
})

console.log(result.text)

Selecting providers directly

const githubModel = await runtime.getLanguageModel("github-copilot", "gpt-4o-mini")
const response = await generateText({
  model: githubModel,
  messages: [{ role: "user", content: "Explain the PR diff" }],
})

Refreshing state

Call runtime.reset() if you update opencode.jsonc or auth.json during runtime.

Demo script

A ready-to-run script lives at scripts/run-model.ts. It uses the package to pick a model and print the response.

Prerequisites

  1. Bun ≥ 1.1 installed.
  2. OpenCode credentials configured (e.g. ~/.local/share/opencode/auth.json plus any opencode.jsonc files you rely on).
  3. This repo checked out (e.g. /home/dan/.config/opencode/opencode-auth-provider).

Steps

cd /home/dan/.config/opencode/opencode-auth-provider
bun install           # install deps (already done if you ran it once)

Quick single-shot call

bun scripts/run-model.ts --prompt "Say hello"
  • Use --provider <id> and --model <id> to override the defaults (otherwise it uses whatever opencode.jsonc marks as default).
  • Use --cwd /path/to/project if you want the runtime to load configs from another workspace.
  • The script outputs which provider/model were chosen and prints the model text. Any OAuth refresh handling happens automatically.

Interactive picker

bun scripts/chat-with-provider.ts
  • Shows every detected provider + model and lets you pick by number or ID.
  • Prompts for the message text and prints the resulting completion.
  • Press Enter to accept defaults (the same ones OpenCode would use).

Notes

  • The package requires Bun (matching OpenCode) because it relies on Bun.spawn, Bun.hash, and Bun's package installer for on-demand provider SDKs.
  • Additional OAuth plugins can be added by listing them in opencode.jsonc and installing their npm packages alongside this library.
  • By default the Anthropic and Copilot auth plugins are always loaded (unless OPENCODE_DISABLE_DEFAULT_PLUGINS=1).
  • A bundled snapshot of models.dev is included so cold starts work offline; when the network is available, it continues to refresh the cache hourly just like the CLI.