@gullabs/xai 0.6.0 → 0.7.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
@@ -815,7 +815,7 @@ declare const xaiPricingVersion: "xai-2026-08-24";
815
815
  /**
816
816
  * Live-pinned 2026-08-24 per-invocation tool rates (µUSD per call).
817
817
  * Source: `usage.server_side_tool_usage_details` on /v1/responses.
818
- * $5 / 1,000 web or X searches; $10 / 1,000 attachment/document searches.
818
+ * $5 / 1,000 web or X searches. Attachment search is not priced until live-pinned.
819
819
  */
820
820
  declare const XAI_TOOL_RATE_MICRO_USD: {
821
821
  readonly web_search_calls: 5000;
@@ -875,10 +875,10 @@ declare const XAI_PRICING: Readonly<Record<string, XaiModelRates>>;
875
875
  * nearest integer micro-USD.
876
876
  * 6. `microUsd` is the sum of the four components — guarantees
877
877
  * `details.input + details.cached + details.output + details.tools === microUsd`.
878
- * 7. Tool lanes: live-pinned counters `web_search_calls`, `x_search_calls`,
879
- * `document_search_calls`. If `usage.details.server_tools_requested === 1`
880
- * and those counters are absent, token lanes are priced, `tools: 0`,
881
- * `confidence: 'estimated'`. `'exact'` requires counters present or no
878
+ * 7. Tool lanes: live-pinned counters `web_search_calls`, `x_search_calls`.
879
+ * Missing expected counters → `tools: 0`, `estimated`. File-ref sets
880
+ * `attachment_search_unpinned` → `estimated` (attachment not priced).
881
+ * `'exact'` requires no unpinned attachment and counters present or no
882
882
  * server tools requested.
883
883
  */
884
884
  declare function computeXaiCost(model: string, usage: Usage, tier?: string): Cost;
package/dist/index.d.ts CHANGED
@@ -815,7 +815,7 @@ declare const xaiPricingVersion: "xai-2026-08-24";
815
815
  /**
816
816
  * Live-pinned 2026-08-24 per-invocation tool rates (µUSD per call).
817
817
  * Source: `usage.server_side_tool_usage_details` on /v1/responses.
818
- * $5 / 1,000 web or X searches; $10 / 1,000 attachment/document searches.
818
+ * $5 / 1,000 web or X searches. Attachment search is not priced until live-pinned.
819
819
  */
820
820
  declare const XAI_TOOL_RATE_MICRO_USD: {
821
821
  readonly web_search_calls: 5000;
@@ -875,10 +875,10 @@ declare const XAI_PRICING: Readonly<Record<string, XaiModelRates>>;
875
875
  * nearest integer micro-USD.
876
876
  * 6. `microUsd` is the sum of the four components — guarantees
877
877
  * `details.input + details.cached + details.output + details.tools === microUsd`.
878
- * 7. Tool lanes: live-pinned counters `web_search_calls`, `x_search_calls`,
879
- * `document_search_calls`. If `usage.details.server_tools_requested === 1`
880
- * and those counters are absent, token lanes are priced, `tools: 0`,
881
- * `confidence: 'estimated'`. `'exact'` requires counters present or no
878
+ * 7. Tool lanes: live-pinned counters `web_search_calls`, `x_search_calls`.
879
+ * Missing expected counters → `tools: 0`, `estimated`. File-ref sets
880
+ * `attachment_search_unpinned` → `estimated` (attachment not priced).
881
+ * `'exact'` requires no unpinned attachment and counters present or no
882
882
  * server tools requested.
883
883
  */
884
884
  declare function computeXaiCost(model: string, usage: Usage, tier?: string): Cost;
package/dist/index.js CHANGED
@@ -556,6 +556,13 @@ function xaiAdapter(opts) {
556
556
  )}]; tool cost will be estimated.`
557
557
  });
558
558
  }
559
+ if (hasFileRef) {
560
+ usage.details["attachment_search_unpinned"] = 1;
561
+ warnings.push({
562
+ type: "other",
563
+ message: "xai: file-ref enables attachment_search but that counter is not live-pinned; tool cost is estimated."
564
+ });
565
+ }
559
566
  }
560
567
  const citations = collectXaiCitations(response, messageItems);
561
568
  const providerMeta = {};
@@ -1492,7 +1499,8 @@ function computeXaiCost(model, usage, tier) {
1492
1499
  usage.outputTokens * base.outputPerM * factor / 1e6
1493
1500
  );
1494
1501
  const serverToolsRequested = usage.details["server_tools_requested"] === 1;
1495
- const missingRequestedCounters = usage.details["server_tools_missing"] === 1 || serverToolsRequested && !XAI_TOOL_COUNTER_KEYS.some((key) => key in usage.details);
1502
+ const missingRequestedCounters = usage.details["server_tools_missing"] === 1 || serverToolsRequested && usage.details["attachment_search_unpinned"] !== 1 && !XAI_TOOL_COUNTER_KEYS.some((key) => key in usage.details);
1503
+ const attachmentUnpinned = usage.details["attachment_search_unpinned"] === 1;
1496
1504
  const toolsCost = missingRequestedCounters ? 0 : XAI_TOOL_COUNTER_KEYS.reduce((sum, key) => {
1497
1505
  const count = usage.details[key];
1498
1506
  if (typeof count !== "number" || count <= 0) return sum;
@@ -1503,7 +1511,7 @@ function computeXaiCost(model, usage, tier) {
1503
1511
  microUsd,
1504
1512
  usd: microUsd / 1e6,
1505
1513
  pricingVersion: xaiPricingVersion,
1506
- confidence: missingRequestedCounters ? "estimated" : "exact",
1514
+ confidence: missingRequestedCounters || attachmentUnpinned ? "estimated" : "exact",
1507
1515
  details: {
1508
1516
  input: inputCost,
1509
1517
  cached: cachedCost,