pareta 2.0.0 → 2.1.0

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/dist/index.d.cts CHANGED
@@ -47,6 +47,17 @@ declare class ChatCompletion extends BaseModel {
47
47
  get created(): number | null;
48
48
  get choices(): Choice[];
49
49
  get usage(): Usage;
50
+ /** #164 receipt, held OFF `.raw` so `toDict()` stays the raw server JSON. */
51
+ private _cost?;
52
+ /** #164: attach the per-call receipt from the response headers (billed +
53
+ * the frontier counterfactual, micro-USD ints). Chainable. */
54
+ withCost(headers?: Headers): ChatCompletion;
55
+ /** What Pareta charged, micro-USD (0 on an idempotent replay); null if absent. */
56
+ get billedMicroUsd(): number | null;
57
+ /** What one list-priced frontier call would have cost, micro-USD. */
58
+ get frontierWouldHaveCostMicroUsd(): number | null;
59
+ /** frontier / billed — e.g. 17 = 17× cheaper; null if either is missing or billed is 0. */
60
+ get savingsFactor(): number | null;
50
61
  }
51
62
  /** One SSE delta. `chunk.choices[0].delta.content` is the incremental text. */
52
63
  declare class ChatCompletionChunk extends ChatCompletion {
@@ -632,6 +643,9 @@ interface RequestOptions {
632
643
  files?: Record<string, FilePart>;
633
644
  data?: Record<string, string>;
634
645
  cast?: (raw: unknown) => unknown;
646
+ /** Invoked with the response headers on success (before the body is cast) —
647
+ * lets a caller read receipt headers (#164: X-Pareta-Billed + counterfactual). */
648
+ onHeaders?: (headers: Headers) => void;
635
649
  }
636
650
  interface StreamOptions {
637
651
  body?: unknown;
@@ -698,7 +712,7 @@ declare class Pareta implements Transport {
698
712
  stream<T = unknown>(method: string, path: string, opts?: StreamOptions): AsyncGenerator<T>;
699
713
  }
700
714
 
701
- declare const VERSION = "2.0.0";
715
+ declare const VERSION = "2.1.0";
702
716
 
703
717
  /**
704
718
  * Typed error hierarchy for the Pareta SDK — a faithful port of the Python
package/dist/index.d.ts CHANGED
@@ -47,6 +47,17 @@ declare class ChatCompletion extends BaseModel {
47
47
  get created(): number | null;
48
48
  get choices(): Choice[];
49
49
  get usage(): Usage;
50
+ /** #164 receipt, held OFF `.raw` so `toDict()` stays the raw server JSON. */
51
+ private _cost?;
52
+ /** #164: attach the per-call receipt from the response headers (billed +
53
+ * the frontier counterfactual, micro-USD ints). Chainable. */
54
+ withCost(headers?: Headers): ChatCompletion;
55
+ /** What Pareta charged, micro-USD (0 on an idempotent replay); null if absent. */
56
+ get billedMicroUsd(): number | null;
57
+ /** What one list-priced frontier call would have cost, micro-USD. */
58
+ get frontierWouldHaveCostMicroUsd(): number | null;
59
+ /** frontier / billed — e.g. 17 = 17× cheaper; null if either is missing or billed is 0. */
60
+ get savingsFactor(): number | null;
50
61
  }
51
62
  /** One SSE delta. `chunk.choices[0].delta.content` is the incremental text. */
52
63
  declare class ChatCompletionChunk extends ChatCompletion {
@@ -632,6 +643,9 @@ interface RequestOptions {
632
643
  files?: Record<string, FilePart>;
633
644
  data?: Record<string, string>;
634
645
  cast?: (raw: unknown) => unknown;
646
+ /** Invoked with the response headers on success (before the body is cast) —
647
+ * lets a caller read receipt headers (#164: X-Pareta-Billed + counterfactual). */
648
+ onHeaders?: (headers: Headers) => void;
635
649
  }
636
650
  interface StreamOptions {
637
651
  body?: unknown;
@@ -698,7 +712,7 @@ declare class Pareta implements Transport {
698
712
  stream<T = unknown>(method: string, path: string, opts?: StreamOptions): AsyncGenerator<T>;
699
713
  }
700
714
 
701
- declare const VERSION = "2.0.0";
715
+ declare const VERSION = "2.1.0";
702
716
 
703
717
  /**
704
718
  * Typed error hierarchy for the Pareta SDK — a faithful port of the Python
package/dist/index.mjs CHANGED
@@ -172,7 +172,7 @@ function parseSSE(reader, opts) {
172
172
  }
173
173
 
174
174
  // src/version.ts
175
- var VERSION = "2.0.0";
175
+ var VERSION = "2.1.0";
176
176
 
177
177
  // src/money.ts
178
178
  var MICRO_PER_CENT = 10000n;
@@ -253,6 +253,36 @@ var ChatCompletion = class extends BaseModel {
253
253
  get usage() {
254
254
  return new Usage(this.raw.usage ?? {});
255
255
  }
256
+ /** #164 receipt, held OFF `.raw` so `toDict()` stays the raw server JSON. */
257
+ _cost;
258
+ /** #164: attach the per-call receipt from the response headers (billed +
259
+ * the frontier counterfactual, micro-USD ints). Chainable. */
260
+ withCost(headers) {
261
+ const int = (name) => {
262
+ const v = headers?.get(name);
263
+ if (v == null) return null;
264
+ const n = parseInt(v, 10);
265
+ return Number.isNaN(n) ? null : n;
266
+ };
267
+ this._cost = {
268
+ billed: int("X-Pareta-Billed"),
269
+ frontier: int("X-Pareta-Frontier-Would-Have-Cost")
270
+ };
271
+ return this;
272
+ }
273
+ /** What Pareta charged, micro-USD (0 on an idempotent replay); null if absent. */
274
+ get billedMicroUsd() {
275
+ return this._cost?.billed ?? null;
276
+ }
277
+ /** What one list-priced frontier call would have cost, micro-USD. */
278
+ get frontierWouldHaveCostMicroUsd() {
279
+ return this._cost?.frontier ?? null;
280
+ }
281
+ /** frontier / billed — e.g. 17 = 17× cheaper; null if either is missing or billed is 0. */
282
+ get savingsFactor() {
283
+ const b = this.billedMicroUsd, f = this.frontierWouldHaveCostMicroUsd;
284
+ return b && f && b > 0 ? Math.round(f / b * 10) / 10 : null;
285
+ }
256
286
  };
257
287
  var ChatCompletionChunk = class extends ChatCompletion {
258
288
  };
@@ -642,10 +672,14 @@ var Completions = class {
642
672
  cast: (raw) => new ChatCompletionChunk(raw)
643
673
  });
644
674
  }
675
+ let headers;
645
676
  return this.client.request("POST", PATH, {
646
677
  body,
647
- cast: (raw) => new ChatCompletion(raw)
648
- });
678
+ cast: (raw) => new ChatCompletion(raw),
679
+ onHeaders: (h) => {
680
+ headers = h;
681
+ }
682
+ }).then((completion) => completion.withCost(headers));
649
683
  }
650
684
  };
651
685
  var Chat = class {
@@ -1308,6 +1342,7 @@ var Pareta = class _Pareta {
1308
1342
  break;
1309
1343
  }
1310
1344
  if (res.ok) {
1345
+ if (opts.onHeaders) opts.onHeaders(res.headers);
1311
1346
  const text = await res.text();
1312
1347
  const raw = text ? JSON.parse(text) : {};
1313
1348
  return cast ? cast(raw) : raw;