@gullabs/xai 0.4.0 → 0.5.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
@@ -99,7 +99,7 @@ interface XaiResponseCreateParams {
99
99
  input: XaiInputItem[];
100
100
  instructions?: string;
101
101
  reasoning?: {
102
- effort: 'low' | 'high';
102
+ effort: 'low' | 'medium' | 'high' | 'xhigh';
103
103
  };
104
104
  text?: {
105
105
  format: XaiTextFormat;
@@ -108,6 +108,11 @@ interface XaiResponseCreateParams {
108
108
  top_p?: number;
109
109
  max_output_tokens?: number;
110
110
  prompt_cache_key?: string;
111
+ /**
112
+ * Responses `service_tier`. Only `'priority'` is forwarded (live-verified
113
+ * on grok-4.6, 2026-08-12). Omitted when the caller did not request a tier.
114
+ */
115
+ service_tier?: 'priority';
111
116
  /** Always `false` — this library never relies on xAI-side conversation storage. */
112
117
  store: false;
113
118
  }
@@ -181,6 +186,11 @@ interface XaiResponseShape {
181
186
  effort?: string;
182
187
  summary?: string;
183
188
  };
189
+ /**
190
+ * Echoed served tier. Observed values: `"default"`, `"priority"`.
191
+ * Kept as a plain string — xAI may add further values.
192
+ */
193
+ service_tier?: string;
184
194
  store?: boolean;
185
195
  prompt_cache_key?: string | null;
186
196
  /**
@@ -446,19 +456,53 @@ declare const Grok45ConfigSchema: z.ZodObject<{
446
456
  }, z.core.$strict>>;
447
457
  }, z.core.$strict>;
448
458
 
459
+ /**
460
+ * Strict Zod config schema for xAI's `grok-4.6` model.
461
+ *
462
+ * Same Responses-API surface as grok-4.5, plus live-verified (2026-08-12)
463
+ * `reasoning.effort` of `'low' | 'medium' | 'high' | 'xhigh'` and
464
+ * `serviceTier: 'priority'`. `'none'` is rejected by the live API. Unknown
465
+ * tiers (`flex`, `standard`, `batch`) are rejected — `flex` is silently
466
+ * remapped to `default` by xAI, so this schema never admits it.
467
+ *
468
+ * @module
469
+ */
470
+
471
+ declare const Grok46ConfigSchema: z.ZodObject<{
472
+ temperature: z.ZodOptional<z.ZodNumber>;
473
+ topP: z.ZodOptional<z.ZodNumber>;
474
+ maxOutputTokens: z.ZodOptional<z.ZodNumber>;
475
+ reasoning: z.ZodOptional<z.ZodObject<{
476
+ effort: z.ZodEnum<{
477
+ low: "low";
478
+ medium: "medium";
479
+ high: "high";
480
+ xhigh: "xhigh";
481
+ }>;
482
+ }, z.core.$strict>>;
483
+ serviceTier: z.ZodOptional<z.ZodLiteral<"priority">>;
484
+ timeoutMs: z.ZodOptional<z.ZodNumber>;
485
+ providerOptions: z.ZodOptional<z.ZodObject<{
486
+ xai: z.ZodOptional<z.ZodObject<{
487
+ promptCacheKey: z.ZodOptional<z.ZodString>;
488
+ }, z.core.$strict>>;
489
+ }, z.core.$strict>>;
490
+ }, z.core.$strict>;
491
+
449
492
  /**
450
493
  * Model descriptor + registry for @gullabs/xai.
451
494
  *
452
- * v1 ships exactly one model: `grok-4.5` (canonical id only — the
453
- * `grok-4.5-latest` / `grok-build-latest` aliases visible in xAI's
454
- * `/v1/models` listing are intentionally NOT registered as separate
455
- * descriptors; reject-don't-map, callers must use `grok-4.5` verbatim).
495
+ * Ships two canonical models: `grok-4.5` and `grok-4.6`. xAI aliases
496
+ * (`grok-4.5-latest`, `grok-build-latest`) visible in `/v1/models` are
497
+ * intentionally NOT registered (reject-don't-map). `grok-4.6` has no
498
+ * aliases as of the 2026-08-12 `/v1/models` listing.
456
499
  *
457
500
  * @module
458
501
  */
459
502
 
460
503
  declare const grok45ModelDescriptor: ModelDescriptor;
461
- /** Every model descriptor `@gullabs/xai` contributes. v1 ships only grok-4.5. */
504
+ declare const grok46ModelDescriptor: ModelDescriptor;
505
+ /** Every model descriptor `@gullabs/xai` contributes. */
462
506
  declare const xaiModelDescriptors: ModelDescriptor[];
463
507
  declare const xaiRegistry: ModelRegistry;
464
508
 
@@ -474,35 +518,33 @@ declare const xaiRegistry: ModelRegistry;
474
518
  * (those are Gemini-only). `PricingSource` is provider-scoped by contract
475
519
  * (see `packages/core/src/ports.ts`); this module is xai's own.
476
520
  *
477
- * **Long-context tier.** grok-4.5 charges a premium when the GROSS input
478
- * token count exceeds 200,000 (`long_context_threshold` in xAI's
521
+ * **Long-context tier.** grok-4.5 / grok-4.6 charge a premium when the GROSS
522
+ * input token count exceeds 200,000 (`long_context_threshold` in xAI's
479
523
  * `/v1/models` listing). Selected by `inputTokens` (incl. cached), not by
480
524
  * billable input — mirrors core's `selectRates` convention exactly (strictly
481
525
  * greater than 200,000).
482
526
  *
483
- * **Service tiers.** xAI has no service-tier concept for grok-4.5 — there is
484
- * no `TIER_FACTOR`-equivalent here. `price()`'s `tier` param is accepted for
485
- * `PricingSource` structural conformance but any *defined* tier is treated
486
- * as unrecognized → unpriced (reject-don't-map), mirroring core's own
487
- * defensive stance for an unrecognized tier. `undefined` (no tier requested,
488
- * the only value xAI adapters ever pass — `xaiAdapter` rejects `serviceTier`
489
- * upstream) prices normally.
527
+ * **Service tiers.** grok-4.5 has none. grok-4.6 admits `'priority'`
528
+ * (echo live-verified 2026-08-12). The 2× multiplier is confirmed by
529
+ * fixture `12-grok-4-6-xhigh-priority.json` (`cost_in_usd_ticks` equals
530
+ * exactly 2× standard list). `'default'` (the value xAI echoes when no
531
+ * priority is served) and `undefined` (no tier requested) price at the
532
+ * standard list. Any other defined tier is unpriced (reject-don't-map).
490
533
  *
491
534
  * **Conversion factor.** xAI's `/v1/models` raw `*_token_price` fields are
492
535
  * in hundred-thousandths of a dollar per token (i.e. divide the raw integer
493
- * by 10,000 to get USD per million tokens): e.g. `grok-4.5`'s raw
494
- * `prompt_text_token_price: 20000` ÷ 10,000 = $2.00/M, which matches the
495
- * confirmed live-verified figure.
536
+ * by 10,000 to get USD per million tokens): e.g. `grok-4.6`'s raw
537
+ * `prompt_text_token_price: 20000` ÷ 10,000 = $2.00/M.
496
538
  *
497
- * Verified against `/v1/models` fixture captured 2026-07-09 (see
498
- * `docs/provider-plugins-and-xai-grok-4-5-plan.md` and the live-verification
499
- * fixture directory referenced in the commit-3 task brief).
539
+ * Verified against `/v1/models` on 2026-08-12. Prior snapshot
540
+ * `xai-2026-07-09` priced grok-4.5 cached input at $0.50 / $1.00; the live
541
+ * listing now reports $0.30 / $0.60.
500
542
  *
501
543
  * @module
502
544
  */
503
545
 
504
546
  /** Identifies this pricing snapshot — bump the date when rates change. */
505
- declare const xaiPricingVersion: "xai-2026-07-09";
547
+ declare const xaiPricingVersion: "xai-2026-08-12";
506
548
  /**
507
549
  * Per-model rate entry (all values in µUSD per million tokens).
508
550
  *
@@ -521,6 +563,14 @@ interface XaiModelRates {
521
563
  cachedPerM: number;
522
564
  outputPerM: number;
523
565
  };
566
+ /**
567
+ * Multiplier for Responses `service_tier: "priority"`. Absent = this
568
+ * model does not admit priority (unpriced). Uncached standard-list 2×
569
+ * is confirmed by fixture `12-grok-4-6-xhigh-priority.json` ticks;
570
+ * cached and `gt200k` legs follow the official 2×-after-cache-discount
571
+ * docs rule (that fixture has cached=0 and input < 200k).
572
+ */
573
+ priorityFactor?: number;
524
574
  }
525
575
  /**
526
576
  * Frozen xAI pricing snapshot (per-1M in µUSD).
@@ -539,8 +589,10 @@ declare const XAI_PRICING: Readonly<Record<string, XaiModelRates>>;
539
589
  * **Algorithm** (mirrors `@gullabs/core`'s `computeCost` exactly, xai-owned):
540
590
  * 1. Look up rates for `model`; if not found, return an unpriced `Cost`
541
591
  * (`microUsd: null`) naming the model.
542
- * 2. A defined `tier` is always unpriced (xai has no tiers; reject-don't-map).
543
- * `undefined` prices normally.
592
+ * 2. `undefined` or `'default'` prices at the standard list.
593
+ * `'priority'` applies `rates.priorityFactor` when present.
594
+ * Any other defined tier, or `'priority'` on a model without
595
+ * `priorityFactor`, is unpriced (reject-don't-map).
544
596
  * 3. Select base vs. `>200k` long-context rates from GROSS `inputTokens`.
545
597
  * 4. Billable input = `inputTokens − (cachedInputTokens ?? 0)`, clamped to 0.
546
598
  * 5. Round each component (input, cached, output) independently to the
@@ -558,7 +610,7 @@ declare function computeXaiCost(model: string, usage: Usage, tier?: string): Cos
558
610
  * import { xaiPricingSource } from '@gullabs/xai'
559
611
  *
560
612
  * const pricing = xaiPricingSource()
561
- * const cost = pricing.price('grok-4.5', usage)
613
+ * const cost = pricing.price('grok-4.6', usage)
562
614
  * ```
563
615
  */
564
616
  declare function xaiPricingSource(): PricingSource;
@@ -566,8 +618,9 @@ declare function xaiPricingSource(): PricingSource;
566
618
  /**
567
619
  * `xaiProvider` — {@link ProviderPlugin} factory for @gullabs/xai.
568
620
  *
569
- * Bundles the xAI Grok adapter, the `grok-4.5` model descriptor, and the
570
- * xai pricing source into a single plugin for {@link composeProviders}.
621
+ * Bundles the xAI Grok adapter, the `grok-4.5` / `grok-4.6` model
622
+ * descriptors, and the xai pricing source into a single plugin for
623
+ * {@link composeProviders}.
571
624
  *
572
625
  * @module
573
626
  */
@@ -576,8 +629,8 @@ declare function xaiPricingSource(): PricingSource;
576
629
  * Create a {@link ProviderPlugin} for the xAI Grok provider.
577
630
  *
578
631
  * @param opts - Forwarded to {@link xaiAdapter}.
579
- * @returns A plugin bundling the xAI adapter, the `grok-4.5` model
580
- * descriptor, and the built-in xai pricing source.
632
+ * @returns A plugin bundling the xAI adapter, the `grok-4.5` / `grok-4.6`
633
+ * model descriptors, and the built-in xai pricing source.
581
634
  *
582
635
  * @example
583
636
  * ```ts
@@ -591,4 +644,4 @@ declare function xaiPricingSource(): PricingSource;
591
644
  */
592
645
  declare function xaiProvider(opts?: XaiAdapterOptions): ProviderPlugin;
593
646
 
594
- export { type FileDeleteOptions, Grok45ConfigSchema, XAI_FILES_DEFAULT_BASE_URL, XAI_FILE_MAX_BYTES, XAI_FILE_TTL_MAX_SECONDS, XAI_FILE_TTL_MIN_SECONDS, XAI_PRICING, type XaiAdapterOptions, type XaiClientLike, type XaiFileHandle, type XaiFileListOptions, type XaiFileListResult, XaiFileStore, type XaiFileStoreOptions, type XaiFileUploadInput, type XaiInputContentPart, type XaiInputFilePart, type XaiInputImagePart, type XaiInputItem, type XaiInputTextPart, type XaiMessageOutputItem, type XaiModelRates, type XaiOutputItem, type XaiOutputTextPart, type XaiProviderOptions, type XaiReasoningOutputItem, type XaiReasoningSummaryPart, type XaiResponseCreateParams, type XaiResponseShape, type XaiTextFormat, type XaiUsageShape, buildXaiClient, classifyXaiError, computeXaiCost, grok45ModelDescriptor, requireApiKey, xaiAdapter, xaiModelDescriptors, xaiPricingSource, xaiPricingVersion, xaiProvider, xaiRegistry };
647
+ export { type FileDeleteOptions, Grok45ConfigSchema, Grok46ConfigSchema, XAI_FILES_DEFAULT_BASE_URL, XAI_FILE_MAX_BYTES, XAI_FILE_TTL_MAX_SECONDS, XAI_FILE_TTL_MIN_SECONDS, XAI_PRICING, type XaiAdapterOptions, type XaiClientLike, type XaiFileHandle, type XaiFileListOptions, type XaiFileListResult, XaiFileStore, type XaiFileStoreOptions, type XaiFileUploadInput, type XaiInputContentPart, type XaiInputFilePart, type XaiInputImagePart, type XaiInputItem, type XaiInputTextPart, type XaiMessageOutputItem, type XaiModelRates, type XaiOutputItem, type XaiOutputTextPart, type XaiProviderOptions, type XaiReasoningOutputItem, type XaiReasoningSummaryPart, type XaiResponseCreateParams, type XaiResponseShape, type XaiTextFormat, type XaiUsageShape, buildXaiClient, classifyXaiError, computeXaiCost, grok45ModelDescriptor, grok46ModelDescriptor, requireApiKey, xaiAdapter, xaiModelDescriptors, xaiPricingSource, xaiPricingVersion, xaiProvider, xaiRegistry };
package/dist/index.d.ts CHANGED
@@ -99,7 +99,7 @@ interface XaiResponseCreateParams {
99
99
  input: XaiInputItem[];
100
100
  instructions?: string;
101
101
  reasoning?: {
102
- effort: 'low' | 'high';
102
+ effort: 'low' | 'medium' | 'high' | 'xhigh';
103
103
  };
104
104
  text?: {
105
105
  format: XaiTextFormat;
@@ -108,6 +108,11 @@ interface XaiResponseCreateParams {
108
108
  top_p?: number;
109
109
  max_output_tokens?: number;
110
110
  prompt_cache_key?: string;
111
+ /**
112
+ * Responses `service_tier`. Only `'priority'` is forwarded (live-verified
113
+ * on grok-4.6, 2026-08-12). Omitted when the caller did not request a tier.
114
+ */
115
+ service_tier?: 'priority';
111
116
  /** Always `false` — this library never relies on xAI-side conversation storage. */
112
117
  store: false;
113
118
  }
@@ -181,6 +186,11 @@ interface XaiResponseShape {
181
186
  effort?: string;
182
187
  summary?: string;
183
188
  };
189
+ /**
190
+ * Echoed served tier. Observed values: `"default"`, `"priority"`.
191
+ * Kept as a plain string — xAI may add further values.
192
+ */
193
+ service_tier?: string;
184
194
  store?: boolean;
185
195
  prompt_cache_key?: string | null;
186
196
  /**
@@ -446,19 +456,53 @@ declare const Grok45ConfigSchema: z.ZodObject<{
446
456
  }, z.core.$strict>>;
447
457
  }, z.core.$strict>;
448
458
 
459
+ /**
460
+ * Strict Zod config schema for xAI's `grok-4.6` model.
461
+ *
462
+ * Same Responses-API surface as grok-4.5, plus live-verified (2026-08-12)
463
+ * `reasoning.effort` of `'low' | 'medium' | 'high' | 'xhigh'` and
464
+ * `serviceTier: 'priority'`. `'none'` is rejected by the live API. Unknown
465
+ * tiers (`flex`, `standard`, `batch`) are rejected — `flex` is silently
466
+ * remapped to `default` by xAI, so this schema never admits it.
467
+ *
468
+ * @module
469
+ */
470
+
471
+ declare const Grok46ConfigSchema: z.ZodObject<{
472
+ temperature: z.ZodOptional<z.ZodNumber>;
473
+ topP: z.ZodOptional<z.ZodNumber>;
474
+ maxOutputTokens: z.ZodOptional<z.ZodNumber>;
475
+ reasoning: z.ZodOptional<z.ZodObject<{
476
+ effort: z.ZodEnum<{
477
+ low: "low";
478
+ medium: "medium";
479
+ high: "high";
480
+ xhigh: "xhigh";
481
+ }>;
482
+ }, z.core.$strict>>;
483
+ serviceTier: z.ZodOptional<z.ZodLiteral<"priority">>;
484
+ timeoutMs: z.ZodOptional<z.ZodNumber>;
485
+ providerOptions: z.ZodOptional<z.ZodObject<{
486
+ xai: z.ZodOptional<z.ZodObject<{
487
+ promptCacheKey: z.ZodOptional<z.ZodString>;
488
+ }, z.core.$strict>>;
489
+ }, z.core.$strict>>;
490
+ }, z.core.$strict>;
491
+
449
492
  /**
450
493
  * Model descriptor + registry for @gullabs/xai.
451
494
  *
452
- * v1 ships exactly one model: `grok-4.5` (canonical id only — the
453
- * `grok-4.5-latest` / `grok-build-latest` aliases visible in xAI's
454
- * `/v1/models` listing are intentionally NOT registered as separate
455
- * descriptors; reject-don't-map, callers must use `grok-4.5` verbatim).
495
+ * Ships two canonical models: `grok-4.5` and `grok-4.6`. xAI aliases
496
+ * (`grok-4.5-latest`, `grok-build-latest`) visible in `/v1/models` are
497
+ * intentionally NOT registered (reject-don't-map). `grok-4.6` has no
498
+ * aliases as of the 2026-08-12 `/v1/models` listing.
456
499
  *
457
500
  * @module
458
501
  */
459
502
 
460
503
  declare const grok45ModelDescriptor: ModelDescriptor;
461
- /** Every model descriptor `@gullabs/xai` contributes. v1 ships only grok-4.5. */
504
+ declare const grok46ModelDescriptor: ModelDescriptor;
505
+ /** Every model descriptor `@gullabs/xai` contributes. */
462
506
  declare const xaiModelDescriptors: ModelDescriptor[];
463
507
  declare const xaiRegistry: ModelRegistry;
464
508
 
@@ -474,35 +518,33 @@ declare const xaiRegistry: ModelRegistry;
474
518
  * (those are Gemini-only). `PricingSource` is provider-scoped by contract
475
519
  * (see `packages/core/src/ports.ts`); this module is xai's own.
476
520
  *
477
- * **Long-context tier.** grok-4.5 charges a premium when the GROSS input
478
- * token count exceeds 200,000 (`long_context_threshold` in xAI's
521
+ * **Long-context tier.** grok-4.5 / grok-4.6 charge a premium when the GROSS
522
+ * input token count exceeds 200,000 (`long_context_threshold` in xAI's
479
523
  * `/v1/models` listing). Selected by `inputTokens` (incl. cached), not by
480
524
  * billable input — mirrors core's `selectRates` convention exactly (strictly
481
525
  * greater than 200,000).
482
526
  *
483
- * **Service tiers.** xAI has no service-tier concept for grok-4.5 — there is
484
- * no `TIER_FACTOR`-equivalent here. `price()`'s `tier` param is accepted for
485
- * `PricingSource` structural conformance but any *defined* tier is treated
486
- * as unrecognized → unpriced (reject-don't-map), mirroring core's own
487
- * defensive stance for an unrecognized tier. `undefined` (no tier requested,
488
- * the only value xAI adapters ever pass — `xaiAdapter` rejects `serviceTier`
489
- * upstream) prices normally.
527
+ * **Service tiers.** grok-4.5 has none. grok-4.6 admits `'priority'`
528
+ * (echo live-verified 2026-08-12). The 2× multiplier is confirmed by
529
+ * fixture `12-grok-4-6-xhigh-priority.json` (`cost_in_usd_ticks` equals
530
+ * exactly 2× standard list). `'default'` (the value xAI echoes when no
531
+ * priority is served) and `undefined` (no tier requested) price at the
532
+ * standard list. Any other defined tier is unpriced (reject-don't-map).
490
533
  *
491
534
  * **Conversion factor.** xAI's `/v1/models` raw `*_token_price` fields are
492
535
  * in hundred-thousandths of a dollar per token (i.e. divide the raw integer
493
- * by 10,000 to get USD per million tokens): e.g. `grok-4.5`'s raw
494
- * `prompt_text_token_price: 20000` ÷ 10,000 = $2.00/M, which matches the
495
- * confirmed live-verified figure.
536
+ * by 10,000 to get USD per million tokens): e.g. `grok-4.6`'s raw
537
+ * `prompt_text_token_price: 20000` ÷ 10,000 = $2.00/M.
496
538
  *
497
- * Verified against `/v1/models` fixture captured 2026-07-09 (see
498
- * `docs/provider-plugins-and-xai-grok-4-5-plan.md` and the live-verification
499
- * fixture directory referenced in the commit-3 task brief).
539
+ * Verified against `/v1/models` on 2026-08-12. Prior snapshot
540
+ * `xai-2026-07-09` priced grok-4.5 cached input at $0.50 / $1.00; the live
541
+ * listing now reports $0.30 / $0.60.
500
542
  *
501
543
  * @module
502
544
  */
503
545
 
504
546
  /** Identifies this pricing snapshot — bump the date when rates change. */
505
- declare const xaiPricingVersion: "xai-2026-07-09";
547
+ declare const xaiPricingVersion: "xai-2026-08-12";
506
548
  /**
507
549
  * Per-model rate entry (all values in µUSD per million tokens).
508
550
  *
@@ -521,6 +563,14 @@ interface XaiModelRates {
521
563
  cachedPerM: number;
522
564
  outputPerM: number;
523
565
  };
566
+ /**
567
+ * Multiplier for Responses `service_tier: "priority"`. Absent = this
568
+ * model does not admit priority (unpriced). Uncached standard-list 2×
569
+ * is confirmed by fixture `12-grok-4-6-xhigh-priority.json` ticks;
570
+ * cached and `gt200k` legs follow the official 2×-after-cache-discount
571
+ * docs rule (that fixture has cached=0 and input < 200k).
572
+ */
573
+ priorityFactor?: number;
524
574
  }
525
575
  /**
526
576
  * Frozen xAI pricing snapshot (per-1M in µUSD).
@@ -539,8 +589,10 @@ declare const XAI_PRICING: Readonly<Record<string, XaiModelRates>>;
539
589
  * **Algorithm** (mirrors `@gullabs/core`'s `computeCost` exactly, xai-owned):
540
590
  * 1. Look up rates for `model`; if not found, return an unpriced `Cost`
541
591
  * (`microUsd: null`) naming the model.
542
- * 2. A defined `tier` is always unpriced (xai has no tiers; reject-don't-map).
543
- * `undefined` prices normally.
592
+ * 2. `undefined` or `'default'` prices at the standard list.
593
+ * `'priority'` applies `rates.priorityFactor` when present.
594
+ * Any other defined tier, or `'priority'` on a model without
595
+ * `priorityFactor`, is unpriced (reject-don't-map).
544
596
  * 3. Select base vs. `>200k` long-context rates from GROSS `inputTokens`.
545
597
  * 4. Billable input = `inputTokens − (cachedInputTokens ?? 0)`, clamped to 0.
546
598
  * 5. Round each component (input, cached, output) independently to the
@@ -558,7 +610,7 @@ declare function computeXaiCost(model: string, usage: Usage, tier?: string): Cos
558
610
  * import { xaiPricingSource } from '@gullabs/xai'
559
611
  *
560
612
  * const pricing = xaiPricingSource()
561
- * const cost = pricing.price('grok-4.5', usage)
613
+ * const cost = pricing.price('grok-4.6', usage)
562
614
  * ```
563
615
  */
564
616
  declare function xaiPricingSource(): PricingSource;
@@ -566,8 +618,9 @@ declare function xaiPricingSource(): PricingSource;
566
618
  /**
567
619
  * `xaiProvider` — {@link ProviderPlugin} factory for @gullabs/xai.
568
620
  *
569
- * Bundles the xAI Grok adapter, the `grok-4.5` model descriptor, and the
570
- * xai pricing source into a single plugin for {@link composeProviders}.
621
+ * Bundles the xAI Grok adapter, the `grok-4.5` / `grok-4.6` model
622
+ * descriptors, and the xai pricing source into a single plugin for
623
+ * {@link composeProviders}.
571
624
  *
572
625
  * @module
573
626
  */
@@ -576,8 +629,8 @@ declare function xaiPricingSource(): PricingSource;
576
629
  * Create a {@link ProviderPlugin} for the xAI Grok provider.
577
630
  *
578
631
  * @param opts - Forwarded to {@link xaiAdapter}.
579
- * @returns A plugin bundling the xAI adapter, the `grok-4.5` model
580
- * descriptor, and the built-in xai pricing source.
632
+ * @returns A plugin bundling the xAI adapter, the `grok-4.5` / `grok-4.6`
633
+ * model descriptors, and the built-in xai pricing source.
581
634
  *
582
635
  * @example
583
636
  * ```ts
@@ -591,4 +644,4 @@ declare function xaiPricingSource(): PricingSource;
591
644
  */
592
645
  declare function xaiProvider(opts?: XaiAdapterOptions): ProviderPlugin;
593
646
 
594
- export { type FileDeleteOptions, Grok45ConfigSchema, XAI_FILES_DEFAULT_BASE_URL, XAI_FILE_MAX_BYTES, XAI_FILE_TTL_MAX_SECONDS, XAI_FILE_TTL_MIN_SECONDS, XAI_PRICING, type XaiAdapterOptions, type XaiClientLike, type XaiFileHandle, type XaiFileListOptions, type XaiFileListResult, XaiFileStore, type XaiFileStoreOptions, type XaiFileUploadInput, type XaiInputContentPart, type XaiInputFilePart, type XaiInputImagePart, type XaiInputItem, type XaiInputTextPart, type XaiMessageOutputItem, type XaiModelRates, type XaiOutputItem, type XaiOutputTextPart, type XaiProviderOptions, type XaiReasoningOutputItem, type XaiReasoningSummaryPart, type XaiResponseCreateParams, type XaiResponseShape, type XaiTextFormat, type XaiUsageShape, buildXaiClient, classifyXaiError, computeXaiCost, grok45ModelDescriptor, requireApiKey, xaiAdapter, xaiModelDescriptors, xaiPricingSource, xaiPricingVersion, xaiProvider, xaiRegistry };
647
+ export { type FileDeleteOptions, Grok45ConfigSchema, Grok46ConfigSchema, XAI_FILES_DEFAULT_BASE_URL, XAI_FILE_MAX_BYTES, XAI_FILE_TTL_MAX_SECONDS, XAI_FILE_TTL_MIN_SECONDS, XAI_PRICING, type XaiAdapterOptions, type XaiClientLike, type XaiFileHandle, type XaiFileListOptions, type XaiFileListResult, XaiFileStore, type XaiFileStoreOptions, type XaiFileUploadInput, type XaiInputContentPart, type XaiInputFilePart, type XaiInputImagePart, type XaiInputItem, type XaiInputTextPart, type XaiMessageOutputItem, type XaiModelRates, type XaiOutputItem, type XaiOutputTextPart, type XaiProviderOptions, type XaiReasoningOutputItem, type XaiReasoningSummaryPart, type XaiResponseCreateParams, type XaiResponseShape, type XaiTextFormat, type XaiUsageShape, buildXaiClient, classifyXaiError, computeXaiCost, grok45ModelDescriptor, grok46ModelDescriptor, requireApiKey, xaiAdapter, xaiModelDescriptors, xaiPricingSource, xaiPricingVersion, xaiProvider, xaiRegistry };
package/dist/index.js CHANGED
@@ -260,10 +260,19 @@ function xaiAdapter(opts) {
260
260
  if (genConfig.maxOutputTokens !== void 0) {
261
261
  params.max_output_tokens = genConfig.maxOutputTokens;
262
262
  }
263
+ const admittedTiers = req.modelDescriptor?.capabilities?.serviceTiers;
263
264
  if (genConfig.serviceTier !== void 0) {
264
- throw badXaiRequest(
265
- `serviceTier is not supported for xai models (got "${genConfig.serviceTier}").`
266
- );
265
+ if (admittedTiers === void 0 || !admittedTiers.includes(genConfig.serviceTier)) {
266
+ throw badXaiRequest(
267
+ `serviceTier is not supported for xai model "${model}" (got "${genConfig.serviceTier}").`
268
+ );
269
+ }
270
+ if (genConfig.serviceTier !== "priority") {
271
+ throw badXaiRequest(
272
+ `serviceTier "${genConfig.serviceTier}" is not supported for xai model "${model}" (only "priority" is admitted).`
273
+ );
274
+ }
275
+ params.service_tier = "priority";
267
276
  }
268
277
  const reasoning = genConfig.reasoning;
269
278
  if (reasoning !== void 0) {
@@ -274,13 +283,13 @@ function xaiAdapter(opts) {
274
283
  }
275
284
  if (reasoning.effort !== void 0) {
276
285
  const effort = reasoning.effort;
277
- if (effort !== "low" && effort !== "high") {
286
+ if (effort === "none") {
278
287
  throw badXaiRequest(
279
- `reasoning.effort "${effort}" is not supported for xai model "${model}" (only "low" and "high" are admitted).`
288
+ `reasoning.effort "none" is not supported for xai model "${model}".`
280
289
  );
281
290
  }
282
291
  const admitted = req.modelDescriptor?.capabilities?.admittedReasoningEfforts;
283
- if (admitted !== void 0 && !admitted.includes(effort)) {
292
+ if (admitted === void 0 || !admitted.includes(effort)) {
284
293
  throw badXaiRequest(
285
294
  `reasoning.effort "${effort}" is not supported for xai model "${model}".`
286
295
  );
@@ -358,6 +367,7 @@ function xaiAdapter(opts) {
358
367
  if (isPlainRecord(response.metadata)) {
359
368
  providerMeta["metadata"] = response.metadata;
360
369
  }
370
+ const servedServiceTier = typeof response.service_tier === "string" && response.service_tier.length > 0 ? response.service_tier : void 0;
361
371
  const result = {
362
372
  model: response.model,
363
373
  usage,
@@ -367,6 +377,7 @@ function xaiAdapter(opts) {
367
377
  ...text.length > 0 ? { text } : {},
368
378
  ...reasoningText !== void 0 ? { reasoningText } : {},
369
379
  ...rawStructured !== void 0 ? { rawStructured } : {},
380
+ ...servedServiceTier !== void 0 ? { servedServiceTier } : {},
370
381
  ...Object.keys(providerMeta).length > 0 ? { providerMetadata: providerMeta } : {}
371
382
  };
372
383
  return result;
@@ -873,6 +884,55 @@ var Grok45ConfigSchema = z.strictObject({
873
884
  description: "Strict Responses API config for model grok-4.5. Level reasoning (low/high only), tunable sampling, no service tiers, structured output, vision, priced.",
874
885
  examples: [{ reasoning: { effort: "high" } }]
875
886
  });
887
+ var Grok46ConfigSchema = z.strictObject({
888
+ temperature: z.number().optional().meta({
889
+ title: "Temperature",
890
+ description: "Sampling temperature forwarded verbatim to grok-4.6."
891
+ }),
892
+ topP: z.number().optional().meta({
893
+ title: "Top P",
894
+ description: "Nucleus sampling parameter forwarded verbatim to grok-4.6."
895
+ }),
896
+ maxOutputTokens: z.number().int().positive().optional().meta({
897
+ title: "Max Output Tokens",
898
+ description: "Maximum output token cap for grok-4.6. No artificial ceiling \u2014 xAI accepts arbitrarily large values; truncation surfaces as finishReason:'length', not an error."
899
+ }),
900
+ reasoning: z.strictObject({
901
+ effort: z.enum(["low", "medium", "high", "xhigh"]).meta({
902
+ title: "Reasoning Effort",
903
+ description: 'Reasoning effort for grok-4.6. Live-verified 2026-08-12: "low", "medium", "high", and "xhigh" are accepted; "none" is rejected. Vendor default when omitted is "high".'
904
+ })
905
+ }).optional().meta({
906
+ title: "Reasoning",
907
+ description: "grok-4.6 effort-level reasoning configuration. No budgetTokens field \u2014 xAI uses level-style reasoning, not token budgets."
908
+ }),
909
+ serviceTier: z.literal("priority").optional().meta({
910
+ title: "Service Tier",
911
+ description: 'xAI priority processing for grok-4.6 (Responses `service_tier: "priority"`). Echo live-verified 2026-08-12. Bills at 2\xD7 after the cache discount (uncached standard-list 2\xD7 confirmed by live ticks; cached/long-context legs follow the official 2\xD7 rule). Omitted requests stay on xAI default. "flex"/"standard"/"batch" are rejected.'
912
+ }),
913
+ timeoutMs: z.number().int().positive().optional().meta({
914
+ title: "Timeout",
915
+ description: "Logical request timeout in milliseconds."
916
+ }),
917
+ providerOptions: z.strictObject({
918
+ xai: z.strictObject({
919
+ promptCacheKey: z.string().min(1).optional().meta({
920
+ title: "Prompt Cache Key",
921
+ description: "xAI conversation-routing cache key \u2014 maps to Responses API `prompt_cache_key`."
922
+ })
923
+ }).optional().meta({
924
+ title: "xAI Provider Options",
925
+ description: "Allowlisted xAI provider options for grok-4.6."
926
+ })
927
+ }).optional().meta({
928
+ title: "Provider Options",
929
+ description: "Provider-specific options accepted for grok-4.6."
930
+ })
931
+ }).meta({
932
+ title: "Grok46Config",
933
+ description: "Strict Responses API config for model grok-4.6. Level reasoning (low/medium/high/xhigh), optional priority service tier, tunable sampling, structured output, vision, priced.",
934
+ examples: [{ reasoning: { effort: "high" } }]
935
+ });
876
936
 
877
937
  // src/models.ts
878
938
  var grok45ModelDescriptor = {
@@ -890,20 +950,55 @@ var grok45ModelDescriptor = {
890
950
  sampling: "tunable",
891
951
  caching: { explicit: false, minTokens: 0 },
892
952
  grounding: false
893
- // No serviceTiers key — xai has no service-tier concept.
953
+ // No serviceTiers key — grok-4.5 has no admitted service-tier vocabulary.
894
954
  },
895
955
  configSchema: Grok45ConfigSchema,
896
956
  configJsonSchema: toConfigJsonSchema(Grok45ConfigSchema),
897
957
  validateConfig: zodToStandardSchema(Grok45ConfigSchema)
898
958
  };
899
- var xaiModelDescriptors = [grok45ModelDescriptor];
959
+ var grok46ModelDescriptor = {
960
+ model: "grok-4.6",
961
+ provider: "xai",
962
+ pricingFamily: "grok-4.6",
963
+ capabilities: {
964
+ reasoning: true,
965
+ reasoningApi: "level",
966
+ admittedReasoningEfforts: ["low", "medium", "high", "xhigh"],
967
+ structuredOutput: true,
968
+ nativeStructuredOutput: true,
969
+ vision: true,
970
+ audioInput: false,
971
+ sampling: "tunable",
972
+ caching: { explicit: false, minTokens: 0 },
973
+ grounding: false,
974
+ serviceTiers: ["priority"]
975
+ },
976
+ configSchema: Grok46ConfigSchema,
977
+ configJsonSchema: toConfigJsonSchema(Grok46ConfigSchema),
978
+ validateConfig: zodToStandardSchema(Grok46ConfigSchema)
979
+ };
980
+ var xaiModelDescriptors = [
981
+ grok45ModelDescriptor,
982
+ grok46ModelDescriptor
983
+ ];
900
984
  var xaiRegistry = createModelRegistry(xaiModelDescriptors);
901
985
 
902
986
  // src/pricing.ts
903
- var xaiPricingVersion = "xai-2026-07-09";
987
+ var xaiPricingVersion = "xai-2026-08-12";
904
988
  var XAI_PRICING = Object.freeze({
905
- // ── grok-4.5 ── $2.00/$6.00 (≤200k), $4.00/$12.00 (>200k); cached $0.50/$1.00
989
+ // ── grok-4.5 ── $2.00/$6.00 (≤200k), $4.00/$12.00 (>200k); cached $0.30/$0.60
906
990
  "grok-4.5": {
991
+ inputPerM: 2e6,
992
+ cachedPerM: 3e5,
993
+ outputPerM: 6e6,
994
+ gt200k: {
995
+ inputPerM: 4e6,
996
+ cachedPerM: 6e5,
997
+ outputPerM: 12e6
998
+ }
999
+ },
1000
+ // ── grok-4.6 ── $2.00/$6.00 (≤200k), $4.00/$12.00 (>200k); cached $0.50/$1.00
1001
+ "grok-4.6": {
907
1002
  inputPerM: 2e6,
908
1003
  cachedPerM: 5e5,
909
1004
  outputPerM: 6e6,
@@ -911,7 +1006,9 @@ var XAI_PRICING = Object.freeze({
911
1006
  inputPerM: 4e6,
912
1007
  cachedPerM: 1e6,
913
1008
  outputPerM: 12e6
914
- }
1009
+ },
1010
+ // Confirmed 2026-08-12 by fixture 12 cost_in_usd_ticks (2× list).
1011
+ priorityFactor: 2
915
1012
  }
916
1013
  });
917
1014
  var LONG_CONTEXT_THRESHOLD = 2e5;
@@ -940,22 +1037,29 @@ function computeXaiCost(model, usage, tier) {
940
1037
  unpricedReason: `Unknown model "${model}"; no pricing entry found.`
941
1038
  };
942
1039
  }
943
- if (tier !== void 0) {
944
- return {
945
- microUsd: null,
946
- usd: null,
947
- pricingVersion: xaiPricingVersion,
948
- confidence: "estimated",
949
- details: { input: 0, cached: 0, output: 0 },
950
- unpricedReason: `Unknown service tier "${tier}"; xai has no service tiers, refusing to guess a pricing multiplier.`
951
- };
1040
+ let factor = 1;
1041
+ if (tier !== void 0 && tier !== "default") {
1042
+ if (tier === "priority" && rates.priorityFactor !== void 0) {
1043
+ factor = rates.priorityFactor;
1044
+ } else {
1045
+ return {
1046
+ microUsd: null,
1047
+ usd: null,
1048
+ pricingVersion: xaiPricingVersion,
1049
+ confidence: "estimated",
1050
+ details: { input: 0, cached: 0, output: 0 },
1051
+ unpricedReason: `Unknown service tier "${tier}"; xai model "${model}" has no such tier, refusing to guess a pricing multiplier.`
1052
+ };
1053
+ }
952
1054
  }
953
1055
  const base = selectRates(rates, usage.inputTokens);
954
1056
  const cached = usage.cachedInputTokens ?? 0;
955
1057
  const billableInput = Math.max(0, usage.inputTokens - cached);
956
- const inputCost = Math.round(billableInput * base.inputPerM / 1e6);
957
- const cachedCost = Math.round(cached * base.cachedPerM / 1e6);
958
- const outputCost = Math.round(usage.outputTokens * base.outputPerM / 1e6);
1058
+ const inputCost = Math.round(billableInput * base.inputPerM * factor / 1e6);
1059
+ const cachedCost = Math.round(cached * base.cachedPerM * factor / 1e6);
1060
+ const outputCost = Math.round(
1061
+ usage.outputTokens * base.outputPerM * factor / 1e6
1062
+ );
959
1063
  const microUsd = inputCost + cachedCost + outputCost;
960
1064
  return {
961
1065
  microUsd,
@@ -993,6 +1097,6 @@ function xaiProvider(opts) {
993
1097
  };
994
1098
  }
995
1099
 
996
- export { Grok45ConfigSchema, XAI_FILES_DEFAULT_BASE_URL, XAI_FILE_MAX_BYTES, XAI_FILE_TTL_MAX_SECONDS, XAI_FILE_TTL_MIN_SECONDS, XAI_PRICING, XaiFileStore, buildXaiClient, classifyXaiError, computeXaiCost, grok45ModelDescriptor, requireApiKey, xaiAdapter, xaiModelDescriptors, xaiPricingSource, xaiPricingVersion, xaiProvider, xaiRegistry };
1100
+ export { Grok45ConfigSchema, Grok46ConfigSchema, XAI_FILES_DEFAULT_BASE_URL, XAI_FILE_MAX_BYTES, XAI_FILE_TTL_MAX_SECONDS, XAI_FILE_TTL_MIN_SECONDS, XAI_PRICING, XaiFileStore, buildXaiClient, classifyXaiError, computeXaiCost, grok45ModelDescriptor, grok46ModelDescriptor, requireApiKey, xaiAdapter, xaiModelDescriptors, xaiPricingSource, xaiPricingVersion, xaiProvider, xaiRegistry };
997
1101
  //# sourceMappingURL=index.js.map
998
1102
  //# sourceMappingURL=index.js.map