@aliou/pi-synthetic

中文文档
0.31.1发布于 2026/11/05MITTypeScriptES Module构建来源已验证近 30 天下载 2428

banner

原始使用文档
文档目录19 节
  1. Installation
  2. Get API Key
  3. Configure Credentials
  4. Install Extension
  5. Usage
  6. Models
  7. Web Search Tool
  8. Prompt Cache
  9. Reasoning Levels
  10. Provider API
  11. Quotas Command
  12. Utility API Proxy
  13. Usage Status
  14. Quota Warnings
  15. Library Use
  16. Disabling Features
  17. Development
  18. Requirements
  19. Links

banner

Pi Synthetic Extension

A Pi extension that adds Synthetic as a model provider, giving you access to open-source models through Synthetic's OpenAI-compatible API.

Installation

Get API Key

Sign up here to get an API key (referral link).

Configure Credentials

The extension uses Pi's credential storage. Add your API key to ~/.pi/agent/auth.json (recommended):

{
  "synthetic": { "type": "api_key", "key": "your-api-key-here" }
}

Or set environment variable:

export SYNTHETIC_API_KEY="your-api-key-here"

Credentials are resolved in this order:

  1. CLI --api-key flag
  2. auth.json entry for synthetic
  3. Environment variable SYNTHETIC_API_KEY

Install Extension

# From npm
pi install npm:@aliou/pi-synthetic

# From git
pi install git:github.com/aliou/pi-synthetic

# Local development
pi -e .

Usage

Once installed, select synthetic as your provider and choose from available models:

/model synthetic hf:moonshotai/Kimi-K3

Models

Models come from Synthetic's models API and are cached for four hours. A built-in list covers offline starts and carries per-model reasoning and compatibility overrides the API does not expose.

Synthetic's category IDs (syn:large:text, syn:small:text, syn:large:vision, syn:small:vision) always route to the current best model for that category, so they survive model rotations without reconfiguration.

Web Search Tool

The extension registers synthetic_web_search — a zero-data-retention web search tool. At session start, it checks the Synthetic quotas API in the background even when another provider is selected. The tool is available only after that check confirms a Synthetic subscription; it remains hidden for pay-as-you-go accounts, missing credentials, and quota API failures.

Prompt Cache

Synthetic caches prompt prefixes per inference node. Pi reads cache hits from the prompt_tokens_details.cached_tokens field and prices them at the cache-read rate Synthetic's API reports. Reuse within a session is the reliable case; cross-session reuse is not guaranteed.

Reasoning Levels

Accepted reasoning efforts differ per model. Built-in per-model mappings limit Pi's level picker to what each known model accepts. Some models cannot turn reasoning off; some accept max.

Provider API

Synthetic serves every chat model twice: on an OpenAI-compatible POST /openai/v1 endpoint and on an Anthropic-compatible POST /anthropic/v1/messages endpoint. The full catalog (hf: models and syn: aliases alike) is valid on both surfaces; quotas, pricing, and the web search tool are surface-agnostic.

Pick the surface with /synthetic:settings under Provider > API (default openai-completions). Changes apply after /reload.

The Anthropic surface streams real thinking blocks, uses native tool_use/tool_result, and reports cache reads and writes directly. Its reasoning control is on or off only: effort levels are not graded, and syn:large:text and hf:zai-org/GLM-5.3-Flash cannot turn reasoning off. The OpenAI surface keeps graded effort where the model supports it.

Quotas Command

Check your API usage:

/synthetic:quotas

Utility API Proxy

Web search and quotas can use a proxy instead of https://api.synthetic.new. Configure it with /synthetic:settings under Connection > Utility API Proxy. The proxy is only used for /v2/search and /v2/quotas; model provider calls still use Synthetic's OpenAI-compatible endpoint directly.

If the proxy requires auth, pi-synthetic still requires a Synthetic API key and sends Authorization: Bearer .... If the proxy does not require auth, disable Requires auth and these utility calls skip API key checks and omit Authorization.

Usage Status

When a Synthetic model is active, the footer status bar shows live quota usage (e.g. week:82% (↺in 3d) 5h:95%). Colors follow the same severity assessment as quota warnings: green by default, yellow/red only when projected usage is at risk. The status auto-refreshes every 60 seconds and after each turn.

Quota Warnings

The extension automatically notifies you when you approach or exceed your Synthetic API quotas. Notifications fire on severity transitions and escalations, not as repeated reminders for the same level. Recovered quotas can notify again if they later become risky.

Weekly credits and five-hour request windows are projected from recent usage, so a short burst does not trigger a weekly warning. Without enough history, warnings use current usage instead. For projections, the extension keeps up to 14 days (5 MiB) of quota history under $XDG_STATE_HOME/pi-synthetic/quota-history or Pi's agent state directory. Nothing is stored while quota warnings are disabled.

Library Use

The provider is also available without Pi as @aliou/pi-synthetic/provider. The default export builds a pi-ai Provider:

import { createModels } from "@earendil-works/pi-ai";
import createSyntheticProvider from "@aliou/pi-synthetic/provider";

const models = createModels({ credentials, modelsStore });
models.setProvider(createSyntheticProvider({ api: "openai-completions" }));
await models.refresh();

The baseline catalog always lists. An online refresh fetches the live catalog from Synthetic; refresh({ allowNetwork: false }) restores the host's stored catalog. The provider stays refreshable without credentials: stored keys and SYNTHETIC_API_KEY resolve first, then anonymous access to the public catalog.

The durable extension is available without Pi as @aliou/pi-synthetic/durable. The default export builds a pi-durable Extension:

import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
import { createRegistry, Harness, MemoryStorage } from "@earendil-works/pi-durable";
import createSyntheticExtension from "@aliou/pi-synthetic/durable";

const registry = createRegistry();
registry.install(createSyntheticExtension());

The durable extension ships only the synthetic_web_search tool, with the fixed synthetic_ prefix stored conversations rely on. It reads no settings: the API key comes from the host's Models (getAuth("synthetic")) or the apiKey option, and the utility API proxy comes from the proxyUrl/proxyRequiresAuth options. Truncated results are saved through the host's execution environment when one exists; without one, results stay truncated inline. Re-run after a crash is safe: the tool is a read-only query.

Disabling Features

Each feature (provider, web search, quotas command, usage status, quota warnings) is a separate Pi extension. Disable individual features either through the pi config TUI or by editing ~/.pi/agent/settings.json.

Run pi config to open the resource selector and unselect the extension you want to disable. Press Tab to switch between global and project-local scope.

To disable features directly in ~/.pi/agent/settings.json, list the extensions you want with + (enable) and - (disable) prefixes on paths relative to the package root. For example, to disable usage-status and quota-warnings while keeping the rest active:

{
  "packages": [
    {
      "source": "npm:@aliou/pi-synthetic",
      "extensions": [
        "+extensions/command-quotas/index.ts",
        "-extensions/usage-status/index.ts",
        "-extensions/quota-warnings/index.ts",
        "+extensions/web-search/index.ts",
        "+extensions/provider/index.ts"
      ]
    }
  ]
}

The extension paths map to the files under extensions/ in this repo: provider, web-search, command-quotas, usage-status, and quota-warnings.

The Utility API Proxy setting is not a loadable extension feature. It is a regular setting controlled through /synthetic:settings.

Development

git clone https://github.com/aliou/pi-synthetic.git
cd pi-synthetic
nix develop       # Node.js, pnpm 11, and pre-commit hooks
pnpm install
pnpm run typecheck
pnpm run lint
pnpm run test
pi -e .            # run Pi with the local checkout

The Nix dev shell installs pre-commit hooks for Biome, frozen-lockfile checks, and typechecking. Built-in model entries live in extensions/provider/models.ts; AGENTS.md explains how they combine with the API catalog.

Releases use Changesets. After CI passes on main, the publish workflow opens a release PR; merging it stages the package on npm for manual promotion.

Requirements

  • Pi coding agent v1.0.0+ (required for ProviderConfig.refreshModels dynamic model discovery)
  • Synthetic API key (configured in ~/.pi/agent/auth.json or via SYNTHETIC_API_KEY) for model provider calls and authenticated utility API calls

版本与发布记录

@aliou/pi-synthetic 共发布 80 个版本,首次发布于 2026/01/29;过去 12 个月发布了 80 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.31.1latest2026/11/052 天前
0.31.02026/11/044 天前
0.30.12026/11/016 天前
0.30.02026/10/2712 天前
0.29.22026/10/2217 天前
0.29.12026/10/1821 天前

关于 @aliou/pi-synthetic 的常见问题

如何安装 @aliou/pi-synthetic?

在项目目录运行 npm install @aliou/pi-synthetic,或使用 pnpm add / yarn add / bun add。

@aliou/pi-synthetic 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@aliou/pi-synthetic 支持 ESM 还是 CommonJS?

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

@aliou/pi-synthetic 可以商用吗?

@aliou/pi-synthetic 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@aliou/pi-synthetic 的下载量有多少?

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

@aliou/pi-synthetic 还在维护吗?

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