@extrafemi-ai/lodestone 0.3.0 → 0.3.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
@@ -60,6 +60,10 @@ A step with no key is skipped. A route skips the model lists and the catalogue,
60
60
 
61
61
  Keep a customer's own key out of any fallback step: build the route from their key only.
62
62
 
63
+ ### Your own key
64
+
65
+ Pass the customer's OpenRouter key as `apiKey` on a call. It replaces the platform's key, allows the paid fallback, and is never stored. The platform's `fallbacks` are **not** used on a call with a customer's own key (they carry the platform's money), unless a fallback sets `allowWithCallerKey`. Attempts that fail with 401, 402 or 403 are not counted in live stats, because they say nothing about the model.
66
+
63
67
  ### Phases
64
68
 
65
69
  For each call, in order, until one answers:
@@ -15,6 +15,8 @@ export interface FallbackConfig {
15
15
  apiKey: string;
16
16
  /** Tried in order. */
17
17
  models: string[];
18
+ /** Also use this provider when the caller supplied their own OpenRouter key. Default false: a fallback has the platform's key, and a caller's own key must never lead to the platform's money being spent. */
19
+ allowWithCallerKey?: boolean;
18
20
  }
19
21
  export interface AttemptEvent {
20
22
  provider: string;
package/dist/lodestone.js CHANGED
@@ -76,7 +76,7 @@ export function createLodestone(config = {}) {
76
76
  const left = () => budget - (now() - started);
77
77
  const orKey = opts.apiKey || config.openrouter?.apiKey;
78
78
  const paidAllowed = Boolean(opts.apiKey) || Boolean(config.openrouter?.allowPaid);
79
- const fbs = fallbacks.filter((f) => f.apiKey && (!images || f.provider.vision));
79
+ const fbs = fallbacks.filter((f) => f.apiKey && (!images || f.provider.vision) && (!opts.apiKey || f.allowWithCallerKey));
80
80
  const paidAvailable = Boolean(orKey) && paidAllowed && paidModels.length > 0;
81
81
  const later = paidAvailable || fbs.length > 0;
82
82
  const freeEnds = later ? t.freePhaseLater : budget;
@@ -109,7 +109,9 @@ export function createLodestone(config = {}) {
109
109
  out = { kind: 'fail', status: 599, body: e.message };
110
110
  }
111
111
  const event = { provider: provider.name, model, phase, outcome: out.kind === 'ok' ? 'ok' : out.kind === 'timeout' ? 'timeout' : 'failed', status: out.kind === 'fail' ? out.status : undefined, ms: now() - at };
112
- config.stats?.record(event);
112
+ // A key or credit problem (401, 402, 403) says nothing about the model, so it is not counted against it.
113
+ if (!(out.kind === 'fail' && [401, 402, 403].includes(out.status)))
114
+ config.stats?.record(event);
113
115
  config.onAttempt?.(event);
114
116
  last = out;
115
117
  return out;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@extrafemi-ai/lodestone",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Calls AI models so your tool keeps working when a model is withdrawn, slow or rate-limited.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -40,7 +40,7 @@
40
40
  "devDependencies": {
41
41
  "@types/node": "^22.10.0",
42
42
  "typescript": "^5.6.0",
43
- "vitest": "^2.1.0"
43
+ "vitest": "^4.1.12"
44
44
  },
45
45
  "keywords": [
46
46
  "ai",