@gullabs/xai 0.4.1 → 0.5.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 +40 -33
- package/dist/index.cjs +144 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +100 -52
- package/dist/index.d.ts +100 -52
- package/dist/index.js +143 -24
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
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
|
/**
|
|
@@ -230,28 +240,23 @@ declare function buildXaiClient(auth: AuthMaterial): Promise<XaiClientLike>;
|
|
|
230
240
|
* Classify a raw error thrown from the xAI Responses API call into a typed
|
|
231
241
|
* {@link LlmError}.
|
|
232
242
|
*
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
* `
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
-
* retry" bucket this adapter's `countTokens` path already uses for
|
|
251
|
-
* provider-side failures with no HTTP status. A connection that never
|
|
252
|
-
* reached xAI is not the caller's fault and is safe to retry; it must never
|
|
253
|
-
* be surfaced as the non-retryable `unknown` kind, which Temporal treats as
|
|
254
|
-
* fatal and uses to kill the run outright.
|
|
243
|
+
* HTTP status is a hint, not a kind. Overlays inspect the STRUCTURED parsed
|
|
244
|
+
* body only — never free-form `Error.message` — so echoed user content cannot
|
|
245
|
+
* change classification.
|
|
246
|
+
*
|
|
247
|
+
* 1. Already an {@link LlmError} → returned unchanged (including an untagged
|
|
248
|
+
* one).
|
|
249
|
+
* 2. HTTP 400 whose structured body starts with
|
|
250
|
+
* `"Incorrect API key provided"` (fixture 09; prefix only — the SDK may
|
|
251
|
+
* drop `code`) → `invalid_auth`.
|
|
252
|
+
* 3. HTTP 403 whose structured body starts with
|
|
253
|
+
* `"Content violates usage guidelines"` (fixture 15; `SAFETY_CHECK_TYPE_*`
|
|
254
|
+
* suffixes vary) → `content_filter`. A bare 403 without that body stays
|
|
255
|
+
* the core default, `invalid_auth`.
|
|
256
|
+
* 4. `kind: 'unknown'` with a known transport-failure signature (see
|
|
257
|
+
* {@link isXaiTransportError}) → `server`, retryable. A connection that
|
|
258
|
+
* never reached xAI is not the caller's fault.
|
|
259
|
+
* 5. Else rebuild the core classification tagged `provider: 'xai'`.
|
|
255
260
|
*/
|
|
256
261
|
declare function classifyXaiError(rawErr: unknown): LlmError;
|
|
257
262
|
interface XaiAdapterOptions {
|
|
@@ -446,19 +451,53 @@ declare const Grok45ConfigSchema: z.ZodObject<{
|
|
|
446
451
|
}, z.core.$strict>>;
|
|
447
452
|
}, z.core.$strict>;
|
|
448
453
|
|
|
454
|
+
/**
|
|
455
|
+
* Strict Zod config schema for xAI's `grok-4.6` model.
|
|
456
|
+
*
|
|
457
|
+
* Same Responses-API surface as grok-4.5, plus live-verified (2026-08-12)
|
|
458
|
+
* `reasoning.effort` of `'low' | 'medium' | 'high' | 'xhigh'` and
|
|
459
|
+
* `serviceTier: 'priority'`. `'none'` is rejected by the live API. Unknown
|
|
460
|
+
* tiers (`flex`, `standard`, `batch`) are rejected — `flex` is silently
|
|
461
|
+
* remapped to `default` by xAI, so this schema never admits it.
|
|
462
|
+
*
|
|
463
|
+
* @module
|
|
464
|
+
*/
|
|
465
|
+
|
|
466
|
+
declare const Grok46ConfigSchema: z.ZodObject<{
|
|
467
|
+
temperature: z.ZodOptional<z.ZodNumber>;
|
|
468
|
+
topP: z.ZodOptional<z.ZodNumber>;
|
|
469
|
+
maxOutputTokens: z.ZodOptional<z.ZodNumber>;
|
|
470
|
+
reasoning: z.ZodOptional<z.ZodObject<{
|
|
471
|
+
effort: z.ZodEnum<{
|
|
472
|
+
low: "low";
|
|
473
|
+
medium: "medium";
|
|
474
|
+
high: "high";
|
|
475
|
+
xhigh: "xhigh";
|
|
476
|
+
}>;
|
|
477
|
+
}, z.core.$strict>>;
|
|
478
|
+
serviceTier: z.ZodOptional<z.ZodLiteral<"priority">>;
|
|
479
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
480
|
+
providerOptions: z.ZodOptional<z.ZodObject<{
|
|
481
|
+
xai: z.ZodOptional<z.ZodObject<{
|
|
482
|
+
promptCacheKey: z.ZodOptional<z.ZodString>;
|
|
483
|
+
}, z.core.$strict>>;
|
|
484
|
+
}, z.core.$strict>>;
|
|
485
|
+
}, z.core.$strict>;
|
|
486
|
+
|
|
449
487
|
/**
|
|
450
488
|
* Model descriptor + registry for @gullabs/xai.
|
|
451
489
|
*
|
|
452
|
-
*
|
|
453
|
-
* `grok-4.5-latest
|
|
454
|
-
*
|
|
455
|
-
*
|
|
490
|
+
* Ships two canonical models: `grok-4.5` and `grok-4.6`. xAI aliases
|
|
491
|
+
* (`grok-4.5-latest`, `grok-build-latest`) visible in `/v1/models` are
|
|
492
|
+
* intentionally NOT registered (reject-don't-map). `grok-4.6` has no
|
|
493
|
+
* aliases as of the 2026-08-12 `/v1/models` listing.
|
|
456
494
|
*
|
|
457
495
|
* @module
|
|
458
496
|
*/
|
|
459
497
|
|
|
460
498
|
declare const grok45ModelDescriptor: ModelDescriptor;
|
|
461
|
-
|
|
499
|
+
declare const grok46ModelDescriptor: ModelDescriptor;
|
|
500
|
+
/** Every model descriptor `@gullabs/xai` contributes. */
|
|
462
501
|
declare const xaiModelDescriptors: ModelDescriptor[];
|
|
463
502
|
declare const xaiRegistry: ModelRegistry;
|
|
464
503
|
|
|
@@ -474,35 +513,33 @@ declare const xaiRegistry: ModelRegistry;
|
|
|
474
513
|
* (those are Gemini-only). `PricingSource` is provider-scoped by contract
|
|
475
514
|
* (see `packages/core/src/ports.ts`); this module is xai's own.
|
|
476
515
|
*
|
|
477
|
-
* **Long-context tier.** grok-4.5
|
|
478
|
-
* token count exceeds 200,000 (`long_context_threshold` in xAI's
|
|
516
|
+
* **Long-context tier.** grok-4.5 / grok-4.6 charge a premium when the GROSS
|
|
517
|
+
* input token count exceeds 200,000 (`long_context_threshold` in xAI's
|
|
479
518
|
* `/v1/models` listing). Selected by `inputTokens` (incl. cached), not by
|
|
480
519
|
* billable input — mirrors core's `selectRates` convention exactly (strictly
|
|
481
520
|
* greater than 200,000).
|
|
482
521
|
*
|
|
483
|
-
* **Service tiers.**
|
|
484
|
-
*
|
|
485
|
-
* `
|
|
486
|
-
*
|
|
487
|
-
*
|
|
488
|
-
*
|
|
489
|
-
* upstream) prices normally.
|
|
522
|
+
* **Service tiers.** grok-4.5 has none. grok-4.6 admits `'priority'`
|
|
523
|
+
* (echo live-verified 2026-08-12). The 2× multiplier is confirmed by
|
|
524
|
+
* fixture `12-grok-4-6-xhigh-priority.json` (`cost_in_usd_ticks` equals
|
|
525
|
+
* exactly 2× standard list). `'default'` (the value xAI echoes when no
|
|
526
|
+
* priority is served) and `undefined` (no tier requested) price at the
|
|
527
|
+
* standard list. Any other defined tier is unpriced (reject-don't-map).
|
|
490
528
|
*
|
|
491
529
|
* **Conversion factor.** xAI's `/v1/models` raw `*_token_price` fields are
|
|
492
530
|
* 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.
|
|
494
|
-
* `prompt_text_token_price: 20000` ÷ 10,000 = $2.00/M
|
|
495
|
-
* confirmed live-verified figure.
|
|
531
|
+
* by 10,000 to get USD per million tokens): e.g. `grok-4.6`'s raw
|
|
532
|
+
* `prompt_text_token_price: 20000` ÷ 10,000 = $2.00/M.
|
|
496
533
|
*
|
|
497
|
-
* Verified against `/v1/models`
|
|
498
|
-
* `
|
|
499
|
-
*
|
|
534
|
+
* Verified against `/v1/models` on 2026-08-12. Prior snapshot
|
|
535
|
+
* `xai-2026-07-09` priced grok-4.5 cached input at $0.50 / $1.00; the live
|
|
536
|
+
* listing now reports $0.30 / $0.60.
|
|
500
537
|
*
|
|
501
538
|
* @module
|
|
502
539
|
*/
|
|
503
540
|
|
|
504
541
|
/** Identifies this pricing snapshot — bump the date when rates change. */
|
|
505
|
-
declare const xaiPricingVersion: "xai-2026-
|
|
542
|
+
declare const xaiPricingVersion: "xai-2026-08-12";
|
|
506
543
|
/**
|
|
507
544
|
* Per-model rate entry (all values in µUSD per million tokens).
|
|
508
545
|
*
|
|
@@ -521,6 +558,14 @@ interface XaiModelRates {
|
|
|
521
558
|
cachedPerM: number;
|
|
522
559
|
outputPerM: number;
|
|
523
560
|
};
|
|
561
|
+
/**
|
|
562
|
+
* Multiplier for Responses `service_tier: "priority"`. Absent = this
|
|
563
|
+
* model does not admit priority (unpriced). Uncached standard-list 2×
|
|
564
|
+
* is confirmed by fixture `12-grok-4-6-xhigh-priority.json` ticks;
|
|
565
|
+
* cached and `gt200k` legs follow the official 2×-after-cache-discount
|
|
566
|
+
* docs rule (that fixture has cached=0 and input < 200k).
|
|
567
|
+
*/
|
|
568
|
+
priorityFactor?: number;
|
|
524
569
|
}
|
|
525
570
|
/**
|
|
526
571
|
* Frozen xAI pricing snapshot (per-1M in µUSD).
|
|
@@ -539,8 +584,10 @@ declare const XAI_PRICING: Readonly<Record<string, XaiModelRates>>;
|
|
|
539
584
|
* **Algorithm** (mirrors `@gullabs/core`'s `computeCost` exactly, xai-owned):
|
|
540
585
|
* 1. Look up rates for `model`; if not found, return an unpriced `Cost`
|
|
541
586
|
* (`microUsd: null`) naming the model.
|
|
542
|
-
* 2.
|
|
543
|
-
* `
|
|
587
|
+
* 2. `undefined` or `'default'` prices at the standard list.
|
|
588
|
+
* `'priority'` applies `rates.priorityFactor` when present.
|
|
589
|
+
* Any other defined tier, or `'priority'` on a model without
|
|
590
|
+
* `priorityFactor`, is unpriced (reject-don't-map).
|
|
544
591
|
* 3. Select base vs. `>200k` long-context rates from GROSS `inputTokens`.
|
|
545
592
|
* 4. Billable input = `inputTokens − (cachedInputTokens ?? 0)`, clamped to 0.
|
|
546
593
|
* 5. Round each component (input, cached, output) independently to the
|
|
@@ -558,7 +605,7 @@ declare function computeXaiCost(model: string, usage: Usage, tier?: string): Cos
|
|
|
558
605
|
* import { xaiPricingSource } from '@gullabs/xai'
|
|
559
606
|
*
|
|
560
607
|
* const pricing = xaiPricingSource()
|
|
561
|
-
* const cost = pricing.price('grok-4.
|
|
608
|
+
* const cost = pricing.price('grok-4.6', usage)
|
|
562
609
|
* ```
|
|
563
610
|
*/
|
|
564
611
|
declare function xaiPricingSource(): PricingSource;
|
|
@@ -566,8 +613,9 @@ declare function xaiPricingSource(): PricingSource;
|
|
|
566
613
|
/**
|
|
567
614
|
* `xaiProvider` — {@link ProviderPlugin} factory for @gullabs/xai.
|
|
568
615
|
*
|
|
569
|
-
* Bundles the xAI Grok adapter, the `grok-4.5`
|
|
570
|
-
* xai pricing source into a single plugin for
|
|
616
|
+
* Bundles the xAI Grok adapter, the `grok-4.5` / `grok-4.6` model
|
|
617
|
+
* descriptors, and the xai pricing source into a single plugin for
|
|
618
|
+
* {@link composeProviders}.
|
|
571
619
|
*
|
|
572
620
|
* @module
|
|
573
621
|
*/
|
|
@@ -576,8 +624,8 @@ declare function xaiPricingSource(): PricingSource;
|
|
|
576
624
|
* Create a {@link ProviderPlugin} for the xAI Grok provider.
|
|
577
625
|
*
|
|
578
626
|
* @param opts - Forwarded to {@link xaiAdapter}.
|
|
579
|
-
* @returns A plugin bundling the xAI adapter, the `grok-4.5`
|
|
580
|
-
*
|
|
627
|
+
* @returns A plugin bundling the xAI adapter, the `grok-4.5` / `grok-4.6`
|
|
628
|
+
* model descriptors, and the built-in xai pricing source.
|
|
581
629
|
*
|
|
582
630
|
* @example
|
|
583
631
|
* ```ts
|
|
@@ -591,4 +639,4 @@ declare function xaiPricingSource(): PricingSource;
|
|
|
591
639
|
*/
|
|
592
640
|
declare function xaiProvider(opts?: XaiAdapterOptions): ProviderPlugin;
|
|
593
641
|
|
|
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 };
|
|
642
|
+
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
|
/**
|
|
@@ -230,28 +240,23 @@ declare function buildXaiClient(auth: AuthMaterial): Promise<XaiClientLike>;
|
|
|
230
240
|
* Classify a raw error thrown from the xAI Responses API call into a typed
|
|
231
241
|
* {@link LlmError}.
|
|
232
242
|
*
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
* `
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
-
* retry" bucket this adapter's `countTokens` path already uses for
|
|
251
|
-
* provider-side failures with no HTTP status. A connection that never
|
|
252
|
-
* reached xAI is not the caller's fault and is safe to retry; it must never
|
|
253
|
-
* be surfaced as the non-retryable `unknown` kind, which Temporal treats as
|
|
254
|
-
* fatal and uses to kill the run outright.
|
|
243
|
+
* HTTP status is a hint, not a kind. Overlays inspect the STRUCTURED parsed
|
|
244
|
+
* body only — never free-form `Error.message` — so echoed user content cannot
|
|
245
|
+
* change classification.
|
|
246
|
+
*
|
|
247
|
+
* 1. Already an {@link LlmError} → returned unchanged (including an untagged
|
|
248
|
+
* one).
|
|
249
|
+
* 2. HTTP 400 whose structured body starts with
|
|
250
|
+
* `"Incorrect API key provided"` (fixture 09; prefix only — the SDK may
|
|
251
|
+
* drop `code`) → `invalid_auth`.
|
|
252
|
+
* 3. HTTP 403 whose structured body starts with
|
|
253
|
+
* `"Content violates usage guidelines"` (fixture 15; `SAFETY_CHECK_TYPE_*`
|
|
254
|
+
* suffixes vary) → `content_filter`. A bare 403 without that body stays
|
|
255
|
+
* the core default, `invalid_auth`.
|
|
256
|
+
* 4. `kind: 'unknown'` with a known transport-failure signature (see
|
|
257
|
+
* {@link isXaiTransportError}) → `server`, retryable. A connection that
|
|
258
|
+
* never reached xAI is not the caller's fault.
|
|
259
|
+
* 5. Else rebuild the core classification tagged `provider: 'xai'`.
|
|
255
260
|
*/
|
|
256
261
|
declare function classifyXaiError(rawErr: unknown): LlmError;
|
|
257
262
|
interface XaiAdapterOptions {
|
|
@@ -446,19 +451,53 @@ declare const Grok45ConfigSchema: z.ZodObject<{
|
|
|
446
451
|
}, z.core.$strict>>;
|
|
447
452
|
}, z.core.$strict>;
|
|
448
453
|
|
|
454
|
+
/**
|
|
455
|
+
* Strict Zod config schema for xAI's `grok-4.6` model.
|
|
456
|
+
*
|
|
457
|
+
* Same Responses-API surface as grok-4.5, plus live-verified (2026-08-12)
|
|
458
|
+
* `reasoning.effort` of `'low' | 'medium' | 'high' | 'xhigh'` and
|
|
459
|
+
* `serviceTier: 'priority'`. `'none'` is rejected by the live API. Unknown
|
|
460
|
+
* tiers (`flex`, `standard`, `batch`) are rejected — `flex` is silently
|
|
461
|
+
* remapped to `default` by xAI, so this schema never admits it.
|
|
462
|
+
*
|
|
463
|
+
* @module
|
|
464
|
+
*/
|
|
465
|
+
|
|
466
|
+
declare const Grok46ConfigSchema: z.ZodObject<{
|
|
467
|
+
temperature: z.ZodOptional<z.ZodNumber>;
|
|
468
|
+
topP: z.ZodOptional<z.ZodNumber>;
|
|
469
|
+
maxOutputTokens: z.ZodOptional<z.ZodNumber>;
|
|
470
|
+
reasoning: z.ZodOptional<z.ZodObject<{
|
|
471
|
+
effort: z.ZodEnum<{
|
|
472
|
+
low: "low";
|
|
473
|
+
medium: "medium";
|
|
474
|
+
high: "high";
|
|
475
|
+
xhigh: "xhigh";
|
|
476
|
+
}>;
|
|
477
|
+
}, z.core.$strict>>;
|
|
478
|
+
serviceTier: z.ZodOptional<z.ZodLiteral<"priority">>;
|
|
479
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
480
|
+
providerOptions: z.ZodOptional<z.ZodObject<{
|
|
481
|
+
xai: z.ZodOptional<z.ZodObject<{
|
|
482
|
+
promptCacheKey: z.ZodOptional<z.ZodString>;
|
|
483
|
+
}, z.core.$strict>>;
|
|
484
|
+
}, z.core.$strict>>;
|
|
485
|
+
}, z.core.$strict>;
|
|
486
|
+
|
|
449
487
|
/**
|
|
450
488
|
* Model descriptor + registry for @gullabs/xai.
|
|
451
489
|
*
|
|
452
|
-
*
|
|
453
|
-
* `grok-4.5-latest
|
|
454
|
-
*
|
|
455
|
-
*
|
|
490
|
+
* Ships two canonical models: `grok-4.5` and `grok-4.6`. xAI aliases
|
|
491
|
+
* (`grok-4.5-latest`, `grok-build-latest`) visible in `/v1/models` are
|
|
492
|
+
* intentionally NOT registered (reject-don't-map). `grok-4.6` has no
|
|
493
|
+
* aliases as of the 2026-08-12 `/v1/models` listing.
|
|
456
494
|
*
|
|
457
495
|
* @module
|
|
458
496
|
*/
|
|
459
497
|
|
|
460
498
|
declare const grok45ModelDescriptor: ModelDescriptor;
|
|
461
|
-
|
|
499
|
+
declare const grok46ModelDescriptor: ModelDescriptor;
|
|
500
|
+
/** Every model descriptor `@gullabs/xai` contributes. */
|
|
462
501
|
declare const xaiModelDescriptors: ModelDescriptor[];
|
|
463
502
|
declare const xaiRegistry: ModelRegistry;
|
|
464
503
|
|
|
@@ -474,35 +513,33 @@ declare const xaiRegistry: ModelRegistry;
|
|
|
474
513
|
* (those are Gemini-only). `PricingSource` is provider-scoped by contract
|
|
475
514
|
* (see `packages/core/src/ports.ts`); this module is xai's own.
|
|
476
515
|
*
|
|
477
|
-
* **Long-context tier.** grok-4.5
|
|
478
|
-
* token count exceeds 200,000 (`long_context_threshold` in xAI's
|
|
516
|
+
* **Long-context tier.** grok-4.5 / grok-4.6 charge a premium when the GROSS
|
|
517
|
+
* input token count exceeds 200,000 (`long_context_threshold` in xAI's
|
|
479
518
|
* `/v1/models` listing). Selected by `inputTokens` (incl. cached), not by
|
|
480
519
|
* billable input — mirrors core's `selectRates` convention exactly (strictly
|
|
481
520
|
* greater than 200,000).
|
|
482
521
|
*
|
|
483
|
-
* **Service tiers.**
|
|
484
|
-
*
|
|
485
|
-
* `
|
|
486
|
-
*
|
|
487
|
-
*
|
|
488
|
-
*
|
|
489
|
-
* upstream) prices normally.
|
|
522
|
+
* **Service tiers.** grok-4.5 has none. grok-4.6 admits `'priority'`
|
|
523
|
+
* (echo live-verified 2026-08-12). The 2× multiplier is confirmed by
|
|
524
|
+
* fixture `12-grok-4-6-xhigh-priority.json` (`cost_in_usd_ticks` equals
|
|
525
|
+
* exactly 2× standard list). `'default'` (the value xAI echoes when no
|
|
526
|
+
* priority is served) and `undefined` (no tier requested) price at the
|
|
527
|
+
* standard list. Any other defined tier is unpriced (reject-don't-map).
|
|
490
528
|
*
|
|
491
529
|
* **Conversion factor.** xAI's `/v1/models` raw `*_token_price` fields are
|
|
492
530
|
* 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.
|
|
494
|
-
* `prompt_text_token_price: 20000` ÷ 10,000 = $2.00/M
|
|
495
|
-
* confirmed live-verified figure.
|
|
531
|
+
* by 10,000 to get USD per million tokens): e.g. `grok-4.6`'s raw
|
|
532
|
+
* `prompt_text_token_price: 20000` ÷ 10,000 = $2.00/M.
|
|
496
533
|
*
|
|
497
|
-
* Verified against `/v1/models`
|
|
498
|
-
* `
|
|
499
|
-
*
|
|
534
|
+
* Verified against `/v1/models` on 2026-08-12. Prior snapshot
|
|
535
|
+
* `xai-2026-07-09` priced grok-4.5 cached input at $0.50 / $1.00; the live
|
|
536
|
+
* listing now reports $0.30 / $0.60.
|
|
500
537
|
*
|
|
501
538
|
* @module
|
|
502
539
|
*/
|
|
503
540
|
|
|
504
541
|
/** Identifies this pricing snapshot — bump the date when rates change. */
|
|
505
|
-
declare const xaiPricingVersion: "xai-2026-
|
|
542
|
+
declare const xaiPricingVersion: "xai-2026-08-12";
|
|
506
543
|
/**
|
|
507
544
|
* Per-model rate entry (all values in µUSD per million tokens).
|
|
508
545
|
*
|
|
@@ -521,6 +558,14 @@ interface XaiModelRates {
|
|
|
521
558
|
cachedPerM: number;
|
|
522
559
|
outputPerM: number;
|
|
523
560
|
};
|
|
561
|
+
/**
|
|
562
|
+
* Multiplier for Responses `service_tier: "priority"`. Absent = this
|
|
563
|
+
* model does not admit priority (unpriced). Uncached standard-list 2×
|
|
564
|
+
* is confirmed by fixture `12-grok-4-6-xhigh-priority.json` ticks;
|
|
565
|
+
* cached and `gt200k` legs follow the official 2×-after-cache-discount
|
|
566
|
+
* docs rule (that fixture has cached=0 and input < 200k).
|
|
567
|
+
*/
|
|
568
|
+
priorityFactor?: number;
|
|
524
569
|
}
|
|
525
570
|
/**
|
|
526
571
|
* Frozen xAI pricing snapshot (per-1M in µUSD).
|
|
@@ -539,8 +584,10 @@ declare const XAI_PRICING: Readonly<Record<string, XaiModelRates>>;
|
|
|
539
584
|
* **Algorithm** (mirrors `@gullabs/core`'s `computeCost` exactly, xai-owned):
|
|
540
585
|
* 1. Look up rates for `model`; if not found, return an unpriced `Cost`
|
|
541
586
|
* (`microUsd: null`) naming the model.
|
|
542
|
-
* 2.
|
|
543
|
-
* `
|
|
587
|
+
* 2. `undefined` or `'default'` prices at the standard list.
|
|
588
|
+
* `'priority'` applies `rates.priorityFactor` when present.
|
|
589
|
+
* Any other defined tier, or `'priority'` on a model without
|
|
590
|
+
* `priorityFactor`, is unpriced (reject-don't-map).
|
|
544
591
|
* 3. Select base vs. `>200k` long-context rates from GROSS `inputTokens`.
|
|
545
592
|
* 4. Billable input = `inputTokens − (cachedInputTokens ?? 0)`, clamped to 0.
|
|
546
593
|
* 5. Round each component (input, cached, output) independently to the
|
|
@@ -558,7 +605,7 @@ declare function computeXaiCost(model: string, usage: Usage, tier?: string): Cos
|
|
|
558
605
|
* import { xaiPricingSource } from '@gullabs/xai'
|
|
559
606
|
*
|
|
560
607
|
* const pricing = xaiPricingSource()
|
|
561
|
-
* const cost = pricing.price('grok-4.
|
|
608
|
+
* const cost = pricing.price('grok-4.6', usage)
|
|
562
609
|
* ```
|
|
563
610
|
*/
|
|
564
611
|
declare function xaiPricingSource(): PricingSource;
|
|
@@ -566,8 +613,9 @@ declare function xaiPricingSource(): PricingSource;
|
|
|
566
613
|
/**
|
|
567
614
|
* `xaiProvider` — {@link ProviderPlugin} factory for @gullabs/xai.
|
|
568
615
|
*
|
|
569
|
-
* Bundles the xAI Grok adapter, the `grok-4.5`
|
|
570
|
-
* xai pricing source into a single plugin for
|
|
616
|
+
* Bundles the xAI Grok adapter, the `grok-4.5` / `grok-4.6` model
|
|
617
|
+
* descriptors, and the xai pricing source into a single plugin for
|
|
618
|
+
* {@link composeProviders}.
|
|
571
619
|
*
|
|
572
620
|
* @module
|
|
573
621
|
*/
|
|
@@ -576,8 +624,8 @@ declare function xaiPricingSource(): PricingSource;
|
|
|
576
624
|
* Create a {@link ProviderPlugin} for the xAI Grok provider.
|
|
577
625
|
*
|
|
578
626
|
* @param opts - Forwarded to {@link xaiAdapter}.
|
|
579
|
-
* @returns A plugin bundling the xAI adapter, the `grok-4.5`
|
|
580
|
-
*
|
|
627
|
+
* @returns A plugin bundling the xAI adapter, the `grok-4.5` / `grok-4.6`
|
|
628
|
+
* model descriptors, and the built-in xai pricing source.
|
|
581
629
|
*
|
|
582
630
|
* @example
|
|
583
631
|
* ```ts
|
|
@@ -591,4 +639,4 @@ declare function xaiPricingSource(): PricingSource;
|
|
|
591
639
|
*/
|
|
592
640
|
declare function xaiProvider(opts?: XaiAdapterOptions): ProviderPlugin;
|
|
593
641
|
|
|
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 };
|
|
642
|
+
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 };
|