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

droid-oauth-opencode

v0.3.4

Published

OpenCode plugin for Factory (Droid) LLM proxy models — Claude (incl. Fable 5, Opus Fast Modes) on the Anthropic route plus Droid Core (GLM-5.2 Fast, Kimi, MiniMax, DeepSeek) on the OpenAI route — via the local Factory CLI credential.

Readme

droid-oauth-opencode

Use Factory (Droid) proxied models inside OpenCode, authenticated with the credential the Factory droid CLI already stores on your machine. No API key to paste, no local proxy server, no opencode auth login step.

Two providers are registered:

| OpenCode provider | Route | Models | | --- | --- | --- | | factory | /api/llm/a/v1 (Anthropic Messages API; SDK appends /messages) | Claude Opus 4.8/4.7/4.6/4.5 (+ Fast Modes), Fable 5, Sonnet 5/4.6/4.5, Haiku 4.5 | | factory-g | /api/llm/o/v1 (OpenAI chat/completions) | GLM-5.2 Fast, GLM-5.2, Kimi K2.7 Code, Kimi K2.6, MiniMax M3, MiniMax M2.7, DeepSeek V4 Pro |

factory-g/glm-5.2-fast is Factory's "Droid Core" GLM-5.2 running on Fireworks — the fast variant that has no equivalent in the stock Z.AI / Devin providers. Anthropic Opus *-fast variants send speed: "fast" and the fast-mode-2026-02-01 anthropic-beta flag (same as the droid CLI).

Install

npx droid-oauth-opencode setup --global

Then restart OpenCode and pick a factory/* or factory-g/* model. The plugin reuses the droid CLI credential automatically. If you have never logged in with the droid CLI, run droid once first (or export FACTORY_API_KEY=fk-...).

Project-local install (writes ./opencode.json instead of the global config):

npx droid-oauth-opencode setup --project

How it works

Both routes live on https://app.factory.ai behind one WorkOS bearer token. The plugin registers one provider per route and attaches a custom fetch that injects auth + Factory routing headers.

Authentication and token refresh

The droid CLI stores its WorkOS OAuth tokens encrypted at ~/.factory/auth.v2.file (AES-256-GCM, envelope iv:tag:ciphertext in base64, key base64 in ~/.factory/auth.v2.key) as JSON { access_token, refresh_token, active_organization_id }.

Access tokens are short-lived JWTs. On each request the plugin:

  1. Decrypts the credential and reads the access-token expiry.
  2. If expired (or within 60s of expiry), exchanges the refresh token at https://api.workos.com/user_management/authenticate (grant_type=refresh_token, Factory's production client_id, no organization_id — WorkOS returns organization_not_found if you send one), then re-encrypts the rotated credential back into the exact same envelope (atomic write, so a concurrent droid read never sees a half-written file).
  3. If the server still returns 401, forces one more refresh and retries the request once.

Set FACTORY_API_KEY=fk-... to bypass all of this with a long-lived key.

The factory-g (OpenAI) route quirks

The generic route is fussier than the Anthropic one. sanitizeBody / factoryGenericFetch normalize four things discovered by probing the live endpoint:

  1. x-api-provider header must be the model's upstream backend (fireworks), not the registry enum generic-chat-completion-api (which 400s with Invalid x-api-provider header).
  2. User-Agent must be factory-cli/0.57.0 or newer; older versions 400 with too old to use this endpoint.
  3. Body leakage — the @ai-sdk/openai-compatible SDK leaks provider options (baseURL, apiKey) into the JSON request body, which the route rejects. Unknown keys are stripped to a chat/completions allow-list.
  4. role: "system" is rejected by the Fireworks route; messages are rewritten to role: "developer".
  5. WAF phrases — Factory's edge 403s on exact OpenCode identity strings. Softened in-proxy (punctuation only, same meaning):
    • You are powered by the model namedYou are powered by the model, named
    • You are OpenCode, the best coding agent on the planet.You are OpenCode. The best coding agent on the planet.
  6. Skills beta — OpenCode often sends skills-* without a code_execution tool; Anthropic returns 400. The proxy drops that beta unless the tool is present.

Endpoints

  • Anthropic: POST https://app.factory.ai/api/llm/a/v1/messages
  • Generic: POST https://app.factory.ai/api/llm/o/v1/chat/completions
  • Token refresh: POST https://api.workos.com/user_management/authenticate

Environment variables

| Variable | Purpose | | --- | --- | | FACTORY_API_KEY | Long-lived fk-... key; bypasses the CLI credential + refresh entirely. | | FACTORY_HOME | Override the ~/.factory directory. | | FACTORY_API_BASE_URL | Override https://app.factory.ai. | | FACTORY_CLI_VERSION | Override the factory-cli/<ver> User-Agent (default 0.57.0). | | FACTORY_WORKOS_BASE_URL | Override the WorkOS user_management base URL. | | FACTORY_WORKOS_CLIENT_ID | Override the WorkOS client id used for refresh. |

Development

bun install
bun run build     # tsc -> dist/, bundles bin/setup.js
bun test          # smoke test: decrypt credential + one live request

Source layout:

  • src/credentials.ts — decrypt / refresh / re-encrypt the Factory credential.
  • src/models.ts — static model catalogs for both providers.
  • src/index.ts — the plugin: provider registration + the two fetch hooks.
  • bin/setup.ts — the npx installer that patches OpenCode's config.

The model catalogs and route quirks were reverse-engineered from the droid binary's embedded model registry and confirmed against the live API.

Notes

  • Model availability, -fast variants, and pricing are gated by Factory feature flags on your account; the picker only shows what your org can use.
  • HTTP 402 ("reached your 5-hour standard usage limit") is a Factory billing limit, not a plugin bug — the request authenticated fine.
  • This project is unaffiliated with Factory; it just reuses the credential the official droid CLI already stores locally.

License

MIT — see LICENSE.