@cartanova/qgrid-cli

中文文档
2.18.0发布于 2026/11/09ES Module构建来源已验证近 30 天下载 5718
原始使用文档
文档目录8 节
  1. Install
  2. Preparing PostgreSQL
  3. Usage
  4. Options
  5. Environment variables
  6. Prerequisites
  7. How it works
  8. SDK integration

@cartanova/qgrid-cli

English · 한국어

Run the Qgrid server in one line. An LLM proxy that exposes OpenAI/Anthropic subscription credits as an HTTP API + dashboard.

Install

npm i -g @cartanova/qgrid-cli

Installing also syncs the qgrid skills automatically:

  • global install: ~/.codex/skills/qgrid, ~/.claude/skills/qgrid
  • project install: .agents/skills/qgrid, .claude/skills/qgrid

Project installs create symlinks, falling back to copies when symlinking fails.

Preparing PostgreSQL

Qgrid needs PostgreSQL to store OAuth tokens and request logs. If you already have a reachable PostgreSQL, connect with --db or the QGRID_DB_* environment variables. If you don't have one locally, you can spin one up with Docker:

docker run --name qgrid-postgres \
  -e POSTGRES_USER=postgres \
  -e POSTGRES_PASSWORD=postgres \
  -e POSTGRES_DB=qgrid \
  -p 5432:5432 \
  -d postgres:18

Usage

# Run with a DB URL
qgrid --db postgres://user:password@host:port/dbname

# Specify a port
qgrid --db postgres://... -p 3000

# Configure the DB with environment variables (flags can be omitted)
export QGRID_DB_HOST=dev.example.com
export QGRID_DB_PORT=5432
export QGRID_DB_USER=postgres
export QGRID_DB_PASSWORD=postgres
export QGRID_DB_NAME=qgrid
qgrid

The CLI translates the public QGRID_DB_* settings into Sonamu's internal SONAMU_DB_* variables. The packaged CLI defaults to NODE_ENV=production; set NODE_ENV=staging only when intentionally running it as a remote non-production service. This profile selection never creates or renames the database selected by QGRID_DB_NAME. The packaged CLI rejects development and test, which require the source development layout.

Once the server is up, open the dashboard at http://localhost:44900 → register tokens through OAuth login. With -p, --port set, connect on that port instead.

The server port is determined only by the default 44900 or --port. The PORT environment variable is not read as CLI server port input. If the selected port is already in use, the CLI exits with an error instead of killing the existing process or falling back to another port.

Stop with Ctrl+C.

Options

qgrid [options]

  --db <url>         PostgreSQL connection URL
  -p, --port <port>  Server port (default: 44900)
  --skip-update      Skip the automatic update check
  -V, --version      Print version
  -h, --help         Help

On startup the CLI checks the latest version on npm and self-updates whenever the installed version differs, including patch releases. The updater installs the exact published version it just resolved and restarts from the updated binary.

Environment variables

Without the --db flag, DB connection info is read from:

VariableDefault
QGRID_DB_HOSTlocalhost
QGRID_DB_PORT5432
QGRID_DB_USERpostgres
QGRID_DB_PASSWORDpostgres
QGRID_DB_NAMEqgrid
SLACK_BOT_TOKEN— (unset disables token-expiry notifications)
SLACK_CHANNEL_ID—
SLACK_EXPIRY_REMINDER_INTERVAL_MINUTES— (unset disables session-expiry repeats)
SLACK_USER_MAP— (tokenName:SlackUserId pairs)

Server behavior variables:

VariableDescriptionDefault
NODE_ENVSonamu runtime profile. Set staging for a remote non-production deploymentproduction

Prerequisites

  • Node.js >= 22
  • PostgreSQL
  • Docker (if running PostgreSQL locally as a container)
  • Claude Code (for Anthropic models)

How it works

The CLI ships the Sonamu-based server as a built-in bundle. On launch:

  1. Verify the DB connection
  2. Start the server (API + dashboard web UI)
  3. Load registered tokens from the DB. Later token additions/changes propagate to the running server in real time via PostgreSQL LISTEN/NOTIFY
  4. OpenAI tokens: call https://chatgpt.com/backend-api/codex/responses directly over HTTPS and decode SSE. Token-level concurrent permits use smooth weighted routing; a 50-item queue waits at most 60 seconds. Full history is replayed with opaque sessionKey-derived prompt-cache affinity, and AbortSignal cancels queued or active work
  5. Anthropic tokens: spawn a fresh, isolated claude process per request (stream-json in/out). Tokens are selected least-used-first. OAuth tokens are refreshed automatically
  6. Tokens over their quota threshold (default 80%) are excluded from routing (usage-lookup failures fail open)

The Qgrid app itself does not depend on Docker, but PostgreSQL is required. If you don't run PostgreSQL locally, running it in Docker is the simplest setup.

OpenAI login uses direct PKCE OAuth, and quota checks call the private wham/usage endpoint directly with Codex CLI identity headers. These ChatGPT backend interfaces are undocumented and may change without notice. Mocked tests do not establish live-provider compatibility.

SDK integration

Once the server is running, call it with @cartanova/qgrid-ai-sdk:

import { generateText } from "ai";
import { qgrid } from "@cartanova/qgrid-ai-sdk";

const { text } = await generateText({
  model: qgrid("openai/gpt-6-luna"),
  prompt: "What's the weather in Seoul?",
});

See the @cartanova/qgrid-ai-sdk README for details.

版本与发布记录

@cartanova/qgrid-cli 共发布 125 个版本,首次发布于 2026/04/13;过去 12 个月发布了 125 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.18.0latest2026/11/09今天
2.17.12026/11/09今天
2.17.02026/11/09今天
2.16.02026/11/09今天
2.15.52026/11/09今天
2.15.42026/11/09今天

关于 @cartanova/qgrid-cli 的常见问题

如何安装 @cartanova/qgrid-cli?

在项目目录运行 npm install @cartanova/qgrid-cli,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 qgrid,可以用 npx qgrid 直接运行。

@cartanova/qgrid-cli 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/cartanova__qgrid-cli 是否存在。

@cartanova/qgrid-cli 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@cartanova/qgrid-cli 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@cartanova/qgrid-cli 可以商用吗?

@cartanova/qgrid-cli 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@cartanova/qgrid-cli 的下载量有多少?

根据 npm 官方下载统计,@cartanova/qgrid-cli 在 2026/10/09 – 2026/11/07 这 30 天内被下载 5,718 次,日均约 191 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cartanova/qgrid-cli 还在维护吗?

最新版本 2.18.0 发布于 2026/11/09(今天);至今共发布 125 个版本,其中过去 12 个月发布了 125 个;首次发布于 2026/04/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。