@gtrabanco/pi-nan-provider 1.5.5 → 1.5.7
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 +57 -28
- package/README.es.md +38 -23
- package/README.md +37 -22
- package/package.json +1 -1
- package/scripts/generate-models.ts +27 -37
- package/scripts/manual-overrides.ts +168 -121
- package/scripts/models.generated.ts +217 -68
- package/src/openai-compat-sanitizer.ts +10 -9
- package/src/provider-factory.ts +6 -4
package/AGENTS.md
CHANGED
|
@@ -206,45 +206,62 @@ Since 1.0.0 the package version **aligns its MAJOR.MINOR with the pi release lin
|
|
|
206
206
|
truth (maintainer instruction, reaffirmed 2026-09-29), cross-checked against
|
|
207
207
|
the `model` param description in https://nan.builders/openapi.json, plus
|
|
208
208
|
(since 2026-11-10) the live `GET /v1/models` for models NaN launches before
|
|
209
|
-
the docs catch up (see "
|
|
209
|
+
the docs catch up (see "Larger models" below). The original
|
|
210
210
|
seven documented chat models declare 1M-token windows where the docs say so —
|
|
211
211
|
`deepseek-v4-flash`, `glm5.3-flash`, `qwen3.8-flash` and `mimo-v2.6-flash` at
|
|
212
212
|
**1,048,576**, `qwen3.6` and `gemma4` at **262,144** — and the first three
|
|
213
213
|
carry a `MANUAL_OVERRIDES.contextWindow` because models.dev lagged (rounded
|
|
214
214
|
1,000,000 for the first two, stale 262,144 for `qwen3.8-flash`; docs checked
|
|
215
215
|
2026-10-14).
|
|
216
|
-
Official chat models (checked 2026-
|
|
216
|
+
Official chat models (checked 2026-11-17): community `deepseek-v4-flash`,
|
|
217
217
|
`mimo-v2.6-flash`, `qwen3.8-flash`, `glm5.3-flash`, `qwen3.6`, `gemma4`
|
|
218
|
-
(all text+image vision) + `glm5.3`
|
|
219
|
-
|
|
218
|
+
(all text+image vision) + `glm5.3` (~753B MoE, **text only** since the
|
|
219
|
+
2026-11-17 docs — an image, audio, video or file part answers 400, earlier
|
|
220
|
+
turns included; the old card said multimodal, models.dev now says text-only).
|
|
220
221
|
**glm5.3 is a general catalog model since 2026-11-10** (NaN announced "a
|
|
221
222
|
partir de ahora ya NO habrá modelos exclusivos por tier"; the live
|
|
222
223
|
`GET /v1/models` lists it for a non-premium key, checked 2026-11-10). It was
|
|
223
224
|
premium live-only before (`LIVE_ONLY_MODEL_IDS` in the generator and
|
|
224
225
|
`LIVE_ONLY_MODEL_DATA` in `src/fetch-models.ts`); both were REMOVED in
|
|
225
226
|
package 1.5.1 as dead code once nothing was tier-gated. Its values live in
|
|
226
|
-
`MANUAL_OVERRIDES["glm5.3"]` (1,048,576 / 131,072, text
|
|
227
|
-
reasoningEffortValues low/medium/high/max,
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
`
|
|
238
|
-
`
|
|
239
|
-
(`EXTERNAL_MODELS`), each with a provenance
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
227
|
+
`MANUAL_OVERRIDES["glm5.3"]` (1,048,576 / 131,072, **text only**,
|
|
228
|
+
reasoningEffortValues minimal/low/medium/high/xhigh/max,
|
|
229
|
+
`thinkingLevelMap { off: "minimal" }` — GLM cannot stop reasoning and the
|
|
230
|
+
docs apply `none` as `minimal`, name "GLM 5.3") over the models.dev entry
|
|
231
|
+
(text-only, 1,000,000). The overlay/merge paths now treat it like any
|
|
232
|
+
catalogued id (issue #19's invariant is intact: the store decides which ids
|
|
233
|
+
exist, the generated catalog decides their capabilities). `src/usage.ts` no
|
|
234
|
+
longer has a `premium` flag (removed in 1.5.1 at the maintainer's request);
|
|
235
|
+
its token windows are a known follow-up, NaN moved to credits.
|
|
236
|
+
**Larger models — six, all documented since 2026-11-17** (the docs' own
|
|
237
|
+
label; NaN bills them as "larger model" because they use credits faster):
|
|
238
|
+
`kimi-k3.1-pro`, `qwen3.8-max`, `qwen4-max`, `deepseek-v4-pro`, `hy4`,
|
|
239
|
+
`hy4-flash`. They live in `scripts/manual-overrides.ts` as `LARGER_MODELS`
|
|
240
|
+
(renamed from `EXTERNAL_MODELS` in package 1.5.6), each with a provenance
|
|
241
|
+
note citing https://nan.builders/docs/models (checked 2026-11-17):
|
|
242
|
+
contextWindow 1,048,576 per NaN's 1M convention except the two Alibaba
|
|
243
|
+
flagships (1,000,000, the first-party vendor value); maxTokens from the
|
|
244
|
+
card's "Max answer" (kimi 1,048,576, deepseek-v4-pro 393,216, hy4 and
|
|
245
|
+
hy4-flash 65,536, qwen3.8-max 131,072, qwen4-max 131,072) — pi-ai clamps the
|
|
246
|
+
outgoing budget to the context room (`clampMaxTokensToContext`), so a large
|
|
247
|
+
documented ceiling never becomes an over-context request; input from the
|
|
248
|
+
card (`deepseek-v4-pro` is text-only); reasoning true; cost 0 (maintainer
|
|
249
|
+
decision). `qwen4-max` and `hy4-flash` are the two ids the catalog never had
|
|
250
|
+
— models.dev provider `nan` lists neither, so they enter through
|
|
251
|
+
`MANUAL_ONLY_MODEL_IDS`; the other four are models.dev entries corrected by
|
|
252
|
+
the overrides. Reasoning: the docs keep `kimi-k3.1-pro` and
|
|
253
|
+
`deepseek-v4-pro` out of the contract and state their `none` aliases are NOT
|
|
254
|
+
mapped, so they declare no effort values and no `thinkingLevelMap`;
|
|
255
|
+
`qwen3.8-max` gets `maxTokensField: "max_completion_tokens"` because its
|
|
256
|
+
`max_tokens` bounds only the visible answer (issue #34's quota failure
|
|
257
|
+
mode); `qwen3.8-flash` used the same interim field from #34 until NaN support
|
|
258
|
+
confirmed the deployed `max_tokens` fix on 2026-11-17, when #36 reverted it
|
|
259
|
+
(package 1.5.7) — do not reintroduce it without a new measurement;
|
|
260
|
+
`qwen4-max`, `qwen3.8-flash`, `hy4`, `hy4-flash` and `qwen3.8-max`
|
|
261
|
+
map `off` to `none`; `hy4` reasons by default with the gateway applying
|
|
262
|
+
`low` when no level is sent.
|
|
263
|
+
When the docs or models.dev change, re-verify the values (docs win; a
|
|
264
|
+
measurement wins over the docs).
|
|
248
265
|
Removed by the provider: `glm5.2` (2026-09-05) and `mimo-v2.5` (checked
|
|
249
266
|
2026-09-29 — zero mentions in the docs and in openapi.json, and models.dev
|
|
250
267
|
dropped it too; superseded by `mimo-v2.6-flash`). models.dev may re-list a
|
|
@@ -290,7 +307,16 @@ Since 1.0.0 the package version **aligns its MAJOR.MINOR with the pi release lin
|
|
|
290
307
|
`test/issue-2-truncated-stream.test.ts`, `test/issue-4-token-usage.test.ts`,
|
|
291
308
|
`test/issue-7-streaming-usage-default.test.ts`;
|
|
292
309
|
issues #2, #4 and #7.
|
|
293
|
-
- **
|
|
310
|
+
- **The catalog declares `thinkingLevelMap` for reasoning suppression** (issue #16, measured 2026-09-27 against live gateway, repro script in the issue; extended 2026-11-17 from the docs for every model they now document). `deepseek-v4-flash` → `{ off: "none" }` (0 reasoning tokens, reproducible); `glm5.3-flash` and `glm5.3` → `{ off: "minimal" }` (38 reasoning tokens + answer; `none` does NOT work on glm5.3-flash — 13,382 tokens — and the docs state GLM always reasons, so `none` is applied as `minimal`); `qwen3.6`, `gemma4`, `qwen3.8-flash`, `qwen4-max`, `qwen3.8-max`, `hy4`, `hy4-flash` → `{ off: "none" }` (the NaN docs state that with no parameter these models reason by default and that `none` turns reasoning off — https://nan.builders/docs/models#controlling-reasoning, checked 2026-11-17 — so `off` must send `none` explicitly). `kimi-k3.1-pro` and `deepseek-v4-pro` declare NO map: the docs keep them out of the reasoning contract and state their `none` aliases are not mapped, so `off` sends nothing and the model decides. pi-ai's `buildRequest` maps `reasoning: "off"` → `reasoningEffort: undefined` → fires the off-branch that checks `model.thinkingLevelMap?.off` (verified in pi-ai 1.5.1, `api/openai-completions.js` ~line 715). `reasoningEffortValues` is catalog documentation only — pi and pi-ai never read it (`rg reasoningEffortValues node_modules/@earendil-works` → no match on 1.5.1) — and it now lives in ONE place, each model's `MANUAL_OVERRIDES` entry, with no fallback map in the generator. Ladders follow the docs: `deepseek-v4-flash` `none`+minimal…max (the measured fact that only `none` *suppresses* is unchanged and still drives its off map), `mimo-v2.6-flash` `none`/low…max (`minimal` is applied as `low`, `xhigh` as `max`), GLM and the two new models include `xhigh`. `xhigh` and `max` are opt-in in pi-ai: `getSupportedThinkingLevels` only lists them when the map carries a non-null entry for that level, and `clampThinkingLevel` silently degrades a request for either one to `high` otherwise (pi-ai 1.5.1 `dist/models.js:701-713`; its README says both "are opt-in and require a non-null map entry"). NaN accepts both, so every model whose docs declare a ladder up to `max` now carries identity entries `{ xhigh: "xhigh", max: "max" }` — `deepseek-v4-flash`, `gemma4`, `qwen3.6`, `glm5.3`, `glm5.3-flash`, `qwen3.8-flash`, `qwen4-max`, `mimo-v2.6-flash` (the gateway applies `xhigh` as `max` there) — while `hy4`, `hy4-flash` and `qwen3.8-max` (docs document only the off switch) and `kimi-k3.1-pro`/`deepseek-v4-pro` (outside the contract) keep `off` alone and stay at `off`…`high`. Verified end to end: before the entries a `max` request reached the gateway as `reasoning_effort: "high"`; now it reaches it as `"max"`. The README limits table records which models' `maxTokens` DOES bound reasoning plus answer (`qwen4-max`, `hy4`, `hy4-flash`, `mimo-v2.6-flash` per the 2026-11-17 docs) versus the measured case where it does not (max_tokens=512 on deepseek-v4-flash still yielded 13,376 reasoning tokens).
|
|
311
|
+
- **Catalog cost is pinned to 0** (generator constant `NAN_CATALOG_COST`, recorded
|
|
312
|
+
in `GENERATED_CATALOG_META.notes`). NaN bills a credit pool (1 credit ≈ 0.026 €),
|
|
313
|
+
not per-token USD, so pi's per-token cost estimate has nothing to report. models.dev
|
|
314
|
+
provider `nan` started publishing a DERIVED USD conversion on 2026-11-17
|
|
315
|
+
(deepseek-v4-flash 0.29484 / 1.17936, glm5.3 1.37592 / 4.32432, …), which is not a
|
|
316
|
+
price NaN charges; adopting it would make pi display that estimate as real money.
|
|
317
|
+
A model with a confirmed per-token price can still override `cost` through
|
|
318
|
+
`MANUAL_OVERRIDES`; to adopt models.dev's numbers everywhere, delete the constant.
|
|
319
|
+
Regression test: `test/larger-models-2026-11-17.test.ts`.
|
|
294
320
|
- A NaN request that still exceeds the destination model's context window (the
|
|
295
321
|
cross-model thinking guard is disabled with `NAN_THINKING_GUARD=0`, the
|
|
296
322
|
inflation is not a `thinking` block, or the window is smaller) gets NaN's
|
|
@@ -500,7 +526,10 @@ Since 1.0.0 the package version **aligns its MAJOR.MINOR with the pi release lin
|
|
|
500
526
|
provider-side: the store write path belongs to pi-ai.
|
|
501
527
|
|
|
502
528
|
- **Cache-anomaly evidence + `/nan-debug` (issue #35, verified 2026-11-11 on
|
|
503
|
-
pi-ai 1.5.1
|
|
529
|
+
pi-ai 1.5.1; the upstream cache was disabled 2026-11-17):** NaN support
|
|
530
|
+
confirmed the proxy response cache is off — two identical requests now return
|
|
531
|
+
two real completions, each with its own usage — so the #17 replay is fixed.
|
|
532
|
+
The capture below stays as a relapse tripwire. pi-ai's `StreamOptions.onResponse(response, model)` is the
|
|
504
533
|
only response-header surface (`ProviderResponse = { status, headers }`,
|
|
505
534
|
called by openai-completions right after the HTTP response). The gateway
|
|
506
535
|
`id`/`created` pair comes from raw `onProviderStreamEvent` chunks: pi-ai copies
|
package/README.es.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 + MCP nativo para [pi](https://github.com/earendil-works/pi).
|
|
@@ -22,7 +22,7 @@ Registra el proveedor `nan` vía `pi.registerProvider()` usando la API OpenAI-co
|
|
|
22
22
|
| **Rescate de desbordamiento de contexto** | El `400 Invalid request` genérico de NaN se reclasifica como desbordamiento cuando la petición se estima por encima de la ventana del modelo ([#3](https://github.com/gtrabanco/pi-nan-provider/issues/3)), y un `524` de caché fría por encima de `NAN_COLD_CACHE_CEILING_TOKENS` también ([#18](https://github.com/gtrabanco/pi-nan-provider/issues/18)) — pi compacta y reintenta en vez de quedarse colgado. |
|
|
23
23
|
| **Reintento de streams truncados** | `supportsFinishReason: true` convierte un stream SSE cerrado antes de `finish_reason` en un error reintentable en vez de un stall silencioso ([#2](https://github.com/gtrabanco/pi-nan-provider/issues/2)). |
|
|
24
24
|
| **Uso de tokens en streaming** | `stream_options.include_usage` activo por defecto, así que pi reporta recuentos reales de entrada/salida/razonamiento/caché ([#4](https://github.com/gtrabanco/pi-nan-provider/issues/4), [#7](https://github.com/gtrabanco/pi-nan-provider/issues/7)). |
|
|
25
|
-
| **Controles de razonamiento** | `reasoningEffortValues` + `thinkingLevelMap` por modelo ([#16](https://github.com/gtrabanco/pi-nan-provider/issues/16)), el guard de stream solo-razonamiento ([#21](https://github.com/gtrabanco/pi-nan-provider/issues/21)) y el
|
|
25
|
+
| **Controles de razonamiento** | `reasoningEffortValues` + `thinkingLevelMap` por modelo ([#16](https://github.com/gtrabanco/pi-nan-provider/issues/16)), el guard de stream solo-razonamiento ([#21](https://github.com/gtrabanco/pi-nan-provider/issues/21)) y el campo de tokens máximo por modelo (`qwen3.8-max` mantiene `max_completion_tokens`; `qwen3.8-flash` volvió a `max_tokens` tras el arreglo del gateway de NaN, [#34](https://github.com/gtrabanco/pi-nan-provider/issues/34) → [#36](https://github.com/gtrabanco/pi-nan-provider/issues/36)). |
|
|
26
26
|
| **Cabecera de atribución** | `X-Pi-Provider: gtrabanco/pi-nan-provider@<version>` en cada petición, eliminada cuando la telemetría de instalación de pi está desactivada. |
|
|
27
27
|
| **Modelos de imagen nativos** | `flux-2-klein` y `qwen-image-2.1` registrados como modelos de pi `type: "image"`, accesibles desde codemode y extensiones. |
|
|
28
28
|
| **Puente MCP nativo de media** | El servidor `nan-media` (10 herramientas) registrado con `pi.registerMcpServer()`, gestionado con `/nan-mcp`. |
|
|
@@ -84,7 +84,7 @@ NaN responde HTTP 400 `Invalid request. Check your request parameters.` con cual
|
|
|
84
84
|
- un array `content` de asistente que lleva una tool call se mueve al campo superior `tool_calls` (el `ContentPart` de NaN solo acepta `text` y `image_url`);
|
|
85
85
|
- se elimina `reasoning_details`, y las partes de contenido desconocidas (p. ej. `thinking`) se pliegan en una parte `text` para que el razonamiento no se pierda en silencio;
|
|
86
86
|
- se eliminan los campos que el esquema de NaN no lista: `store` siempre, un array `tools` vacío siempre, y `stream_options` salvo que `compat.supportsUsageInStreaming` del modelo diga que el gateway lo reporta;
|
|
87
|
-
- `max_completion_tokens` se renombra a `max_tokens` (el campo documentado) salvo que `compat.maxTokensField` del modelo lo desactive ([#34](https://github.com/gtrabanco/pi-nan-provider/issues/34)
|
|
87
|
+
- `max_completion_tokens` se renombra a `max_tokens` (el campo documentado) salvo que `compat.maxTokensField` del modelo lo desactive ([#34](https://github.com/gtrabanco/pi-nan-provider/issues/34); `qwen3.8-max` es el único modelo del catálogo que lo desactiva tras la reversión del [#36](https://github.com/gtrabanco/pi-nan-provider/issues/36)).
|
|
88
88
|
|
|
89
89
|
Un hook `onPayload` suministrado por el llamante se conserva y se encadena después de la sanitización.
|
|
90
90
|
|
|
@@ -388,9 +388,12 @@ Los errores siguen siendo accionables: `401` → ejecuta `/login nan` o corrige
|
|
|
388
388
|
|
|
389
389
|
## 🧾 Evidencia de anomalías de caché: `/nan-debug`
|
|
390
390
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
391
|
+
NaN desactivó la caché de respuestas del proxy el 2026-11-17 (confirmado por
|
|
392
|
+
soporte): dos peticiones idénticas devuelven ahora dos respuestas reales, cada
|
|
393
|
+
una con su propio usage. La caché antigua podía repetir el mismo `id` y `created`
|
|
394
|
+
en peticiones seguidas (la firma del issue #17). La captura se queda como
|
|
395
|
+
tripwire de recaída; NaN pidió el `model` y el `cf-ray` de un par de llamadas si
|
|
396
|
+
vuelve a pasar, y los transcripts de pi no
|
|
394
397
|
guardan cabeceras de respuesta, así que el proveedor las captura.
|
|
395
398
|
|
|
396
399
|
Cuando dos streams del mismo modelo devuelven el mismo `id` + `created`, se
|
|
@@ -442,17 +445,23 @@ Modelos de chat:
|
|
|
442
445
|
| `mimo-v2.6-flash` | 1,048,576 | 131,072 | texto, imagen | ✅ |
|
|
443
446
|
| `glm5.3-flash` | 1,048,576 | 131,072 | texto, imagen | ✅ |
|
|
444
447
|
| `qwen3.8-flash` | 1,048,576 | 131,072 | texto, imagen | ✅ |
|
|
445
|
-
| `glm5.3` | 1,048,576 | 131,072 | texto
|
|
446
|
-
| `
|
|
447
|
-
| `
|
|
448
|
-
| `
|
|
449
|
-
| `
|
|
450
|
-
|
|
451
|
-
|
|
448
|
+
| `glm5.3` | 1,048,576 | 131,072 | texto | ✅ |
|
|
449
|
+
| `hy4-flash` | 1,048,576 | 65,536 | texto, imagen | ✅ |
|
|
450
|
+
| `hy4` | 1,048,576 | 65,536 | texto, imagen | ✅ |
|
|
451
|
+
| `kimi-k3.1-pro` | 1,048,576 | 1,048,576 | texto, imagen | ✅ |
|
|
452
|
+
| `qwen3.8-max` | 1,000,000 | 131,072 | texto, imagen | ✅ |
|
|
453
|
+
| `qwen4-max` | 1,000,000 | 131,072 | texto, imagen | ✅ |
|
|
454
|
+
| `deepseek-v4-pro` | 1,048,576 | 393,216 | texto | ✅ |
|
|
455
|
+
|
|
456
|
+
> Las ventanas de contexto y la salida máxima de la tabla son los valores **documentados** en [los docs de NaN](https://nan.builders/docs/models) (comprobado 2026-11-17), que son la fuente de verdad; models.dev es un espejo que un humano actualiza más tarde y puede ir por detrás. `glm5.3` fue solo-premium y solo-en-vivo hasta que NaN eliminó los modelos exclusivos por tier el 2026-11-10; ahora está en el catálogo estático, **solo texto** (una imagen, audio, vídeo o fichero — o un turno anterior que lleve uno — responde `400`, así que empieza sesión nueva o cambia de modelo).
|
|
457
|
+
>
|
|
458
|
+
> Los **modelos grandes** — `kimi-k3.1-pro`, `qwen3.8-max`, `qwen4-max`, `deepseek-v4-pro`, `hy4`, `hy4-flash` — son los que NaN factura como "larger model" (gastan créditos más rápido). Los cuatro que entraron en el catálogo el 2026-11-10 llevaban una salida máxima plana de 32,768 y ningún mapeo de razonamiento porque los docs aún no los documentaban; desde el 2026-11-17 cada uno declara su propio "Max answer" y su comportamiento de razonamiento documentado. `qwen4-max` y `hy4-flash` son ids nuevos que el catálogo no tenía (models.dev, proveedor `nan`, no lista ninguno de los dos; el `/models` en vivo y los docs sí). La salida máxima es un techo, no una petición: pi-ai recorta el presupuesto saliente al hueco que queda en la ventana de contexto (`clampMaxTokensToContext`), así que un techo de 1M tokens en `kimi-k3.1-pro` nunca se convierte en un `max_tokens` fuera de contexto.
|
|
459
|
+
>
|
|
460
|
+
> `qwen3.8-max` envía `max_completion_tokens` en vez de `max_tokens`: sus docs dicen que `max_tokens` solo limita la respuesta visible y el razonamiento se factura por encima, así que el presupuesto del cliente debe cubrir el total (docs del 2026-11-17). `qwen3.8-flash` usó el mismo campo provisional después de que NaN confirmara el comportamiento el 2026-11-11 ([#34](https://github.com/gtrabanco/pi-nan-provider/issues/34)); el soporte de NaN confirmó el 2026-11-17 que el arreglo del gateway está desplegado y validado, así que [#36](https://github.com/gtrabanco/pi-nan-provider/issues/36) retiró ese override y vuelve a enviar el `max_tokens` clásico (la página de docs aún arrastra la frase antigua; manda el comportamiento del gateway confirmado por soporte).
|
|
452
461
|
>
|
|
453
|
-
>
|
|
462
|
+
> Todos los modelos del catálogo reportan **coste 0**: NaN factura un pool de créditos (1 crédito ≈ 0,026 €), no USD por token, así que la estimación de coste de pi no tiene nada que reportar. models.dev, proveedor `nan`, empezó a publicar una conversión derivada a USD el 2026-11-17; el catálogo no la adopta, porque pi la mostraría como dinero real. Usa `/nan-usage` para el consumo real.
|
|
454
463
|
>
|
|
455
|
-
> `*` El límite de salida de 32,768 en `deepseek-v4-flash` es el techo de los docs oficiales de NaN para pi (https://nan.builders/docs/pi, "the same set the NaN CLI writes", issue #20, 2026-10-02); models.dev
|
|
464
|
+
> `*` El límite de salida de 32,768 en `deepseek-v4-flash` es el techo de los docs oficiales de NaN para pi (https://nan.builders/docs/pi, "the same set the NaN CLI writes", issue #20, 2026-10-02); models.dev lista 384,000, pero la pasarela rechaza `max_tokens` por encima de ~256k con 403. `gemma4` se queda con los 32,768 de models.dev: los 65,536 de los bloques de pi/OpenCode están descritos ahí como "a client-side budget rather than a server cap", así que se mantiene el valor menor en vez de arriesgar un `400`.
|
|
456
465
|
|
|
457
466
|
> [!NOTE]
|
|
458
467
|
> **Techo práctico con caché de prompt fría (issue #18).** Las ventanas de contexto de la tabla son las ventanas reales de los modelos, pero el borde de api.nan.builders (Cloudflare) aborta las respuestas que superan su Proxy Read Timeout de 120 s. Medido con peticiones frías directas (relleno único, sin caché de prompt; 2026-10-01): 208.036 tokens (~960 KB de cuerpo) respondió en 12,9 s mientras que ~220k y ~286k tokens devolvieron **HTTP 524 `origin_response_timeout`** a los ~126 s; los mismos tamaños con caché cálida responden en ~10 s. El techo práctico para peticiones frías queda por tanto muy por debajo de las ventanas declaradas. Desde 1.0.0 el provider reclasifica un 524 en una petición estimada por encima de 200.000 tokens (`NAN_COLD_CACHE_CEILING_TOKENS`) como desbordamiento de contexto para que pi compacte y reintente en vez de quedarse colgado; un 524 en una petición menor se deja intacto (timeout transitorio genuino).
|
|
@@ -480,16 +489,22 @@ El parámetro `reasoning_effort` de NaN controla cuánto piensa el modelo antes
|
|
|
480
489
|
|
|
481
490
|
| Modelo | Effort de razonamiento | Cómo funciona |
|
|
482
491
|
| :--- | :--- | :--- |
|
|
483
|
-
| `glm5.3` | `low` · `medium` · `high` · `max` |
|
|
484
|
-
| `
|
|
485
|
-
| `
|
|
486
|
-
| `
|
|
487
|
-
| `
|
|
488
|
-
| `
|
|
489
|
-
| `
|
|
492
|
+
| `glm5.3`, `glm5.3-flash` | `minimal` · `low` · `medium` · `high` · `xhigh` · `max` | GLM no puede parar de razonar: los docs aplican `none` como `minimal`, su razonamiento más corto (unos pocos tokens), así que `thinking: "off"` envía `minimal` vía el `thinkingLevelMap` del catálogo. Valores más altos razonan más antes de responder. `glm5.3-flash` se midió en ~38 tokens de razonamiento con `minimal` (issue #16, 2026-09-27); `none` no lo suprime |
|
|
493
|
+
| `qwen3.6`, `gemma4` | `none` · `minimal` · `low` · `medium` · `high` · `xhigh` · `max` | `none`/`minimal` omiten el razonamiento por completo; el resto limita la fase de razonamiento a 2K / 8K / 16K / 32K tokens. `thinking: "off"` envía `reasoning_effort: "none"` automáticamente vía el `thinkingLevelMap` del catálogo — los docs de NaN dicen que sin parámetro estos modelos razonan por defecto (presupuesto de 16,384 tokens), así que `off` debe ser explícito |
|
|
494
|
+
| `deepseek-v4-flash` | `none` · `minimal` · `low` · `medium` · `high` · `xhigh` · `max` | `none` deshabilita el razonamiento (0 tokens de razonamiento, respuesta completa); cualquier otro valor solo lo dirige — medido: 57 tokens de razonamiento con `low`, 63 omitiendo el parámetro y 109 con `minimal` (issue #16, re-sondado en vivo 2026-10-14). `thinking: "off"` envía `reasoning_effort: "none"` vía el `thinkingLevelMap` del catálogo — sin él el modelo se descontrola hasta `finish_reason: "length"` sin respuesta |
|
|
495
|
+
| `qwen3.8-flash` | `none` · `minimal` · `low` · `medium` · `high` · `xhigh` · `max` | El razonamiento está encendido por defecto (`none` lo apaga, el resto dirige su profundidad). `thinking: "off"` envía `reasoning_effort: "none"`; su presupuesto se limita con `max_tokens`, que el gateway de NaN ahora respeta (issue #36), y hay un tope duro de razonamiento vía `thinking_budget` |
|
|
496
|
+
| `qwen4-max` | `none` · `minimal` · `low` · `medium` · `high` · `xhigh` · `max` | `none` apaga el razonamiento, `minimal` a `max` lo dirigen, y `max_tokens` limita razonamiento **más** respuesta. Los docs recomiendan fijar un presupuesto: una respuesta abierta puede tardar muchos minutos |
|
|
497
|
+
| `mimo-v2.6-flash` | `none` · `low` · `medium` · `high` · `max` | `none` apaga el razonamiento (`minimal` se aplica como `low` y `xhigh` como `max`, así que esos dos no se declaran aparte); el razonamiento cuenta dentro de `max_tokens`. Medido en vivo 2026-10-14: `none` da 0 tokens de razonamiento con respuesta completa |
|
|
498
|
+
| `qwen3.8-max` | `none` | `none` apaga el razonamiento. `max_tokens` solo limita la respuesta visible, así que el catálogo envía `max_completion_tokens` para cubrir el total. Un presupuesto de razonamiento (`thinking_budget`) no se respeta en este modelo |
|
|
499
|
+
| `hy4` | `none` | Razona por defecto — la pasarela aplica `low` cuando la petición no nombra ningún nivel, y tu valor siempre gana. `none` lo apaga. `max_tokens` limita razonamiento más respuesta |
|
|
500
|
+
| `hy4-flash` | `none` | Razona por defecto sin nivel por defecto; `reasoning_effort: "none"` lo apaga (ignora `enable_thinking`). `max_tokens` limita razonamiento más respuesta, así que uno pequeño puede volver vacío |
|
|
501
|
+
| `kimi-k3.1-pro`, `deepseek-v4-pro` | *(sin mapeo declarado)* | Los docs dejan a estos dos fuera del contrato de razonamiento y dicen que los alias de `none` **no están mapeados** en ellos, así que el catálogo no declara valores de effort ni `thinkingLevelMap`: `thinking: "off"` no envía ningún parámetro y decide el modelo |
|
|
502
|
+
|
|
503
|
+
> [!NOTE]
|
|
504
|
+
> **`xhigh` y `max` son opt-in en pi.** pi-ai solo ofrece esos dos niveles a un modelo cuando su `thinkingLevelMap` los declara (`getSupportedThinkingLevels`; si no, una petición de cualquiera de los dos se degrada en silencio a `high`). Por eso el catálogo lleva entradas de identidad (`xhigh: "xhigh"`, `max: "max"`) en todos los modelos cuya doc declara una escalera hasta `max` — los siete modelos de chat más `mimo-v2.6-flash`, donde la pasarela aplica `xhigh` como `max`. `hy4`, `hy4-flash` y `qwen3.8-max` solo documentan su interruptor de apagado, y `kimi-k3.1-pro`/`deepseek-v4-pro` están fuera del contrato, así que esos cinco se quedan en `off`…`high`.
|
|
490
505
|
|
|
491
506
|
> [!NOTE]
|
|
492
|
-
> `maxTokens`
|
|
507
|
+
> `maxTokens` puede cortar antes de la respuesta visible en algunos modelos. El caso medido es `deepseek-v4-flash`: `max_tokens=512` aún consumió 13,376 tokens de completación, todos de razonamiento (26x el techo, issue #16, 2026-09-27). `qwen3.8-max` documenta la misma forma — `max_tokens` solo limita la respuesta visible — así que su entrada del catálogo envía `max_completion_tokens` para cubrir el total (docs del 2026-11-17). `qwen3.8-flash` fue el caso del #34 (NaN confirmó el mismo comportamiento el 2026-11-11); el soporte de NaN confirmó el 2026-11-17 que el arreglo del gateway está desplegado y validado, así que el paquete 1.5.7 retiró el override provisional y vuelve a enviar el `max_tokens` clásico (issue #36). Según los docs del 2026-11-17, `max_tokens` sí cubre razonamiento más respuesta en `qwen4-max` (hasta 131.000), `hy4`/`hy4-flash` (hasta 64.000) y `mimo-v2.6-flash`. Solo el razonamiento aún puede agotar el presupuesto completo y cerrar el turno con contenido vacío; ese corte lleva el marcador `reasoning_only_stream` de NaN y pi-ai reintenta el turno (issue #21).
|
|
493
508
|
|
|
494
509
|
## 🚀 Desarrollo
|
|
495
510
|
|
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).
|
|
@@ -22,7 +22,7 @@ Registers the `nan` provider via `pi.registerProvider()` using NaN's OpenAI-comp
|
|
|
22
22
|
| **Context-overflow rescue** | NaN's generic `400 Invalid request` is reclassified as an overflow when the request is estimated over the model's window ([#3](https://github.com/gtrabanco/pi-nan-provider/issues/3)), and a cold-cache `524` over `NAN_COLD_CACHE_CEILING_TOKENS` too ([#18](https://github.com/gtrabanco/pi-nan-provider/issues/18)) — pi compacts and retries instead of wedging. |
|
|
23
23
|
| **Truncated-stream retry** | `supportsFinishReason: true` turns an SSE stream closed before `finish_reason` into a retryable error instead of a silent stall ([#2](https://github.com/gtrabanco/pi-nan-provider/issues/2)). |
|
|
24
24
|
| **Streaming token usage** | `stream_options.include_usage` is on by default, so pi reports real input/output/reasoning/cache counts ([#4](https://github.com/gtrabanco/pi-nan-provider/issues/4), [#7](https://github.com/gtrabanco/pi-nan-provider/issues/7)). |
|
|
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 `
|
|
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 per-model max-token field (`qwen3.8-max` keeps `max_completion_tokens`; `qwen3.8-flash` returned to `max_tokens` after NaN's gateway fix, [#34](https://github.com/gtrabanco/pi-nan-provider/issues/34) → [#36](https://github.com/gtrabanco/pi-nan-provider/issues/36)). |
|
|
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
28
|
| **Native MCP media bridge** | The `nan-media` server (10 tools) registered through `pi.registerMcpServer()`, managed with `/nan-mcp`. |
|
|
@@ -84,7 +84,7 @@ NaN answers HTTP 400 `Invalid request. Check your request parameters.` for any b
|
|
|
84
84
|
- an assistant `content` array carrying a tool call is moved into the top-level `tool_calls` field (NaN's `ContentPart` accepts only `text` and `image_url`);
|
|
85
85
|
- `reasoning_details` is stripped, and unknown content parts (e.g. `thinking`) are folded into a `text` part so reasoning is not silently lost;
|
|
86
86
|
- fields NaN's schema does not list are removed: `store` always, an empty `tools` array always, and `stream_options` unless the model's `compat.supportsUsageInStreaming` says the gateway reports it;
|
|
87
|
-
- `max_completion_tokens` is renamed to `max_tokens` (the documented field) unless the model's `compat.maxTokensField` opts out ([#34](https://github.com/gtrabanco/pi-nan-provider/issues/34)
|
|
87
|
+
- `max_completion_tokens` is renamed to `max_tokens` (the documented field) unless the model's `compat.maxTokensField` opts out ([#34](https://github.com/gtrabanco/pi-nan-provider/issues/34); `qwen3.8-max` is the only catalog model that opts out after the [#36](https://github.com/gtrabanco/pi-nan-provider/issues/36) revert).
|
|
88
88
|
|
|
89
89
|
A caller-supplied `onPayload` hook is preserved and chained after sanitization.
|
|
90
90
|
|
|
@@ -385,9 +385,12 @@ Failures stay actionable: `401` → run `/login nan` or fix `NAN_API_KEY`, `404`
|
|
|
385
385
|
|
|
386
386
|
## 🧾 Cache anomaly evidence: `/nan-debug`
|
|
387
387
|
|
|
388
|
-
NaN
|
|
389
|
-
|
|
390
|
-
|
|
388
|
+
NaN disabled the proxy response cache on 2026-11-17 (support confirmation): two
|
|
389
|
+
identical requests now return two real completions, each with its own usage. The
|
|
390
|
+
old cache could replay the same completion `id` and `created` timestamp for
|
|
391
|
+
back-to-back requests (the issue #17 signature). The capture stays as a relapse
|
|
392
|
+
tripwire; NaN asked for the `model` and the `cf-ray` of a couple of calls when it
|
|
393
|
+
recurs, and pi transcripts do
|
|
391
394
|
not keep response headers, so the provider captures them itself.
|
|
392
395
|
|
|
393
396
|
When two streams for the same model return the same `id` + `created`, one JSON
|
|
@@ -438,18 +441,24 @@ Chat models:
|
|
|
438
441
|
| `mimo-v2.6-flash` | 1,048,576 | 131,072 | text, image | ✅ |
|
|
439
442
|
| `glm5.3-flash` | 1,048,576 | 131,072 | text, image | ✅ |
|
|
440
443
|
| `qwen3.8-flash` | 1,048,576 | 131,072 | text, image | ✅ |
|
|
441
|
-
| `glm5.3` | 1,048,576 | 131,072 | text
|
|
442
|
-
| `
|
|
443
|
-
| `
|
|
444
|
-
| `
|
|
445
|
-
| `
|
|
444
|
+
| `glm5.3` | 1,048,576 | 131,072 | text | ✅ |
|
|
445
|
+
| `hy4-flash` | 1,048,576 | 65,536 | text, image | ✅ |
|
|
446
|
+
| `hy4` | 1,048,576 | 65,536 | text, image | ✅ |
|
|
447
|
+
| `kimi-k3.1-pro` | 1,048,576 | 1,048,576 | text, image | ✅ |
|
|
448
|
+
| `qwen3.8-max` | 1,000,000 | 131,072 | text, image | ✅ |
|
|
449
|
+
| `qwen4-max` | 1,000,000 | 131,072 | text, image | ✅ |
|
|
450
|
+
| `deepseek-v4-pro` | 1,048,576 | 393,216 | text | ✅ |
|
|
446
451
|
|
|
447
452
|
> [!NOTE]
|
|
448
|
-
> Context windows above are the **documented**
|
|
453
|
+
> 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).
|
|
449
454
|
>
|
|
450
|
-
> `kimi-k3.1-pro`, `qwen3.8-max`, `deepseek-v4-pro`
|
|
455
|
+
> 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`.
|
|
451
456
|
>
|
|
452
|
-
>
|
|
457
|
+
> `qwen3.8-max` sends `max_completion_tokens` instead of `max_tokens`: its 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 (2026-11-17 docs). `qwen3.8-flash` used the same interim field after NaN confirmed the behaviour on 2026-11-11 ([#34](https://github.com/gtrabanco/pi-nan-provider/issues/34)); NaN support reported the gateway fix deployed and validated on 2026-11-17, so [#36](https://github.com/gtrabanco/pi-nan-provider/issues/36) removed that override and it sends the classic `max_tokens` again (the docs page still carries the old sentence; the support-confirmed gateway behaviour wins).
|
|
458
|
+
>
|
|
459
|
+
> 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.
|
|
460
|
+
>
|
|
461
|
+
> `*` 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`.
|
|
453
462
|
>
|
|
454
463
|
> **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).
|
|
455
464
|
|
|
@@ -476,15 +485,21 @@ NaN's `reasoning_effort` parameter controls how much the model thinks before ans
|
|
|
476
485
|
|
|
477
486
|
| Model | Reasoning effort | How it works |
|
|
478
487
|
| :--- | :--- | :--- |
|
|
479
|
-
| `glm5.3` | `low` · `medium` · `high` · `max` |
|
|
480
|
-
| `
|
|
481
|
-
| `
|
|
482
|
-
| `
|
|
483
|
-
| `
|
|
484
|
-
| `
|
|
485
|
-
| `
|
|
488
|
+
| `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 |
|
|
489
|
+
| `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 |
|
|
490
|
+
| `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 |
|
|
491
|
+
| `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_tokens`, which NaN's gateway now honours (issue #36), and a hard reasoning cap is available through `thinking_budget` |
|
|
492
|
+
| `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 |
|
|
493
|
+
| `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 |
|
|
494
|
+
| `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 |
|
|
495
|
+
| `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 |
|
|
496
|
+
| `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 |
|
|
497
|
+
| `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 |
|
|
498
|
+
|
|
499
|
+
> [!NOTE]
|
|
500
|
+
> **`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`.
|
|
486
501
|
> [!NOTE]
|
|
487
|
-
> `maxTokens`
|
|
502
|
+
> `maxTokens` can stop before the visible answer on some models. The measured case is `deepseek-v4-flash`: `max_tokens=512` still consumed 13,376 completion tokens, all reasoning (26x the ceiling, issue #16, 2026-09-27). `qwen3.8-max` documents the same shape — `max_tokens` bounds only the visible answer — so its catalog entry sends `max_completion_tokens` to cap the total (2026-11-17 docs). `qwen3.8-flash` was the #34 case (NaN confirmed the same behaviour on 2026-11-11); NaN support reported the gateway fix deployed and validated on 2026-11-17, so package 1.5.7 removed the interim override and it sends the classic `max_tokens` again (issue #36). Per the 2026-11-17 docs, `max_tokens` does bound reasoning plus answer on `qwen4-max` (up to 131,000), `hy4`/`hy4-flash` (up to 64,000) and `mimo-v2.6-flash`. 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).
|
|
488
503
|
|
|
489
504
|
|
|
490
505
|
---
|
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.7",
|
|
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
|
],
|