@gtrabanco/pi-nan-provider 1.5.4 โ 1.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +63 -32
- package/README.es.md +63 -55
- package/README.md +57 -49
- package/package.json +1 -1
- package/scripts/generate-models.ts +27 -37
- package/scripts/manual-overrides.ts +168 -120
- package/scripts/models.generated.ts +407 -78
- package/src/mcp/media-server.ts +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @gtrabanco/๐-nan-provider
|
|
2
2
|
|
|
3
3
|
[](https://opensource.org/licenses/MIT)
|
|
4
|
-
[](https://github.com/gtrabanco/pi-nan-provider/releases)
|
|
5
5
|
[](https://cloud.nan.builders/r/7GK06FX8)
|
|
6
6
|
|
|
7
7
|
[NaN Builders](https://cloud.nan.builders/r/7GK06FX8) model provider + a native MCP server for [pi](https://github.com/earendil-works/pi).
|
|
@@ -25,8 +25,8 @@ Registers the `nan` provider via `pi.registerProvider()` using NaN's OpenAI-comp
|
|
|
25
25
|
| **Reasoning controls** | Per-model `reasoningEffortValues` + `thinkingLevelMap` ([#16](https://github.com/gtrabanco/pi-nan-provider/issues/16)), the reasoning-only stream guard ([#21](https://github.com/gtrabanco/pi-nan-provider/issues/21)) and the `max_completion_tokens` interim bound for `qwen3.8-flash` ([#34](https://github.com/gtrabanco/pi-nan-provider/issues/34)). |
|
|
26
26
|
| **Attribution header** | `X-Pi-Provider: gtrabanco/pi-nan-provider@<version>` on every request, stripped when pi's install telemetry is disabled. |
|
|
27
27
|
| **Native image models** | `flux-2-klein` and `qwen-image-2.1` registered as pi `type: "image"` models, reachable from codemode and extensions. |
|
|
28
|
-
| **Native MCP media bridge** | The `nan-media` server (
|
|
29
|
-
| **
|
|
28
|
+
| **Native MCP media bridge** | The `nan-media` server (10 tools) registered through `pi.registerMcpServer()`, managed with `/nan-mcp`. |
|
|
29
|
+
| **Credits reporting** | `/nan-usage` shows credits balance with a progress bar, per-model breakdown (input / cached / output in M, credits consumed), and billing period โ all from `GET /v1/usage` ([#37](https://github.com/gtrabanco/pi-nan-provider/issues/37)). |
|
|
30
30
|
| **Cache-anomaly evidence** | `cf-ray` capture on the repeated `id` + `created` gateway signature ([#17](https://github.com/gtrabanco/pi-nan-provider/issues/17)) plus the deterministic `/nan-debug` collector ([#35](https://github.com/gtrabanco/pi-nan-provider/issues/35)). |
|
|
31
31
|
| **pi integration** | Model refresh driven by pi's Models runtime, per-model `models.json` overrides, and the extension changelog (`pi.changelogPath`) that pi shows after an update. |
|
|
32
32
|
|
|
@@ -35,7 +35,7 @@ Commands:
|
|
|
35
35
|
| Command | Purpose |
|
|
36
36
|
| :--- | :--- |
|
|
37
37
|
| `/nan-mcp` | Manage the media MCP bridge (`status` / `enable` / `disable`) |
|
|
38
|
-
| `/nan-usage [1-90]` |
|
|
38
|
+
| `/nan-usage [1-90]` | Credits balance with usage bar, per-model breakdown (in / cached / out in M ยท credits cr), and all-time totals |
|
|
39
39
|
| `/nan-debug [topic] [--window N] [--out path] [--emit]` | Redacted, reproducible evidence package for NaN |
|
|
40
40
|
|
|
41
41
|
---
|
|
@@ -259,6 +259,7 @@ registering a server that can never connect. To get MCP in the CLI, enable the c
|
|
|
259
259
|
| `mcp__nan_media__embed_text` | Text embeddings (qwen3-embedding) |
|
|
260
260
|
| `mcp__nan_media__rerank_documents` | Document reranking (Qwen3-Reranker) |
|
|
261
261
|
| `mcp__nan_media__get_quota` | Per-model token quota (used / cap / remaining / reset) |
|
|
262
|
+
| `mcp__nan_media__get_usage` | Real consumption and credit pool (`GET /v1/usage`; preferred over stale `get_quota` counters) |
|
|
262
263
|
|
|
263
264
|
> pi 0.99.0โ0.99.1 used the hyphenated form (`mcp__nan-media__*`); pi 0.99.2+ sanitizes tool
|
|
264
265
|
> names to `[A-Za-z0-9_]` only, so hyphens became underscores. The underscore form applies
|
|
@@ -269,7 +270,7 @@ registering a server that can never connect. To get MCP in the CLI, enable the c
|
|
|
269
270
|
| Variable | Default | Description |
|
|
270
271
|
| :--- | :--- | :--- |
|
|
271
272
|
| `NAN_MEDIA_MCP` | โ | Per-session override (`0` or `false` to disable). |
|
|
272
|
-
| `NAN_MEDIA_MCP_VERSION` | `1.
|
|
273
|
+
| `NAN_MEDIA_MCP_VERSION` | `1.5.0` | Pinned server version (recommended). |
|
|
273
274
|
| `NAN_MEDIA_MCP_COMMAND` | โ | Custom command override. |
|
|
274
275
|
| `NAN_MEDIA_MCP_TIMEOUT_MS` | `120000` | Per-call timeout. |
|
|
275
276
|
|
|
@@ -290,22 +291,22 @@ included) for human review โ see `.github/workflows/check-pi-sdk-versions.yml`
|
|
|
290
291
|
|
|
291
292
|
---
|
|
292
293
|
|
|
293
|
-
## ๐
|
|
294
|
+
## ๐ Credits: `/nan-usage`
|
|
294
295
|
|
|
295
|
-
Shows your NaN
|
|
296
|
+
Shows your NaN credits balance with a progress bar, per-model breakdown (input / cached / output in millions, credits consumed), billing period, and all-time totals.
|
|
296
297
|
|
|
297
298
|
### How it works
|
|
298
299
|
|
|
299
300
|
`/nan-usage` calls NaN's [`GET /v1/usage`](https://nan.builders/docs/api#tag/usage) endpoint with the **same API key you already use for chat** โ pi's stored credential (`/login nan`) or `NAN_API_KEY`. No CLI login, no session cookie, no extra setup.
|
|
300
301
|
|
|
301
|
-
The endpoint returns your usage (rows per date and model) plus totals covering the requested window โ at most 90 inclusive days. The command reads those totals and
|
|
302
|
+
The endpoint returns your usage (rows per date and model) plus totals covering the requested window โ at most 90 inclusive days. The command reads those totals and displays them in a credits-first layout: the main progress bar reflects credits consumed vs. your plan's allowance, and each model row shows tokens (in / cached / out) and the credits it cost.
|
|
302
303
|
|
|
303
304
|
Rate limit: 30 requests per minute for `/usage`, separate from the model endpoints.
|
|
304
305
|
|
|
305
306
|
### Usage
|
|
306
307
|
|
|
307
308
|
```
|
|
308
|
-
/nan-usage # current UTC month (matches the
|
|
309
|
+
/nan-usage # current UTC month (matches the billing period)
|
|
309
310
|
/nan-usage 7 # rolling 7-day window (1-90)
|
|
310
311
|
/nan-usage 30 # rolling 30-day window
|
|
311
312
|
/nan-usage help # show the usage line
|
|
@@ -333,36 +334,31 @@ Rate limit: 30 requests per minute for `/usage`, separate from the model endpoin
|
|
|
333
334
|
|
|
334
335
|
**With an API key** (real usage):
|
|
335
336
|
```
|
|
336
|
-
|
|
337
|
+
๐ณ Credits
|
|
338
|
+
[โโโโโโโโโโโโโโโโโโโโ] 13.4% used ยท 936.7 / 7000 (6063.3 remaining)
|
|
339
|
+
Period: 2026-11-02 โ 2026-12-02 UTC
|
|
337
340
|
|
|
338
|
-
|
|
341
|
+
โฑ๏ธ Next billing reset: 2026-12-02 UTC (20d 16h 0m 0s)
|
|
339
342
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
MiMo V2.5:
|
|
349
|
-
[โโโโโโโโโโโโโโโโโโโโ] 12.5% of monthly cap
|
|
350
|
-
Used: 125.0M / 1.0B (875.0M remaining) ยท 840 requests
|
|
351
|
-
|
|
352
|
-
GLM 5.3:
|
|
353
|
-
[โโโโโโโโโโโโโโโโโโโโ] 40.0% of monthly cap
|
|
354
|
-
Used: 1.2B / 3.0B (1.8B remaining) ยท 2,400 requests
|
|
355
|
-
โณ rolling window: 400.0M / 4h (daily granularity โ /usage cannot break it down)
|
|
356
|
-
|
|
357
|
-
Uncapped models:
|
|
343
|
+
โก Usage
|
|
344
|
+
deepseek-v4-flash ยท 2701.1M in / 450.9M cached / 8.8M out ยท 189.7 (cr)
|
|
345
|
+
glm5.3-flash ยท 1619.6M in / 20.9M cached / 7.2M out ยท 621.4 (cr)
|
|
346
|
+
qwen3.6 ยท 1123.9M in / 37.1M cached / 3.3M out ยท 0 (cr)
|
|
347
|
+
mimo-v2.6-flash ยท 368.4M in / 67.4M cached / 3.3M out ยท 104.3 (cr)
|
|
348
|
+
qwen3.8-flash ยท 286.4M in / 0.0M cached / 1.3M out ยท 21.3 (cr)
|
|
349
|
+
qwen3-embedding ยท 4.6M in / 0.0M cached / 0.0M out ยท 0 (cr)
|
|
350
|
+
gemma4 ยท 1.0M in / 0.0M cached / 0.0M out ยท 0 (cr)
|
|
358
351
|
|
|
359
|
-
|
|
352
|
+
Total credits consumed: 936.7 (cr)
|
|
360
353
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
๐ก Source: GET /v1/usage ยท caps from https://nan.builders/docs/models
|
|
354
|
+
All time: 30.9B tokens ยท 125,915 requests (as of 2026-11-12)
|
|
355
|
+
๐ก Source: GET /v1/usage
|
|
364
356
|
```
|
|
365
357
|
|
|
358
|
+
- **๐ณ Credits**: progress bar showing `% used ยท used / allowance (remaining)`, billing period dates, pack credits with expiration if applicable, frozen-account warning.
|
|
359
|
+
- **โก Usage**: models sorted by credits consumed (primary billing metric), each row: `model ยท X.XM in / YM cached / Z.ZM out ยท W (cr)`.
|
|
360
|
+
- **All time**: lifetime totals with the last cache timestamp.
|
|
361
|
+
|
|
366
362
|
**Without an API key** (static limits only):
|
|
367
363
|
```
|
|
368
364
|
๐ NaN Quota Status (static limits)
|
|
@@ -442,18 +438,24 @@ Chat models:
|
|
|
442
438
|
| `mimo-v2.6-flash` | 1,048,576 | 131,072 | text, image | โ
|
|
|
443
439
|
| `glm5.3-flash` | 1,048,576 | 131,072 | text, image | โ
|
|
|
444
440
|
| `qwen3.8-flash` | 1,048,576 | 131,072 | text, image | โ
|
|
|
445
|
-
| `glm5.3` | 1,048,576 | 131,072 | text
|
|
446
|
-
| `
|
|
447
|
-
| `
|
|
448
|
-
| `
|
|
449
|
-
| `
|
|
441
|
+
| `glm5.3` | 1,048,576 | 131,072 | text | โ
|
|
|
442
|
+
| `hy4-flash` | 1,048,576 | 65,536 | text, image | โ
|
|
|
443
|
+
| `hy4` | 1,048,576 | 65,536 | text, image | โ
|
|
|
444
|
+
| `kimi-k3.1-pro` | 1,048,576 | 1,048,576 | text, image | โ
|
|
|
445
|
+
| `qwen3.8-max` | 1,000,000 | 131,072 | text, image | โ
|
|
|
446
|
+
| `qwen4-max` | 1,000,000 | 131,072 | text, image | โ
|
|
|
447
|
+
| `deepseek-v4-pro` | 1,048,576 | 393,216 | text | โ
|
|
|
450
448
|
|
|
451
449
|
> [!NOTE]
|
|
452
|
-
> Context windows above are the **documented**
|
|
450
|
+
> Context windows and max output above are the **documented** values from [the NaN docs](https://nan.builders/docs/models) (checked 2026-11-17), which are the source of truth; models.dev is a downstream mirror a human updates later and may lag. `glm5.3` was premium-only and live-only until NaN removed tier-exclusive models on 2026-11-10; it now ships in the static catalog, **text only** (an image, audio, video or file part โ or an earlier turn carrying one โ answers `400`, so start a new session or switch models).
|
|
451
|
+
>
|
|
452
|
+
> The **larger models** โ `kimi-k3.1-pro`, `qwen3.8-max`, `qwen4-max`, `deepseek-v4-pro`, `hy4`, `hy4-flash` โ are the ones NaN bills as "larger model" (they use credits faster). The four that entered the catalog on 2026-11-10 were carrying a flat 32,768 max output and no reasoning mapping because the docs did not document them yet; since 2026-11-17 each one declares its own "Max answer" and its documented reasoning behaviour. `qwen4-max` and `hy4-flash` are new ids the catalog did not have (models.dev provider `nan` lists neither; the live `/models` and the docs do). Maximum output is a ceiling, not a request: pi-ai clamps the outgoing budget to the room left in the context window (`clampMaxTokensToContext`), so a 1M-token ceiling on `kimi-k3.1-pro` never turns into an over-context `max_tokens`.
|
|
453
|
+
>
|
|
454
|
+
> `qwen3.8-max` sends `max_completion_tokens` instead of `max_tokens`, and `qwen3.8-flash` does the same: on those two the docs state that `max_tokens` bounds only the visible answer while the reasoning bills on top of it, so the client budget must cap the total (issue #34).
|
|
453
455
|
>
|
|
454
|
-
>
|
|
456
|
+
> Every catalog model reports **cost 0**: NaN bills a credit pool (1 credit โ 0.026 โฌ), not per-token USD, so pi's cost estimate has nothing to report. models.dev provider `nan` started publishing a derived USD conversion on 2026-11-17; the catalog does not adopt it, because pi would show that estimate as real money. Use `/nan-usage` for the real consumption.
|
|
455
457
|
>
|
|
456
|
-
> `*` deepseek-v4-flash max output 32,768 is the ceiling from the official NaN pi docs (https://nan.builders/docs/pi, "the same set the NaN CLI writes", issue #20, 2026-10-02); models.dev
|
|
458
|
+
> `*` deepseek-v4-flash max output 32,768 is the ceiling from the official NaN pi docs (https://nan.builders/docs/pi, "the same set the NaN CLI writes", issue #20, 2026-10-02); models.dev lists 384,000 but the gateway rejects `max_tokens` above ~256k with 403. `gemma4` keeps models.dev's 32,768: the docs' 65,536 in the pi/OpenCode blocks is described there as "a client-side budget rather than a server cap", so the smaller value stays rather than risking a `400`.
|
|
457
459
|
>
|
|
458
460
|
> **Cold prompt cache practical ceiling (issue #18).** The context windows above are the models' real windows, but the api.nan.builders edge (Cloudflare) aborts responses past its 120 s Proxy Read Timeout. Measured with direct cold requests (unique filler, no prompt cache; 2026-10-01): 208,036 tokens (~960 KB body) answered in 12.9 s while ~220k and ~286k tokens returned **HTTP 524 `origin_response_timeout`** at ~126 s; the same sizes with a warm prompt cache answer in ~10 s. The practical ceiling for cold requests is therefore well below the declared windows. Since 1.0.0 the provider reclassifies a 524 on an estimated over-200,000-token request (`NAN_COLD_CACHE_CEILING_TOKENS`) as a context overflow so pi compacts and retries instead of wedging; a 524 on a smaller request is left alone (genuine transient timeout).
|
|
459
461
|
|
|
@@ -480,15 +482,21 @@ NaN's `reasoning_effort` parameter controls how much the model thinks before ans
|
|
|
480
482
|
|
|
481
483
|
| Model | Reasoning effort | How it works |
|
|
482
484
|
| :--- | :--- | :--- |
|
|
483
|
-
| `glm5.3` | `low` ยท `medium` ยท `high` ยท `max` |
|
|
484
|
-
| `
|
|
485
|
-
| `
|
|
486
|
-
| `
|
|
487
|
-
| `
|
|
488
|
-
| `
|
|
489
|
-
| `
|
|
485
|
+
| `glm5.3`, `glm5.3-flash` | `minimal` ยท `low` ยท `medium` ยท `high` ยท `xhigh` ยท `max` | GLM cannot stop reasoning: the docs apply `none` as `minimal`, its shortest reasoning (a few tokens), so `thinking: "off"` sends `minimal` via the catalog's `thinkingLevelMap`. Higher values reason longer before answering. `glm5.3-flash` was measured at ~38 reasoning tokens for `minimal` (issue #16, 2026-09-27); `none` does not suppress it |
|
|
486
|
+
| `qwen3.6`, `gemma4` | `none` ยท `minimal` ยท `low` ยท `medium` ยท `high` ยท `xhigh` ยท `max` | `none`/`minimal` skip reasoning entirely; the others cap the reasoning phase at 2K / 8K / 16K / 32K tokens. `thinking: "off"` sends `reasoning_effort: "none"` automatically via the catalog's `thinkingLevelMap` โ the NaN docs state that with no parameter these models reason by default (16,384-token budget), so off must be explicit |
|
|
487
|
+
| `deepseek-v4-flash` | `none` ยท `minimal` ยท `low` ยท `medium` ยท `high` ยท `xhigh` ยท `max` | `none` disables reasoning (0 reasoning tokens, a full answer); every other value only steers it โ measured 57 reasoning tokens for `low`, 63 for omitting the parameter, 109 for `minimal` (issue #16, re-probed live 2026-10-14). `thinking: "off"` sends `reasoning_effort: "none"` via the catalog's `thinkingLevelMap` โ without it the model runs away to `finish_reason: "length"` with no answer |
|
|
488
|
+
| `qwen3.8-flash` | `none` ยท `minimal` ยท `low` ยท `medium` ยท `high` ยท `xhigh` ยท `max` | Reasoning is on by default (`none` turns it off, the rest steer its depth). `thinking: "off"` sends `reasoning_effort: "none"`; its budget is capped with `max_completion_tokens` (issue #34), and a hard reasoning cap is available through `thinking_budget` |
|
|
489
|
+
| `qwen4-max` | `none` ยท `minimal` ยท `low` ยท `medium` ยท `high` ยท `xhigh` ยท `max` | `none` turns reasoning off, `minimal` to `max` steer it, and `max_tokens` bounds reasoning **plus** answer. The docs advise setting a budget: an open-ended answer can run for many minutes |
|
|
490
|
+
| `mimo-v2.6-flash` | `none` ยท `low` ยท `medium` ยท `high` ยท `max` | `none` turns reasoning off (`minimal` is applied as `low`, `xhigh` as `max`, so those two are not declared separately); reasoning counts inside `max_tokens`. Measured live 2026-10-14: `none` gives 0 reasoning tokens with a full answer |
|
|
491
|
+
| `qwen3.8-max` | `none` | `none` turns reasoning off. `max_tokens` bounds only the visible answer, so the catalog sends `max_completion_tokens` to cap the total. A reasoning budget (`thinking_budget`) is not honoured on this model |
|
|
492
|
+
| `hy4` | `none` | Reasons by default โ the gateway applies `low` when the request names no level, and your own value always wins. `none` turns it off. `max_tokens` bounds reasoning plus answer |
|
|
493
|
+
| `hy4-flash` | `none` | Reasons by default with no default level; `reasoning_effort: "none"` turns it off (it ignores `enable_thinking`). `max_tokens` bounds reasoning plus answer, so a small one can come back empty |
|
|
494
|
+
| `kimi-k3.1-pro`, `deepseek-v4-pro` | *(no mapping declared)* | The docs keep these two out of the reasoning contract and state that the `none` aliases are **not mapped** on them, so the catalog declares no effort values and no `thinkingLevelMap`: `thinking: "off"` sends no parameter and the model decides |
|
|
495
|
+
|
|
496
|
+
> [!NOTE]
|
|
497
|
+
> **`xhigh` and `max` are opt-in in pi.** pi-ai only offers a model those two levels when its `thinkingLevelMap` declares them (`getSupportedThinkingLevels`; a request for either one is otherwise silently clamped to `high`). The catalog therefore carries identity entries (`xhigh: "xhigh"`, `max: "max"`) on every model whose docs declare a ladder up to `max` โ the seven chat models plus `mimo-v2.6-flash`, where the gateway applies `xhigh` as `max`. `hy4`, `hy4-flash` and `qwen3.8-max` document only their off switch, and `kimi-k3.1-pro`/`deepseek-v4-pro` sit outside the contract, so those five stay at `off`โฆ`high`.
|
|
490
498
|
> [!NOTE]
|
|
491
|
-
> `maxTokens` does NOT bound the reasoning phase on
|
|
499
|
+
> `maxTokens` does NOT bound the reasoning phase on `deepseek-v4-flash`, `glm5.3`, `glm5.3-flash`, `qwen3.8-flash`, `mimo-v2.6-flash`, `qwen3.8-max` or `kimi-k3.1-pro`. The reasoning phase runs to completion (or is cut at NaN's reasoning-only stream limit: 45,000 reasoning characters, or 420 s without visible output) regardless of the budget โ measured: `max_tokens=512` on deepseek-v4-flash still consumed 13,376 completion tokens, all reasoning (26x the ceiling). This is gateway behavior confirmed by issue #16 (measured 2026-09-27) and by NaN for `qwen3.8-flash` (issue #34, 2026-11-11 โ the excess also bills against the quota). The 2026-11-17 docs add the models where the budget **does** bound the total, reasoning plus answer: `qwen4-max` (up to 131,000), `hy4-flash` and `hy4` (up to 64,000), and `mimo-v2.6-flash`. As an interim bound for `qwen3.8-flash` **and `qwen3.8-max`** the catalog sends `max_completion_tokens` instead, which NaN confirmed IS respected; it survives because those models' compat opts out of the schema sanitizer's rename to `max_tokens` (the published OpenAPI schema still documents only `max_tokens`). Remove those overrides once NaN ships their gateway fix โ `test/issue-34-max-completion-tokens.test.ts` is the tripwire. Reasoning alone can still consume the whole budget and end the turn with empty content; that closure carries NaN's `reasoning_only_stream` marker and pi-ai retries the turn (issue #21).
|
|
492
500
|
|
|
493
501
|
|
|
494
502
|
---
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gtrabanco/pi-nan-provider",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.6",
|
|
4
4
|
"description": "NaN Builders (api.nan.builders) model provider for pi - OpenAI-compatible registration with a models.dev-generated fallback, tier-aware live catalog, and an optional community media MCP bridge",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi",
|
|
@@ -37,27 +37,7 @@
|
|
|
37
37
|
import type { GeneratedModelEntry } from "../src/fetch-models.ts";
|
|
38
38
|
import { NON_CHAT_MODEL_IDS } from "../src/fetch-models.ts";
|
|
39
39
|
import type { ManualModelOverride } from "./manual-overrides.ts";
|
|
40
|
-
import {
|
|
41
|
-
MANUAL_OVERRIDES,
|
|
42
|
-
MANUAL_ONLY_MODEL_IDS,
|
|
43
|
-
REASONING_EFFORT_VALUES,
|
|
44
|
-
} from "./manual-overrides.ts";
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Reasoning effort values sourced from the NaN docs (https://nan.builders/docs/models
|
|
48
|
-
* #controlling-reasoning, checked 2026-09-25). models.dev has no reasoning_effort_values
|
|
49
|
-
* field โ only reasoning_options which is [{type:"toggle"}] or [] โ so the actual
|
|
50
|
-
* effort levels must be hand-maintained from the docs. An empty array means the
|
|
51
|
-
* parameter is accepted but depth is not adjustable by the user.
|
|
52
|
-
*/
|
|
53
|
-
const REASONING_EFFORT_VALUES_FROM_DOCS: Record<string, string[]> = {
|
|
54
|
-
...REASONING_EFFORT_VALUES,
|
|
55
|
-
// deepseek-v4-flash: any value (no effect) โ model decides per request
|
|
56
|
-
"deepseek-v4-flash": [],
|
|
57
|
-
// qwen3.8-flash, mimo-v2.6-flash: accepted, depth not adjustable
|
|
58
|
-
"qwen3.8-flash": [],
|
|
59
|
-
"mimo-v2.6-flash": [],
|
|
60
|
-
};
|
|
40
|
+
import { MANUAL_OVERRIDES, MANUAL_ONLY_MODEL_IDS } from "./manual-overrides.ts";
|
|
61
41
|
|
|
62
42
|
const MODELS_DEV_API_URL = "https://models.dev/api.json";
|
|
63
43
|
const SOURCE_PROVIDER_ID = "nan";
|
|
@@ -150,6 +130,22 @@ const NAN_COMPAT = {
|
|
|
150
130
|
maxTokensField: "max_tokens" as "max_tokens" | "max_completion_tokens",
|
|
151
131
|
};
|
|
152
132
|
|
|
133
|
+
/**
|
|
134
|
+
* Catalog cost for every chat model: zero, by maintainer decision. NaN bills a
|
|
135
|
+
* credit pool (1 credit โ 0.026 โฌ) and not per-token USD, so pi's per-token
|
|
136
|
+
* cost estimate has nothing to report here. models.dev provider "nan" started
|
|
137
|
+
* publishing a DERIVED USD conversion on 2026-11-17 (deepseek-v4-flash
|
|
138
|
+
* 0.29484 / 1.17936, glm5.3 1.37592 / 4.32432, โฆ) which is not a price NaN
|
|
139
|
+
* charges; adopting it would make pi display an estimate as real money for a
|
|
140
|
+
* credit-based gateway. A model with a confirmed per-token price can still
|
|
141
|
+
* override it through MANUAL_OVERRIDES.cost; to adopt models.dev's numbers for
|
|
142
|
+
* everything, delete this constant and read `m.cost` in convertModel.
|
|
143
|
+
*/
|
|
144
|
+
const NAN_CATALOG_COST = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 } as const;
|
|
145
|
+
|
|
146
|
+
const NAN_COST_NOTE =
|
|
147
|
+
"cost 0 on every model: NaN bills a credit pool (1 credit โ 0.026 โฌ) rather than per-token USD, so pi's per-token cost estimate does not apply. models.dev provider nan started publishing a derived USD conversion on 2026-11-17; it is not a price NaN charges, so it is not adopted (delete NAN_CATALOG_COST in scripts/generate-models.ts to adopt it).";
|
|
148
|
+
|
|
153
149
|
const NAN_COMPAT_NOTE =
|
|
154
150
|
"compat matches the maintainer's working ~/.pi/agent/models.json LiteLLM config for api.nan.builders (2026-09-04): supportsDeveloperRole false, supportsReasoningEffort true, maxTokensField max_tokens. NaN's docs example sets only supportsDeveloperRole: true and is not battle-tested. supportsFinishReason true (2026-09-13, issue #2): the LiteLLM gateway intermittently closes SSE streams before emitting finish_reason; with true pi-ai raises 'Stream ended without finish_reason', which matches pi-ai's retryable-provider pattern ('ended without') and is retried automatically, whereas false silently synthesized stop/toolUse and stalled the turn mid-answer. supportsUsageInStreaming true (2026-09-16, issue #7): NaN's published schema is silent about stream_options, but the live gateway honors it โ two identical streaming calls per model, differing only in stream_options: { include_usage: true }, returned 0 usage chunks without it and exactly 1 with it (prompt/completion/reasoning/cached token counts) on deepseek-v4-flash, glm5.3-flash, qwen3.6, mimo-v2.5 and gemma4, and a real pi session then recorded token counts where it recorded zeros. pi-ai only sends stream_options when this is not false, and the sanitizer forwards it when the model declares true, so chat models opt in by default and usage is reported (issue #4). A model that does not report streaming usage can still opt out per model with a models.json compat override (supportsUsageInStreaming: false); the sanitizer then strips stream_options and the payload stays strict.";
|
|
155
151
|
|
|
@@ -216,10 +212,7 @@ function buildManualOnlyModelEntry(
|
|
|
216
212
|
detail: string,
|
|
217
213
|
override: ManualModelOverride | undefined,
|
|
218
214
|
): GeneratedModel {
|
|
219
|
-
const reasoningEffortValues =
|
|
220
|
-
override?.reasoningEffortValues ??
|
|
221
|
-
REASONING_EFFORT_VALUES_FROM_DOCS[modelId] ??
|
|
222
|
-
undefined;
|
|
215
|
+
const reasoningEffortValues = override?.reasoningEffortValues ?? undefined;
|
|
223
216
|
|
|
224
217
|
return {
|
|
225
218
|
entry: {
|
|
@@ -227,7 +220,7 @@ function buildManualOnlyModelEntry(
|
|
|
227
220
|
name: override?.name ?? modelId,
|
|
228
221
|
reasoning: override?.reasoning ?? true,
|
|
229
222
|
input: override?.input ?? ["text", "image"],
|
|
230
|
-
cost: override?.cost ?? {
|
|
223
|
+
cost: override?.cost ?? { ...NAN_CATALOG_COST },
|
|
231
224
|
contextWindow: override?.contextWindow ?? 1_048_576,
|
|
232
225
|
maxTokens: override?.maxTokens ?? 131_072,
|
|
233
226
|
reasoningEffortValues,
|
|
@@ -235,6 +228,7 @@ function buildManualOnlyModelEntry(
|
|
|
235
228
|
compat: buildCompat(override),
|
|
236
229
|
notes: [
|
|
237
230
|
NAN_COMPAT_NOTE,
|
|
231
|
+
NAN_COST_NOTE,
|
|
238
232
|
`manual-only: "${modelId}" not yet on models.dev provider nan (${detail}).`,
|
|
239
233
|
...(override ? [override.note] : []),
|
|
240
234
|
],
|
|
@@ -270,11 +264,11 @@ function convertModel(modelId: string, m: ModelsDevModel): GeneratedModel | { sk
|
|
|
270
264
|
}
|
|
271
265
|
|
|
272
266
|
// Reasoning effort values sourced from the NaN docs (models.dev does not
|
|
273
|
-
// expose them โ only reasoning_options: [{type:"toggle"}] or []).
|
|
274
|
-
//
|
|
275
|
-
//
|
|
276
|
-
|
|
277
|
-
|
|
267
|
+
// expose them โ only reasoning_options: [{type:"toggle"}] or []). They live
|
|
268
|
+
// on MANUAL_OVERRIDES next to their provenance note: one source, no fallback
|
|
269
|
+
// map in this generator. An empty array means the parameter is accepted but
|
|
270
|
+
// depth is not adjustable by the user; the model manages its own reasoning.
|
|
271
|
+
const reasoningEffortValues = override?.reasoningEffortValues ?? undefined;
|
|
278
272
|
|
|
279
273
|
return {
|
|
280
274
|
entry: {
|
|
@@ -282,12 +276,7 @@ function convertModel(modelId: string, m: ModelsDevModel): GeneratedModel | { sk
|
|
|
282
276
|
name: override?.name ?? m.name ?? modelId,
|
|
283
277
|
reasoning: override?.reasoning ?? m.reasoning === true,
|
|
284
278
|
input,
|
|
285
|
-
cost: override?.cost ?? {
|
|
286
|
-
input: m.cost?.input ?? 0,
|
|
287
|
-
output: m.cost?.output ?? 0,
|
|
288
|
-
cacheRead: m.cost?.cache_read ?? 0,
|
|
289
|
-
cacheWrite: m.cost?.cache_write ?? 0,
|
|
290
|
-
},
|
|
279
|
+
cost: override?.cost ?? { ...NAN_CATALOG_COST },
|
|
291
280
|
contextWindow: override?.contextWindow ?? contextWindow,
|
|
292
281
|
maxTokens: override?.maxTokens ?? maxTokens,
|
|
293
282
|
reasoningEffortValues,
|
|
@@ -295,6 +284,7 @@ function convertModel(modelId: string, m: ModelsDevModel): GeneratedModel | { sk
|
|
|
295
284
|
compat: buildCompat(override),
|
|
296
285
|
notes: [
|
|
297
286
|
NAN_COMPAT_NOTE,
|
|
287
|
+
NAN_COST_NOTE,
|
|
298
288
|
...(override ? [override.note] : []),
|
|
299
289
|
...(MANUAL_NOTES[modelId] ? [MANUAL_NOTES[modelId]!] : []),
|
|
300
290
|
],
|