@gtrabanco/pi-nan-provider 1.5.6 → 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 +8 -2
- package/README.es.md +12 -9
- package/README.md +12 -9
- package/package.json +1 -1
- package/scripts/manual-overrides.ts +1 -2
- package/scripts/models.generated.ts +5 -5
- package/src/openai-compat-sanitizer.ts +10 -9
- package/src/provider-factory.ts +6 -4
package/AGENTS.md
CHANGED
|
@@ -254,7 +254,10 @@ Since 1.0.0 the package version **aligns its MAJOR.MINOR with the pi release lin
|
|
|
254
254
|
mapped, so they declare no effort values and no `thinkingLevelMap`;
|
|
255
255
|
`qwen3.8-max` gets `maxTokensField: "max_completion_tokens"` because its
|
|
256
256
|
`max_tokens` bounds only the visible answer (issue #34's quota failure
|
|
257
|
-
mode); `
|
|
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`
|
|
258
261
|
map `off` to `none`; `hy4` reasons by default with the gateway applying
|
|
259
262
|
`low` when no level is sent.
|
|
260
263
|
When the docs or models.dev change, re-verify the values (docs win; a
|
|
@@ -523,7 +526,10 @@ Since 1.0.0 the package version **aligns its MAJOR.MINOR with the pi release lin
|
|
|
523
526
|
provider-side: the store write path belongs to pi-ai.
|
|
524
527
|
|
|
525
528
|
- **Cache-anomaly evidence + `/nan-debug` (issue #35, verified 2026-11-11 on
|
|
526
|
-
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
|
|
527
533
|
only response-header surface (`ProviderResponse = { status, headers }`,
|
|
528
534
|
called by openai-completions right after the HTTP response). The gateway
|
|
529
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
|
|
@@ -454,7 +457,7 @@ Modelos de chat:
|
|
|
454
457
|
>
|
|
455
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.
|
|
456
459
|
>
|
|
457
|
-
> `qwen3.8-max` envía `max_completion_tokens` en vez de `max_tokens
|
|
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).
|
|
458
461
|
>
|
|
459
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.
|
|
460
463
|
>
|
|
@@ -489,7 +492,7 @@ El parámetro `reasoning_effort` de NaN controla cuánto piensa el modelo antes
|
|
|
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 |
|
|
490
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 |
|
|
491
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 |
|
|
492
|
-
| `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 `
|
|
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` |
|
|
493
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 |
|
|
494
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 |
|
|
495
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 |
|
|
@@ -501,7 +504,7 @@ El parámetro `reasoning_effort` de NaN controla cuánto piensa el modelo antes
|
|
|
501
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`.
|
|
502
505
|
|
|
503
506
|
> [!NOTE]
|
|
504
|
-
> `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).
|
|
505
508
|
|
|
506
509
|
## 🚀 Desarrollo
|
|
507
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
|
|
@@ -451,7 +454,7 @@ Chat models:
|
|
|
451
454
|
>
|
|
452
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`.
|
|
453
456
|
>
|
|
454
|
-
> `qwen3.8-max` sends `max_completion_tokens` instead of `max_tokens
|
|
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).
|
|
455
458
|
>
|
|
456
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.
|
|
457
460
|
>
|
|
@@ -485,7 +488,7 @@ NaN's `reasoning_effort` parameter controls how much the model thinks before ans
|
|
|
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 |
|
|
486
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 |
|
|
487
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 |
|
|
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 `
|
|
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` |
|
|
489
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 |
|
|
490
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 |
|
|
491
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 |
|
|
@@ -496,7 +499,7 @@ NaN's `reasoning_effort` parameter controls how much the model thinks before ans
|
|
|
496
499
|
> [!NOTE]
|
|
497
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`.
|
|
498
501
|
> [!NOTE]
|
|
499
|
-
> `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).
|
|
500
503
|
|
|
501
504
|
|
|
502
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",
|
|
@@ -292,12 +292,11 @@ export const MANUAL_OVERRIDES: Record<string, ManualModelOverride> = {
|
|
|
292
292
|
},
|
|
293
293
|
"qwen3.8-flash": {
|
|
294
294
|
contextWindow: 1_048_576,
|
|
295
|
-
maxTokensField: "max_completion_tokens",
|
|
296
295
|
reasoningEffortValues: ["none", "minimal", "low", "medium", "high", "xhigh", "max"],
|
|
297
296
|
thinkingLevelMap: { off: "none", xhigh: "xhigh", max: "max" },
|
|
298
297
|
note:
|
|
299
298
|
"contextWindow 1,048,576: NaN docs state '1M token context (1,048,576 tokens)' and 'Max answer 131K tokens' (https://nan.builders/docs/models, checked 2026-11-17) — models.dev still lists 262,144. The earlier override was withdrawn 2026-09-07 when the docs read '262K token context, the model's native window'; the docs now state 1M and they are the source of truth (maintainer instruction: docs win over models.dev, which a user updates later). maxTokens stays 131,072, which models.dev already matches and the docs confirm as the 131K max answer. " +
|
|
300
|
-
"maxTokensField
|
|
299
|
+
"maxTokensField: intermediate history only, no override today. Issue #34 (NaN maintainer confirmation 2026-11-11) reported that max_tokens did NOT bound the reasoning phase on this model and that the excess billed against the quota; package 1.5.3 sent max_completion_tokens as the interim bound. NaN support reported the gateway fix deployed and validated (max_tokens honours 1024, received 2026-11-17), so issue #36 removed the override in package 1.5.7 and the generated entry is back on the classic max_tokens field. qwen3.8-max keeps its own maxTokensField override on separate docs evidence (2026-11-17), not on the #34 interim. " +
|
|
301
300
|
"reasoningEffortValues none..max and thinkingLevelMap { off: 'none' }: the card says 'Reasoning on by default (reasoning_effort: none turns it off · minimal to max)' and the contract table says 'Off. No reasoning tokens' for `none` (https://nan.builders/docs/models, checked 2026-11-17), so `thinking: off` now actually disables reasoning. The earlier note said the parameter was 'accepted, depth not adjustable' with no map, which was true of the 2026-10-14 docs; the model card and the contract table now state the opposite and the docs win.",
|
|
302
301
|
},
|
|
303
302
|
"deepseek-v4-flash": {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// This file is auto-generated by scripts/generate-models.ts
|
|
2
2
|
// Do not edit manually — run `bun run generate-models` to update.
|
|
3
3
|
//
|
|
4
|
-
// Source: https://models.dev/api.json (provider "nan"), fetched 2026-11-
|
|
4
|
+
// Source: https://models.dev/api.json (provider "nan"), fetched 2026-11-18T00:35:14.603Z
|
|
5
5
|
// Provenance: every contextWindow/maxTokens/input/cost value traces to
|
|
6
6
|
// models.dev or to the per-entry notes below. Nothing is invented; entries
|
|
7
7
|
// models.dev documents incompletely are omitted and flagged instead.
|
|
@@ -838,12 +838,12 @@ export const NAN_GENERATED_MODELS: readonly GeneratedModelEntry[] = [
|
|
|
838
838
|
"supportsReasoningEffort": true,
|
|
839
839
|
"supportsUsageInStreaming": true,
|
|
840
840
|
"supportsFinishReason": true,
|
|
841
|
-
"maxTokensField": "
|
|
841
|
+
"maxTokensField": "max_tokens"
|
|
842
842
|
},
|
|
843
843
|
"notes": [
|
|
844
844
|
"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.",
|
|
845
845
|
"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).",
|
|
846
|
-
"contextWindow 1,048,576: NaN docs state '1M token context (1,048,576 tokens)' and 'Max answer 131K tokens' (https://nan.builders/docs/models, checked 2026-11-17) — models.dev still lists 262,144. The earlier override was withdrawn 2026-09-07 when the docs read '262K token context, the model's native window'; the docs now state 1M and they are the source of truth (maintainer instruction: docs win over models.dev, which a user updates later). maxTokens stays 131,072, which models.dev already matches and the docs confirm as the 131K max answer. maxTokensField
|
|
846
|
+
"contextWindow 1,048,576: NaN docs state '1M token context (1,048,576 tokens)' and 'Max answer 131K tokens' (https://nan.builders/docs/models, checked 2026-11-17) — models.dev still lists 262,144. The earlier override was withdrawn 2026-09-07 when the docs read '262K token context, the model's native window'; the docs now state 1M and they are the source of truth (maintainer instruction: docs win over models.dev, which a user updates later). maxTokens stays 131,072, which models.dev already matches and the docs confirm as the 131K max answer. maxTokensField: intermediate history only, no override today. Issue #34 (NaN maintainer confirmation 2026-11-11) reported that max_tokens did NOT bound the reasoning phase on this model and that the excess billed against the quota; package 1.5.3 sent max_completion_tokens as the interim bound. NaN support reported the gateway fix deployed and validated (max_tokens honours 1024, received 2026-11-17), so issue #36 removed the override in package 1.5.7 and the generated entry is back on the classic max_tokens field. qwen3.8-max keeps its own maxTokensField override on separate docs evidence (2026-11-17), not on the #34 interim. reasoningEffortValues none..max and thinkingLevelMap { off: 'none' }: the card says 'Reasoning on by default (reasoning_effort: none turns it off · minimal to max)' and the contract table says 'Off. No reasoning tokens' for `none` (https://nan.builders/docs/models, checked 2026-11-17), so `thinking: off` now actually disables reasoning. The earlier note said the parameter was 'accepted, depth not adjustable' with no map, which was true of the 2026-10-14 docs; the model card and the contract table now state the opposite and the docs win."
|
|
847
847
|
],
|
|
848
848
|
"extras": {
|
|
849
849
|
"id": "qwen3.8-flash",
|
|
@@ -1027,7 +1027,7 @@ export const NAN_GENERATED_MODELS: readonly GeneratedModelEntry[] = [
|
|
|
1027
1027
|
export const GENERATED_CATALOG_META = {
|
|
1028
1028
|
source: "https://models.dev/api.json",
|
|
1029
1029
|
modelsDevProvider: "nan",
|
|
1030
|
-
fetchedAt: "2026-11-
|
|
1030
|
+
fetchedAt: "2026-11-18T00:35:14.603Z",
|
|
1031
1031
|
modelCount: 13,
|
|
1032
1032
|
models: ["deepseek-v4-flash","deepseek-v4-pro","gemma4","glm5.3","glm5.3-flash","hy4","hy4-flash","kimi-k3.1-pro","mimo-v2.6-flash","qwen3.6","qwen3.8-flash","qwen3.8-max","qwen4-max"],
|
|
1033
1033
|
notes: [
|
|
@@ -1057,7 +1057,7 @@ export const GENERATED_CATALOG_META = {
|
|
|
1057
1057
|
"reasoningEffortValues none/low/medium/high/max: the card says 'reasoning_effort: none turns it off · low to max', and the contract table says 'minimal is applied as low and xhigh as max' (https://nan.builders/docs/models#controlling-reasoning, checked 2026-11-17), so only the values with their own meaning are declared. thinkingLevelMap { off: \"none\" } (live re-probe 2026-10-14): the 2026-10-14 docs called the parameter 'accepted, depth not adjustable', but the gateway makes it effective at the off end — `none` gave 0 reasoning tokens / a full answer, while `low` gave 22 reasoning tokens and omitting the parameter gave 17. Measured behavior wins over the docs, so `thinking: off` sends reasoning_effort:\"none\" and actually disables reasoning.",
|
|
1058
1058
|
"manual-only: \"mimo-v2.6-flash\" skipped: models.dev provider \"nan\" now lists it, so the manual-only entry is not emitted and the models.dev values are used (omnimodal model (text, image, audio input) served by NaN; limits and modalities from https://nan.builders/docs/models#mimo-v2-6-flash (checked 2026-09-25, quotas re-checked 2026-09-29): 1,048,576 context / 131,072 max output / 1.0B monthly quota per member. Tool calling: yes. Streaming: yes. Input modalities (pi-representable): text, image (audio not representable in pi's Model type). Fallback entry: emitted only while models.dev provider nan does not list the model — models.dev started listing it on 2026-09-29, so the generator then keeps the models.dev values and attaches this note to that entry instead of emitting a second one.)",
|
|
1059
1059
|
"thinkingLevelMap { off: \"none\" } (issue #16): NaN docs state that with no reasoning_effort parameter every model uses its own default and that default is reasoning ON for qwen3.6 (16,384-token budget), while `none` and `minimal` skip the reasoning phase entirely (https://nan.builders/docs/models#controlling-reasoning, checked 2026-11-17). pi maps reasoning:\"off\" to reasoningEffort:undefined, so without this map `thinking: off` sent no parameter and the model reasoned anyway; the map sends reasoning_effort:\"none\" and actually disables reasoning. reasoningEffortValues: the contract table documents the whole ladder (low 2,048, medium 8,192, high 16,384, xhigh and max 32,768 reasoning tokens on Chat Completions).",
|
|
1060
|
-
"contextWindow 1,048,576: NaN docs state '1M token context (1,048,576 tokens)' and 'Max answer 131K tokens' (https://nan.builders/docs/models, checked 2026-11-17) — models.dev still lists 262,144. The earlier override was withdrawn 2026-09-07 when the docs read '262K token context, the model's native window'; the docs now state 1M and they are the source of truth (maintainer instruction: docs win over models.dev, which a user updates later). maxTokens stays 131,072, which models.dev already matches and the docs confirm as the 131K max answer. maxTokensField
|
|
1060
|
+
"contextWindow 1,048,576: NaN docs state '1M token context (1,048,576 tokens)' and 'Max answer 131K tokens' (https://nan.builders/docs/models, checked 2026-11-17) — models.dev still lists 262,144. The earlier override was withdrawn 2026-09-07 when the docs read '262K token context, the model's native window'; the docs now state 1M and they are the source of truth (maintainer instruction: docs win over models.dev, which a user updates later). maxTokens stays 131,072, which models.dev already matches and the docs confirm as the 131K max answer. maxTokensField: intermediate history only, no override today. Issue #34 (NaN maintainer confirmation 2026-11-11) reported that max_tokens did NOT bound the reasoning phase on this model and that the excess billed against the quota; package 1.5.3 sent max_completion_tokens as the interim bound. NaN support reported the gateway fix deployed and validated (max_tokens honours 1024, received 2026-11-17), so issue #36 removed the override in package 1.5.7 and the generated entry is back on the classic max_tokens field. qwen3.8-max keeps its own maxTokensField override on separate docs evidence (2026-11-17), not on the #34 interim. reasoningEffortValues none..max and thinkingLevelMap { off: 'none' }: the card says 'Reasoning on by default (reasoning_effort: none turns it off · minimal to max)' and the contract table says 'Off. No reasoning tokens' for `none` (https://nan.builders/docs/models, checked 2026-11-17), so `thinking: off` now actually disables reasoning. The earlier note said the parameter was 'accepted, depth not adjustable' with no map, which was true of the 2026-10-14 docs; the model card and the contract table now state the opposite and the docs win.",
|
|
1061
1061
|
"Qwen3.8 Max, documented in https://nan.builders/docs/models (checked 2026-11-17; models.dev provider nan lists it since 2026-11-10). contextWindow 1,000,000: the card says '1M token context' and the first-party vendor value on models.dev provider alibaba (qwen3.8-max) is 1,000,000 — the smaller of that and NaN's 1M = 1,048,576 convention (https://nan.builders/docs/pi). maxTokens 131,072: the card says 'Max answer 131K tokens'. maxTokensField 'max_completion_tokens': the docs state that on this model 'max_tokens only bounds the visible answer: the reasoning comes on top of it. To cap the total (reasoning plus answer, and so the cost) use max_completion_tokens' — the quota blowout issue #34 fixed for qwen3.8-flash, same fix, same sanitizer exemption (SanitizerOptions.preserveMaxCompletionTokens, wired from compat.maxTokensField in src/provider-factory.ts). input text+image per the card. Reasoning: the docs say 'none turns it off' for this model, so reasoningEffortValues declares 'none' and thinkingLevelMap { off: 'none' } sends it when pi maps reasoning:'off' to undefined. Cost 0 per maintainer decision (NaN bills credits, not per-token USD).",
|
|
1062
1062
|
"manual-only: \"qwen3.8-max\" skipped: models.dev provider \"nan\" now lists it, so the manual-only entry is not emitted and the models.dev values are used (NaN larger model documented in https://nan.builders/docs/models (checked 2026-11-17) and listed by the live GET https://api.nan.builders/v1/models (checked 2026-11-17), but absent from models.dev provider nan)",
|
|
1063
1063
|
"manual-only: \"qwen4-max\" not yet on models.dev provider nan (NaN larger model documented in https://nan.builders/docs/models (checked 2026-11-17) and listed by the live GET https://api.nan.builders/v1/models (checked 2026-11-17), but absent from models.dev provider nan).",
|
|
@@ -201,12 +201,12 @@ export interface SanitizerOptions {
|
|
|
201
201
|
/**
|
|
202
202
|
* Keep `max_completion_tokens` in the payload instead of renaming it to
|
|
203
203
|
* `max_tokens`. Set only when the model's effective `compat.maxTokensField`
|
|
204
|
-
* is `"max_completion_tokens"`
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
* documented rename runs — NaN's
|
|
208
|
-
* `max_tokens`, so hand-built
|
|
209
|
-
* the strict shape.
|
|
204
|
+
* is `"max_completion_tokens"` — the per-model mechanism introduced for
|
|
205
|
+
* issue #34. `qwen3.8-flash` used it until the gateway fix landed (#36);
|
|
206
|
+
* `qwen3.8-max` still declares it because its `max_tokens` bounds only the
|
|
207
|
+
* visible answer. When false/absent the documented rename runs — NaN's
|
|
208
|
+
* published OpenAPI schema only documents `max_tokens`, so hand-built
|
|
209
|
+
* payloads and non-overridden models stay on the strict shape.
|
|
210
210
|
*/
|
|
211
211
|
preserveMaxCompletionTokens?: boolean;
|
|
212
212
|
}
|
|
@@ -255,9 +255,10 @@ export function sanitizeOpenAICompatPayload(payload: unknown, options: Sanitizer
|
|
|
255
255
|
// must stay schema-strict.
|
|
256
256
|
if (options.preserveStreamOptions !== true) delete out.stream_options;
|
|
257
257
|
// NaN documents `max_tokens`, not `max_completion_tokens` — unless the
|
|
258
|
-
// model's compat declares `max_completion_tokens` (
|
|
259
|
-
//
|
|
260
|
-
// the catalog's maxTokensField override
|
|
258
|
+
// model's compat declares `max_completion_tokens` (the #34 mechanism,
|
|
259
|
+
// still used by `qwen3.8-max`): the gateway honors it there to bound the
|
|
260
|
+
// total, so the rename would undo the catalog's maxTokensField override
|
|
261
|
+
// before the payload leaves pi.
|
|
261
262
|
if (
|
|
262
263
|
"max_completion_tokens" in out &&
|
|
263
264
|
!("max_tokens" in out) &&
|
package/src/provider-factory.ts
CHANGED
|
@@ -121,10 +121,12 @@ function modelSupportsUsageInStreaming(model: unknown): boolean {
|
|
|
121
121
|
|
|
122
122
|
/**
|
|
123
123
|
* Whether the model's effective compat sends the `max_completion_tokens`
|
|
124
|
-
* request field instead of the classic `max_tokens` (
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
124
|
+
* request field instead of the classic `max_tokens` (the per-model mechanism
|
|
125
|
+
* from issue #34; `qwen3.8-max` is the catalog model that still uses it).
|
|
126
|
+
* The model object here is pi-ai's post-registry view — baseline catalog,
|
|
127
|
+
* live-merge refresh, `models.json` override and the #19 stale-store overlay
|
|
128
|
+
* all flow through `compat`, so this reads the value the user actually runs
|
|
129
|
+
* with.
|
|
128
130
|
*/
|
|
129
131
|
function modelSendsMaxCompletionTokens(model: unknown): boolean {
|
|
130
132
|
if (!isObject(model)) return false;
|