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

@godai_dev/llm

v0.1.0

Published

GDI 共通 LLM 基盤(gdi-llm-proxy)クライアント SDK。gdi-auth auth_token を Bearer で転送し、Gemini 応答(stream/非stream)を数行で呼び出す

Readme

@godai_dev/llm

GDI 共通 LLM 基盤(gdi-llm-proxy Worker、llm.gdidatahub.net)を数行で呼び出すためのクライアント SDK です。 server-side 専用です(Cloudflare Workers / Pages Functions / Node.js 内でのみ動作を想定)。 AI SDK は SDK 内部に一切含みません(AI SDK は Worker 側で完結)。ブラウザから直接呼び出すことは想定していません (token を明示的に渡す設計上、ブラウザに置くと token が露出します)。

インストール

npm install @godai_dev/llm

使い方

token を明示的に渡す(正 API)

import { GodaiLLM } from '@godai_dev/llm';

const llm = new GodaiLLM({ token: authToken, appId: 'haikikanri' });
const res = await llm.chat([{ role: 'user', content: 'こんにちは' }]);
console.log(res.content);
  • token: gdi-auth の auth_token(呼び出し元が明示的に渡す。SDK は検証しません — 検証は Worker 側の責務)
  • appId: コスト按分用のアプリ識別子(自己申告・非シークレット・任意)。X-App-Id ヘッダとして送出されます
  • baseURL: Worker のベース URL(デフォルト: https://llm.gdidatahub.net

Cookie ベースの便宜ヘルパ

import { GodaiLLM } from '@godai_dev/llm';

const llm = GodaiLLM.fromRequest(request, { appId: 'haikikanri' });
return llm.stream(messages);

Requestauth_token Cookie から token を取り出して構築します。Cookie が Worker に届かない構成 (gdi-app.jp 側アプリ等)では使えないため、その場合は token を別経路で取得し new GodaiLLM({ token }) に 明示的に渡してください。

非ストリーミング応答(chat)

const res = await llm.chat([{ role: 'user', content: 'こんにちは' }]);
// res.content / res.usage.promptTokens / res.usage.completionTokens / res.model

短い回答・sync が必要な場面向け。Worker の JSON レスポンスをそのまま ChatResponse にマッピングします。

ストリーミング応答(stream)

export async function POST(request: Request) {
  const llm = GodaiLLM.fromRequest(request);
  return llm.stream(messages);
}

Worker から返される AI SDK data stream protocol の Response をそのまま返します。useChat フック (@ai-sdk/react)は Response を直接受け取れるため、Pages Functions / Worker で return llm.stream(messages) と書くだけで動作します。

メッセージの制約

messages'user' / 'assistant' ロールのみ受け付けます。'system' ロールは Prompt Injection 防止 のため拒否されます(型レベルで制限した上に、SDK 内部でも runtime 検証しています)。空配列も拒否されます。

エラーハンドリング

chat() / stream() は失敗時に GodaiLLMErrorError のサブクラス)を throw します。 status / body / code(あれば)/ retryAfter(あれば)を保持します。

import { GodaiLLMError } from '@godai_dev/llm';

try {
  const res = await llm.chat(messages);
} catch (err) {
  if (err instanceof GodaiLLMError) {
    switch (err.code) {
      case 'TOKEN_MISSING':
      case 'EXPIRED':
        // 401: token が無い / 期限切れ。再ログインを促す
        break;
      case 'INVALID_TOKEN':
      case 'FORBIDDEN':
        // 403: token が不正、またはこのアプリ・ユーザーに権限がない
        break;
      case 'AUTH_UNAVAILABLE':
        // 503: gdi-auth 側の障害。時間をおいて再試行
        break;
      case 'RATE_LIMITED':
        // 429: レート制限。err.retryAfter(Retry-After ヘッダ値)を見て再試行間隔を決める
        break;
      case 'PAYLOAD_TOO_LARGE':
        // 413: メッセージ件数・文字数が上限超過。入力を減らす
        break;
      default:
        // 400(JSON不正・モデル不正・role不正等)/ 500/502/504(Worker・プロバイダ障害)は
        // code が付かない場合がある。err.status で分岐する
        break;
    }
  }
}

セキュリティ上の注意: GodaiLLMErrorbody(Worker の生レスポンス)はログ出力用です。 クライアントへのレスポンスには code のみを使用し、body をそのまま転送しないでください。

対応モデル

現時点では以下の 1 モデルのみ対応しています(ChatOptions.model 省略時のデフォルト)。

| ModelId | ラベル | プロバイダ | | --- | --- | --- | | gemini-3.1-flash-lite | Gemini 3.1 Flash Lite | google |

MODELS / SUPPORTED_MODEL_IDS / isModelId / getProvider を import することで、対応モデルの一覧・ 判定に利用できます。