pi-provider-litellm 4.6.0 → 4.7.1

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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  LiteLLM proxy native Provider extension for [Pi](https://pi.dev). Pi 0.99.2+ is required; on older Pi, install `npm:pi-provider-litellm@3.4.0`.
4
4
 
5
- Discovers models from self-hosted LiteLLM proxies and registers them under Pi providers. The default provider is `litellm`; optional aliases can register additional LiteLLM providers with separate credentials. Supports `/login litellm`, LiteLLM MCP tools, LiteLLM Skills Gateway prompt injection, and Google ADC token auth. Tries `/model/info` first (admin endpoint with rich metadata), falls back to `/v1/models` (OpenAI-compatible) on 401/403/404 or an empty list, then tries `/health` plus per-endpoint `/model/info` for older LiteLLM proxies.
5
+ Discovers models from self-hosted LiteLLM proxies and registers them under Pi providers. The default provider is `litellm`; optional aliases can register additional LiteLLM providers with separate credentials. Supports `/login litellm`, LiteLLM MCP tools, LiteLLM Skills Gateway prompt injection, budget status, image generation and classifier routes, and Google ADC token auth. A [Go port](#pig) brings it to PiG, without image generation and classifier routes. Tries `/model/info` first (admin endpoint with rich metadata), falls back to `/v1/models` (OpenAI-compatible) on 401/403/404 or an empty list, then tries `/health` plus per-endpoint `/model/info` for older LiteLLM proxies.
6
6
 
7
7
  ## Install
8
8
 
@@ -425,10 +425,11 @@ such as OpenAI's GPT-6 Luna, is published as both a chat model and a classifier.
425
425
  | `LITELLM_PROVIDERS` | unset | Canonical comma- or whitespace-separated list of provider IDs to register. |
426
426
  | `LITELLM_PROVIDERS_JSON` | unset | JSON string of provider configuration objects matching the `litellm.providers` settings schema. |
427
427
  | `LITELLM_PROVIDER_<NAME>_*` | unset | Per-provider environment variables for base URL, API key, headers, display name, OAuth, Google auth, and MCP enable/disable toggle (`_ENABLE_MCP` / `_MCP_ENABLED`). See [Multi-provider environment variables](#multi-provider-environment-variables). |
428
+ | `LITELLM_STARTUP_KEY_HELPER` | unset | If set to `1`, activation runs `LITELLM_API_KEY_HELPER` (or the configured key helper) once to seed models at startup. Without it the helper is never run at activation, so a helper-only setup has no models in `pi -p` print mode until a refresh. |
428
429
  | `LITELLM_GCLOUD_TOKEN_AUTH` | unset | If set to a non-empty value other than `0`, use Google Application Default Credentials as the LiteLLM bearer token source. This takes precedence over `LITELLM_API_KEY_HELPER` and `LITELLM_API_KEY` when no stored `/login litellm` credential exists. |
429
430
  | `GOOGLE_APPLICATION_CREDENTIALS` | Google default ADC path | Optional path to an ADC JSON file used by `LITELLM_GCLOUD_TOKEN_AUTH`. If unset, the extension checks the default gcloud ADC locations. |
430
431
  | `LITELLM_OFFLINE` | unset | If `1`, disable all model and MCP discovery, including post-login discovery; use cached models only when their stored canonical proxy root exactly matches the active credential root, including any path prefix. URL-standard host casing and default ports are canonicalized, but paths remain case-sensitive. |
431
- | `PI_OFFLINE` | unset | Pi documents it as disabling automatic network activity, including model catalog refreshes. Through Pi 1.2.0, any set value (including `0` or an empty string) disables startup model discovery and `/model` network refreshes. Run `/litellm-refresh`, or unset it, to discover; cached models can still be used offline. |
432
+ | `PI_OFFLINE` | unset | Pi documents it as disabling automatic network activity, including model catalog refreshes. Through Pi 1.4.0, any set value (including `0` or an empty string) disables startup model discovery and `/model` network refreshes. Run `/litellm-refresh`, or unset it, to discover; cached models can still be used offline. |
432
433
  | `LITELLM_DISCOVERY_TIMEOUT_MS` | `5000` | Background and explicit discovery fetch timeout in ms; `0` disables automatic discovery |
433
434
  | `LITELLM_CLI_JWT_EXPIRATION_HOURS` | `24` | CLI SSO token lifetime fallback for older proxies whose poll response omits `expires_in`; mirror a non-default proxy setting locally |
434
435
  | `LITELLM_VERBOSE_DISCOVERY` | unset | If `1`, enable progress messages during model discovery (login, refresh, startup), including startup skip reasons and defaulted `/model/info` context windows. Progress messages are off by default |
@@ -436,7 +437,7 @@ such as OpenAI's GPT-6 Luna, is published as both a chat model and a classifier.
436
437
  | `LITELLM_TRUST_PROXY_LIMITS` | unset | If `1`, a deployment's explicit `model_info.max_input_tokens` / `max_output_tokens` win over Pi's catalog instead of taking the smaller of the two; the catalog still fills missing values and the group minimum still applies. A `models.json` `modelOverrides` entry still wins first |
437
438
  | `LITELLM_MODELS_DEV` | unset | If `1`, enrich discovered metadata (limits, prices, effort lists) from models.dev, cached for 28 days in `litellm-models-dev.json`. Off by default because LiteLLM's `/model/info` is authoritative; use it when LiteLLM's model map lacks a model's metadata |
438
439
 
439
- Only use a trusted `LITELLM_API_KEY_HELPER` or `!command`. Prefer an absolute executable path, keep secrets out of command arguments, and print only the token to stdout without logging it to stderr.
440
+ Only use a trusted `LITELLM_API_KEY_HELPER` or `!command`. Prefer an absolute executable path, keep secrets out of command arguments, and print only the token to stdout without logging it to stderr. With `LITELLM_STARTUP_KEY_HELPER=1` the helper also runs at startup, so set that flag only from a launcher you trust.
440
441
 
441
442
  With `LITELLM_VERBOSE_DISCOVERY=1`, `/model/info` discovery reports published routes whose context window uses the fallback assumption (including wildcard expansions) on one line with the selected value, a count, and a sample of escaped route names. Each route is reported once per process. Explicit or authoritative catalog limits do not trigger it, even when numerically equal to the default. Set `model_info.max_input_tokens` on every deployment in the route to provide real limits; this diagnostic does not change discovery limits or routing.
442
443
 
@@ -485,13 +486,15 @@ If your LiteLLM proxy exposes `/claude-code/marketplace.json`, enabled skills ar
485
486
  ## PiG
486
487
 
487
488
  A Go port for [PiG](https://github.com/MichaelKinsy/PiG) lives in [`pig/`](pig/README.md). It reads the same
488
- settings, environment variables and `auth.json` entries; see [pig/README.md](pig/README.md) to install it.
489
+ settings, environment variables and `auth.json` entries; see [pig/README.md](pig/README.md) to install it. A PiG native
490
+ provider cannot yet surface image or classifier models, so the port does not publish image generation or decision
491
+ routes.
489
492
 
490
493
  ## Mocked LiteLLM smoke workflow
491
494
 
492
495
  The `LiteLLM Smoke` GitHub Actions workflow starts VidaiMock and a real LiteLLM proxy on the runner. LiteLLM exposes route-distinct Chat, Responses, native Messages, and mixed-deployment models whose upstreams are served by VidaiMock. The smoke runner discovers those models through LiteLLM, asserts each model's expected API, exercises `/v1/chat/completions`, `/v1/responses`, and `/v1/messages`, verifies the expected `x-litellm-response-cost` behavior, and proves endpoint coverage from captured LiteLLM request logs rather than response text.
493
496
 
494
- This keeps the LiteLLM integration path under test but does not call real LLM APIs. No provider API keys or GitHub Models permission are required. The smoke runner also asserts that discovery came from `/model/info` (`LITELLM_SMOKE_EXPECT_SOURCE`) so a silent fallback to `/v1/models` fails the run. The workflow also runs auth checks plus optional Postgres-backed auth checks when `LITELLM_LICENSE` is configured for virtual-key and admin-route behavior, then runs a non-interactive Pi CLI smoke with `--list-models` and `-p` against both the OpenAI-compatible and Anthropic-backed routes, so extension loading, model discovery, and real completion paths are covered without opening the TUI. It also runs an interactive Pi TUI smoke covering `/login litellm` and Pi's native `/model` refresh. VidaiMock returns fixed responses, so the real-proxy smoke does not exercise a model-originated tool call or thinking block; the native Messages compatibility suite covers thinking, tool use, tool results, and replay across turns.
497
+ This keeps the LiteLLM integration path under test but does not call real LLM APIs. No provider API keys or GitHub Models permission are required. The manual `LiteLLM Live Smoke` workflow (`.github/workflows/litellm-live-smoke.yml`) runs the same proxy and smoke runner with a real Anthropic Console key from the repository secret named in that file, publishing cheap Claude backends as native Messages, Chat Completions, and Responses routes; each run spends a few hundred tokens of real credits. The smoke runner also asserts that discovery came from `/model/info` (`LITELLM_SMOKE_EXPECT_SOURCE`) so a silent fallback to `/v1/models` fails the run. The workflow also runs auth checks plus optional Postgres-backed auth checks when `LITELLM_LICENSE` is configured for virtual-key and admin-route behavior, then runs a non-interactive Pi CLI smoke with `--list-models` and `-p` against both the OpenAI-compatible and Anthropic-backed routes, so extension loading, model discovery, and real completion paths are covered without opening the TUI. It also runs an interactive Pi TUI smoke covering `/login litellm` and Pi's native `/model` refresh. VidaiMock returns fixed responses, so the real-proxy smoke does not exercise a model-originated tool call or thinking block; the native Messages compatibility suite covers thinking, tool use, tool results, and replay across turns.
495
498
 
496
499
  ## Development
497
500
 
@@ -512,13 +515,15 @@ npm run supply-chain:guard
512
515
  npm pack --dry-run
513
516
  ```
514
517
 
518
+ Changes to the Go port in `pig/` are verified separately; see [pig/README.md](pig/README.md) for its `go test` and `pig package validate` steps.
519
+
515
520
  The published npm package contains only `src`, `README.md`, `LICENSE`, and the `package.json` npm always includes. Pi loads the TypeScript source entrypoint for both npm and Git installs. The package does not expose a JavaScript or TypeScript library import; load it through Pi.
516
521
 
517
522
  ## Release
518
523
 
519
- Releases are driven by semver tags named `v*.*.*`. The GitHub release workflow installs from the lockfile, then `npm publish` runs `prepublishOnly` to check the source, build `dist` for verification, verify the package contents, and publish to npm with provenance before the workflow creates a GitHub release.
524
+ Releases are driven by semver tags named `v*.*.*`. The GitHub release workflow installs from the lockfile, then `npm publish` runs `prepublishOnly` to check the source, build `dist` for verification, verify the package contents, and publish to npm with provenance before the workflow creates a GitHub release. The same tag publishes the Go port from `pig/` as `pig-provider-litellm`.
520
525
 
521
- Before tagging a release, keep `package.json` and `package-lock.json` versions in sync and verify the dry-run package contents.
526
+ Before tagging a release, keep the `package.json`, `package-lock.json` and `pig/package.json` versions in sync and verify the dry-run package contents.
522
527
 
523
528
  ## Model catalog
524
529
 
@@ -609,7 +614,7 @@ The development probe runs against minimized snapshots with `npm run probe:proxy
609
614
  | "no credentials" warning at startup | Env vars not set and no OAuth credential — run `/login litellm` |
610
615
  | No models, or no new routes, while `PI_OFFLINE` is set | Pi skips every model network refresh, including the one `/model` starts. Run `/litellm-refresh`, or unset `PI_OFFLINE` (`PI_OFFLINE=0` is not enough) |
611
616
  | `No models available` at startup, gone after a restart | A Pi startup race, not discovery — see [`No models available` at startup](#no-models-available-at-startup) |
612
- | "discovered no models" | Proxy returned an empty list — check pi's startup log and verify `/model/info`, `/v1/models`, or `/health` responds |
617
+ | `/litellm-refresh` reports `refreshed 0 models` | Proxy returned an empty list — check pi's startup log and verify `/model/info`, `/v1/models`, or `/health` responds |
613
618
  | `/model/info` returning 401/403/404 or an empty list | Expected behavior with virtual keys — extension falls back to `/v1/models` |
614
619
  | Discovery times out | Increase `LITELLM_DISCOVERY_TIMEOUT_MS` or set `LITELLM_OFFLINE=1` to fall back on cached models. Offline mode does not recover a root mismatch, including a different path prefix — see [Model host enforcement](#model-host-enforcement) |
615
620
  | A provider shows no models | The base URL is missing, invalid, still the placeholder, or its full root, including any path prefix, differs from the root in the cached catalog. Check stderr and see [Model host enforcement](#model-host-enforcement) |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-provider-litellm",
3
- "version": "4.6.0",
3
+ "version": "4.7.1",
4
4
  "description": "LiteLLM proxy provider extension for Pi",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -63,7 +63,7 @@
63
63
  "basic-ftp": "6.0.1",
64
64
  "nanoid": "3.3.18",
65
65
  "protobufjs": "8.7.1",
66
- "undici": "8.10.2"
66
+ "undici": "8.12.3"
67
67
  },
68
68
  "devDependencies": {
69
69
  "@biomejs/biome": "^2.4.15",
@@ -74,7 +74,7 @@
74
74
  "@typescript/native-preview": "7.0.0-dev.20260707.2",
75
75
  "es-module-lexer": "^3.0.2",
76
76
  "tsx": "^4.21.0",
77
- "typebox": "1.4.2",
77
+ "typebox": "1.4.3",
78
78
  "vitest": "^5.0.0"
79
79
  }
80
80
  }
package/src/discover.ts CHANGED
@@ -650,7 +650,12 @@ export async function fetchJson<T>(
650
650
 
651
651
  const DIAGNOSTIC_ROUTE_SAMPLE = 3;
652
652
 
653
+ type Report = (message: string) => void;
654
+
655
+ const writeStderr: Report = (message) => process.stderr.write(`${message}\n`);
656
+
653
657
  function reportBoundedRoutes(
658
+ report: Report,
654
659
  reported: Set<string>,
655
660
  routes: readonly string[],
656
661
  describe: (count: number) => string,
@@ -660,7 +665,7 @@ function reportBoundedRoutes(
660
665
  for (const route of unreported) reported.add(route);
661
666
  const hidden = unreported.length - DIAGNOSTIC_ROUTE_SAMPLE;
662
667
  const sample = unreported.slice(0, DIAGNOSTIC_ROUTE_SAMPLE).join(", ");
663
- process.stderr.write(`${describe(unreported.length)}: ${sample}${hidden > 0 ? ` (+${hidden} more)` : ""}\n`);
668
+ report(`${describe(unreported.length)}: ${sample}${hidden > 0 ? ` (+${hidden} more)` : ""}`);
664
669
  }
665
670
 
666
671
  // Reported routes, so a persistent misconfiguration is announced once rather than on
@@ -673,8 +678,9 @@ const reportedAmbiguousRoutes = new Set<string>();
673
678
  // supplies complete prices; limits and other catalog-derived metadata may still use
674
679
  // conservative defaults. Report that degradation regardless of
675
680
  // LITELLM_VERBOSE_DISCOVERY, carrying only a count and bounded public route ids.
676
- function reportAmbiguousCatalogAuthority(routes: readonly string[]): void {
681
+ function reportAmbiguousCatalogAuthority(report: Report, routes: readonly string[]): void {
677
682
  reportBoundedRoutes(
683
+ report,
678
684
  reportedAmbiguousRoutes,
679
685
  routes,
680
686
  (count) =>
@@ -685,8 +691,9 @@ function reportAmbiguousCatalogAuthority(routes: readonly string[]): void {
685
691
 
686
692
  const reportedIncompatibleModeRoutes = new Set<string>();
687
693
 
688
- function reportIncompatibleDeploymentModes(routes: readonly string[]): void {
694
+ function reportIncompatibleDeploymentModes(report: Report, routes: readonly string[]): void {
689
695
  reportBoundedRoutes(
696
+ report,
690
697
  reportedIncompatibleModeRoutes,
691
698
  routes,
692
699
  (count) =>
@@ -893,9 +900,10 @@ function mapFromModelsList(entry: ModelsListEntry): DiscoveredModel | undefined
893
900
  async function discoverFromHealth(
894
901
  base: string,
895
902
  apiKey: string,
896
- options: DiscoveryOptions & { onProgress?: (message: string) => void; silent?: boolean },
903
+ options: DiscoveryOptions & { onProgress?: (message: string) => void; report?: Report; silent?: boolean },
897
904
  ): Promise<DiscoveredModel[]> {
898
905
  const progress = options.silent ? undefined : options.onProgress;
906
+ const report = options.report ?? writeStderr;
899
907
  progress?.("Querying /health endpoint...");
900
908
  const healthResult = await fetchJson<HealthResponse>(`${base}/health`, apiKey, options);
901
909
  if (!healthResult.ok) return [];
@@ -971,11 +979,11 @@ async function discoverFromHealth(
971
979
  });
972
980
  })
973
981
  .filter((model): model is DiscoveredModel => model !== undefined);
974
- reportIncompatibleDeploymentModes(incompatibleModeRoutes);
975
- reportAmbiguousCatalogAuthority(ambiguousRoutes);
976
- reportConflictingFamilyEvidence(conflictingFamilyRoutes);
977
- reportWithheldToolRepair(withheldRepairRoutes);
978
- reportWithheldToolRepairForModels(discovered);
982
+ reportIncompatibleDeploymentModes(report, incompatibleModeRoutes);
983
+ reportAmbiguousCatalogAuthority(report, ambiguousRoutes);
984
+ reportConflictingFamilyEvidence(report, conflictingFamilyRoutes);
985
+ reportWithheldToolRepair(report, withheldRepairRoutes);
986
+ reportWithheldToolRepairForModels(report, discovered);
979
987
  return discovered;
980
988
  }
981
989
 
@@ -1210,10 +1218,11 @@ function mapFromWildcardExpansion(
1210
1218
  export async function discoverModels(
1211
1219
  baseUrl: string,
1212
1220
  apiKey: string,
1213
- options: DiscoveryOptions & { onProgress?: (message: string) => void; silent?: boolean } = {},
1221
+ options: DiscoveryOptions & { onProgress?: (message: string) => void; report?: Report; silent?: boolean } = {},
1214
1222
  ): Promise<DiscoveryResult> {
1215
1223
  const base = normalizeBaseUrl(baseUrl, options.allowInsecureHttp);
1216
1224
  const progress = options.silent ? undefined : options.onProgress;
1225
+ const report = options.report ?? writeStderr;
1217
1226
  progress?.("Querying /model/info endpoint...");
1218
1227
  const infoResult = await fetchJson<ModelInfoResponse>(`${base}/model/info`, apiKey, options);
1219
1228
  // An empty `/model/info` list is treated like an unavailable endpoint: some proxies
@@ -1265,10 +1274,10 @@ export async function discoverModels(
1265
1274
  let models = reducedGroups
1266
1275
  .map(({ model }) => model)
1267
1276
  .filter((model): model is DiscoveredModel => model !== undefined);
1268
- reportIncompatibleDeploymentModes(incompatibleModeRoutes);
1269
- reportAmbiguousCatalogAuthority(ambiguousRoutes);
1270
- reportConflictingFamilyEvidence(conflictingFamilyRoutes);
1271
- reportWithheldToolRepair(withheldRepairRoutes);
1277
+ reportIncompatibleDeploymentModes(report, incompatibleModeRoutes);
1278
+ reportAmbiguousCatalogAuthority(report, ambiguousRoutes);
1279
+ reportConflictingFamilyEvidence(report, conflictingFamilyRoutes);
1280
+ reportWithheldToolRepair(report, withheldRepairRoutes);
1272
1281
  // LiteLLM's /model/info does NOT expand wildcard model_name entries (e.g.
1273
1282
  // "lemonade/*" backed by model: openai/* + check_provider_endpoint: true)
1274
1283
  // — it returns the literal wildcard only. The discovered ids live in
@@ -1338,7 +1347,7 @@ export async function discoverModels(
1338
1347
  models = [...models, ...expanded];
1339
1348
  }
1340
1349
  }
1341
- reportWithheldToolRepair(withheldRepairRoutes);
1350
+ reportWithheldToolRepair(report, withheldRepairRoutes);
1342
1351
  models = deduplicateModels(models);
1343
1352
  if (process.env.LITELLM_VERBOSE_DISCOVERY === "1") {
1344
1353
  const defaultedWildcards = wildcardRoutes.filter(({ route }) => defaultedContextRoutes.has(route));
@@ -1352,6 +1361,7 @@ export async function discoverModels(
1352
1361
  ),
1353
1362
  );
1354
1363
  reportBoundedRoutes(
1364
+ report,
1355
1365
  reportedDefaultedContextRoutes,
1356
1366
  defaulted.map((model) => JSON.stringify(model.id)),
1357
1367
  (count) =>
@@ -1536,8 +1546,9 @@ function deploymentFamily(entry: ModelInfoEntry): CatalogResolution["semanticFam
1536
1546
  return adapterFamily === identityFamily ? identityFamily : "conflicting";
1537
1547
  }
1538
1548
 
1539
- function reportConflictingFamilyEvidence(routes: readonly string[]): void {
1549
+ function reportConflictingFamilyEvidence(report: Report, routes: readonly string[]): void {
1540
1550
  reportBoundedRoutes(
1551
+ report,
1541
1552
  reportedConflictingFamilyRoutes,
1542
1553
  routes,
1543
1554
  (count) =>
@@ -1546,8 +1557,9 @@ function reportConflictingFamilyEvidence(routes: readonly string[]): void {
1546
1557
  );
1547
1558
  }
1548
1559
 
1549
- function reportWithheldToolRepair(routes: readonly string[]): void {
1560
+ function reportWithheldToolRepair(report: Report, routes: readonly string[]): void {
1550
1561
  reportBoundedRoutes(
1562
+ report,
1551
1563
  reportedWithheldRepairRoutes,
1552
1564
  routes,
1553
1565
  (count) =>
@@ -1558,8 +1570,9 @@ function reportWithheldToolRepair(routes: readonly string[]): void {
1558
1570
  );
1559
1571
  }
1560
1572
 
1561
- function reportWithheldToolRepairForModels(models: readonly DiscoveredModel[]): void {
1573
+ function reportWithheldToolRepairForModels(report: Report, models: readonly DiscoveredModel[]): void {
1562
1574
  reportWithheldToolRepair(
1575
+ report,
1563
1576
  models
1564
1577
  .filter(
1565
1578
  (model) =>
package/src/index.ts CHANGED
@@ -67,6 +67,7 @@ const ENV_CLI_JWT_EXPIRATION_HOURS = "LITELLM_CLI_JWT_EXPIRATION_HOURS";
67
67
  const ENV_OFFLINE = "LITELLM_OFFLINE";
68
68
  const ENV_VERBOSE_DISCOVERY = "LITELLM_VERBOSE_DISCOVERY";
69
69
  const ENV_MODELS_DEV = "LITELLM_MODELS_DEV";
70
+ const ENV_STARTUP_KEY_HELPER = "LITELLM_STARTUP_KEY_HELPER";
70
71
  const MODELS_DEV_CACHE_FILENAME = "litellm-models-dev.json";
71
72
  const DEFAULT_TIMEOUT_MS = 5000;
72
73
  const SEED_TIMEOUT_MS = 3000;
@@ -2448,6 +2449,7 @@ export default async function (pi: ExtensionAPI): Promise<void> {
2448
2449
  let sessionStarted = false;
2449
2450
  const pendingMcpMessages = new Map<string, "info" | "warning">();
2450
2451
 
2452
+ // Also carries provider and discovery diagnostics: raw stderr would paint over the running TUI.
2451
2453
  function notifyMcp(message: string, level: "info" | "warning" = "warning"): void {
2452
2454
  const text = message.trimEnd();
2453
2455
  if (mcpUI) mcpUI.notify(text, level);
@@ -2700,6 +2702,7 @@ export default async function (pi: ExtensionAPI): Promise<void> {
2700
2702
  modelOverrides: await readModelLimitOverrides(),
2701
2703
  silent: !isVerboseDiscovery(),
2702
2704
  onProgress: isVerboseDiscovery() ? (message) => process.stderr.write(`LiteLLM: ${message}\n`) : undefined,
2705
+ report: (message) => notifyMcp(message),
2703
2706
  });
2704
2707
  signal?.throwIfAborted();
2705
2708
  return { ...result, baseUrl: normalizeBaseUrl(auth.baseUrl, auth.allowInsecureHttp) };
@@ -2727,9 +2730,9 @@ export default async function (pi: ExtensionAPI): Promise<void> {
2727
2730
  const agentDir = getAgentDir();
2728
2731
  try {
2729
2732
  const stored = readStoredCredential(definition.name, join(agentDir, "auth.json"));
2730
- // executeHelpers:false — activation must never run the user's key helper as a side effect,
2731
- // so helper-backed setups keep waiting for Pi's own refresh.
2732
- const auth = await authForCredential(definition, stored, false);
2733
+ // Activation must not run the user's key helper as a side effect, so helper-backed setups keep waiting
2734
+ // for Pi's own refresh; LITELLM_STARTUP_KEY_HELPER=1 is the launcher's opt-in to run it here.
2735
+ const auth = await authForCredential(definition, stored, process.env[ENV_STARTUP_KEY_HELPER] === "1");
2733
2736
  const storedModels = await readStoredModels({
2734
2737
  agentDir,
2735
2738
  provider: definition.name,
@@ -2823,6 +2826,7 @@ export default async function (pi: ExtensionAPI): Promise<void> {
2823
2826
  if (disabledReason) throw new Error(`discovery disabled (${disabledReason})`);
2824
2827
  return runDiscovery(await authForCredential(definition, credential), signal);
2825
2828
  },
2829
+ report: (message) => notifyMcp(message),
2826
2830
  });
2827
2831
  Object.assign(provider, { headers: resolveHeaders(definition) });
2828
2832
  const refreshModels = provider.refreshModels!;
package/src/provider.ts CHANGED
@@ -48,6 +48,8 @@ export type LiteLLMProviderOptions = {
48
48
  allowInsecureHttp?: boolean;
49
49
  resolveCredentialRoot: (credential?: Credential, requestBaseUrl?: string, apiKey?: string) => string | undefined;
50
50
  discover(credential: Credential, signal?: AbortSignal): Promise<DiscoveryResult & { baseUrl?: string }>;
51
+ /** Shows a diagnostic line. Defaults to stderr, which paints over Pi's TUI once it is running. */
52
+ report?: (message: string) => void;
51
53
  };
52
54
 
53
55
  // Chat models may omit `type`.
@@ -220,7 +222,9 @@ export function createLiteLLMProvider(options: LiteLLMProviderOptions): Provider
220
222
  const reportUnavailable = (message: string): void => {
221
223
  if (reportedAvailabilityDiagnostics.has(message)) return;
222
224
  reportedAvailabilityDiagnostics.add(message);
223
- process.stderr.write(`LiteLLM (${options.id}): ${message}\n`);
225
+ const line = `LiteLLM (${options.id}): ${message}`;
226
+ if (options.report) options.report(line);
227
+ else process.stderr.write(`${line}\n`);
224
228
  };
225
229
  type ActiveRoot = { root: string; canonical: string; hostname: string };
226
230
  const resolveActiveRoot = (credential: Credential | undefined, hiddenCount: number): ActiveRoot | undefined => {