@tanstack/ai-grok 0.18.10 → 0.19.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
@@ -87,10 +87,10 @@ const adapter = grokImage()
87
87
 
88
88
  const result = await generateImages({
89
89
  adapter,
90
- model: 'grok-2-image-1212',
90
+ model: 'grok-imagine-image-2.0',
91
91
  prompt: 'A beautiful sunset over mountains',
92
92
  numberOfImages: 1,
93
- size: '1024x1024',
93
+ size: '16:9',
94
94
  })
95
95
 
96
96
  console.log(result.images[0].url)
@@ -2,7 +2,7 @@ import { default as OpenAI } from 'openai';
2
2
  import { BaseImageAdapter } from '@tanstack/ai/adapters';
3
3
  import { ImageGenerationOptions, ImageGenerationResult } from '@tanstack/ai';
4
4
  import { GrokImageModel } from '../model-meta.js';
5
- import { GrokImageModelInputModalitiesByName, GrokImageModelProviderOptionsByName, GrokImageModelSizeByName, GrokImageProviderOptions } from '../image/image-provider-options.js';
5
+ import { GrokImageModelInputModalitiesByName, GrokImageModelProviderOptionsByName, GrokImageModelSizeByName, GrokImagineImageProviderOptions } from '../image/image-provider-options.js';
6
6
  import { GrokClientConfig } from '../utils/client.js';
7
7
  /**
8
8
  * Configuration for Grok image adapter
@@ -13,9 +13,7 @@ export interface GrokImageConfig extends GrokClientConfig {
13
13
  * Grok Image Generation Adapter
14
14
  *
15
15
  * Tree-shakeable adapter for Grok image generation functionality.
16
- * Supports the legacy grok-2-image-1212 model (text-to-image via the
17
- * OpenAI-compat endpoint) and the grok-imagine image models, which also
18
- * accept image prompt parts for image-conditioned generation via xAI's
16
+ * Supports the grok-imagine image models. Image prompt parts use xAI's
19
17
  * `/v1/images/edits` endpoint (up to 3 source images).
20
18
  *
21
19
  * Features:
@@ -23,13 +21,13 @@ export interface GrokImageConfig extends GrokClientConfig {
23
21
  * - Size / aspect-ratio validation per model
24
22
  * - Number of images validation
25
23
  */
26
- export declare class GrokImageAdapter<TModel extends GrokImageModel> extends BaseImageAdapter<TModel, GrokImageProviderOptions, GrokImageModelProviderOptionsByName, GrokImageModelSizeByName, GrokImageModelInputModalitiesByName> {
24
+ export declare class GrokImageAdapter<TModel extends GrokImageModel> extends BaseImageAdapter<TModel, GrokImagineImageProviderOptions, GrokImageModelProviderOptionsByName, GrokImageModelSizeByName, GrokImageModelInputModalitiesByName> {
27
25
  readonly kind: "image";
28
26
  readonly name: "grok";
29
27
  protected client: OpenAI;
30
28
  private readonly clientConfig;
31
29
  constructor(config: GrokImageConfig, model: TModel);
32
- generateImages(options: ImageGenerationOptions<GrokImageProviderOptions>): Promise<ImageGenerationResult>;
30
+ generateImages(options: ImageGenerationOptions<GrokImagineImageProviderOptions>): Promise<ImageGenerationResult>;
33
31
  /**
34
32
  * Image-conditioned generation via xAI's Imagine API.
35
33
  *
@@ -46,14 +44,14 @@ export declare class GrokImageAdapter<TModel extends GrokImageModel> extends Bas
46
44
  * Creates a Grok image adapter with explicit API key.
47
45
  * Type resolution happens here at the call site.
48
46
  *
49
- * @param model - The model name (e.g., 'grok-2-image-1212')
47
+ * @param model - The model name (e.g., 'grok-imagine-image-2.0')
50
48
  * @param apiKey - Your xAI API key
51
49
  * @param config - Optional additional configuration
52
50
  * @returns Configured Grok image adapter instance with resolved types
53
51
  *
54
52
  * @example
55
53
  * ```typescript
56
- * const adapter = createGrokImage('grok-2-image-1212', "xai-...");
54
+ * const adapter = createGrokImage('grok-imagine-image-2.0', "xai-...");
57
55
  *
58
56
  * const result = await generateImage({
59
57
  * adapter,
@@ -70,7 +68,7 @@ export declare function createGrokImage<TModel extends GrokImageModel>(model: TM
70
68
  * - `process.env` (Node.js)
71
69
  * - `window.env` (Browser with injected env)
72
70
  *
73
- * @param model - The model name (e.g., 'grok-2-image-1212')
71
+ * @param model - The model name (e.g., 'grok-imagine-image-2.0')
74
72
  * @param config - Optional configuration (excluding apiKey which is auto-detected)
75
73
  * @returns Configured Grok image adapter instance with resolved types
76
74
  * @throws Error if XAI_API_KEY is not found in environment
@@ -78,7 +76,7 @@ export declare function createGrokImage<TModel extends GrokImageModel>(model: TM
78
76
  * @example
79
77
  * ```typescript
80
78
  * // Automatically uses XAI_API_KEY from environment
81
- * const adapter = grokImage('grok-2-image-1212');
79
+ * const adapter = grokImage('grok-imagine-image-2.0');
82
80
  *
83
81
  * const result = await generateImage({
84
82
  * adapter,
@@ -36,9 +36,7 @@ function imagePartToUrl(part) {
36
36
  * Grok Image Generation Adapter
37
37
  *
38
38
  * Tree-shakeable adapter for Grok image generation functionality.
39
- * Supports the legacy grok-2-image-1212 model (text-to-image via the
40
- * OpenAI-compat endpoint) and the grok-imagine image models, which also
41
- * accept image prompt parts for image-conditioned generation via xAI's
39
+ * Supports the grok-imagine image models. Image prompt parts use xAI's
42
40
  * `/v1/images/edits` endpoint (up to 3 source images).
43
41
  *
44
42
  * Features:
@@ -58,25 +56,19 @@ var GrokImageAdapter = class extends BaseImageAdapter {
58
56
  }
59
57
  async generateImages(options) {
60
58
  const { model, numberOfImages, size, modelOptions } = options;
59
+ if (!isGrokImagineImageModel(model)) throw new Error(`Unknown image model: ${model}. Supported models: grok-imagine-image, grok-imagine-image-2.0, grok-imagine-image-quality.`);
61
60
  const resolved = resolveMediaPrompt(options.prompt);
62
61
  const prompt = resolved.text;
63
62
  if (resolved.videos.length > 0 || resolved.audios.length > 0) throw new Error(`grok.generateImages does not support video / audio prompt parts on model ${model}.`);
64
- if (resolved.images.length > 0) {
65
- if (!isGrokImagineImageModel(model)) throw new Error(`grok: model "${model}" does not support image prompt parts. Image-conditioned generation requires an Imagine API model ('grok-imagine-image', 'grok-imagine-image-2.0' or 'grok-imagine-image-quality').`);
66
- return await this.editImages(options, resolved);
67
- }
68
- validatePrompt({
69
- prompt,
70
- model
71
- });
63
+ if (resolved.images.length > 0) return await this.editImages(options, resolved);
64
+ validatePrompt(prompt);
72
65
  validateImageSize(model, size);
73
66
  validateNumberOfImages(model, numberOfImages);
74
- const isImagine = isGrokImagineImageModel(model);
75
67
  const request = {
76
68
  model,
77
69
  prompt,
78
70
  n: numberOfImages ?? 1,
79
- ...isImagine ? imagineSizeParams(size) : size !== void 0 && { size },
71
+ ...imagineSizeParams(size),
80
72
  stream: false,
81
73
  ...modelOptions
82
74
  };
@@ -130,10 +122,7 @@ var GrokImageAdapter = class extends BaseImageAdapter {
130
122
  const unsupportedRole = imageInputs.find((part) => part.metadata?.role === "mask" || part.metadata?.role === "control");
131
123
  if (unsupportedRole) throw new Error(`grok: the Imagine API has no ${unsupportedRole.metadata?.role} input; only source/reference images are supported.`);
132
124
  if (imageInputs.length > MAX_EDIT_IMAGES) throw new Error(`grok: model "${model}" accepts at most ${MAX_EDIT_IMAGES} source images; received ${imageInputs.length}.`);
133
- validatePrompt({
134
- prompt,
135
- model
136
- });
125
+ validatePrompt(prompt);
137
126
  validateImageSize(model, size);
138
127
  validateNumberOfImages(model, numberOfImages);
139
128
  const urls = imageInputs.map((part) => imagePartToUrl(part));
@@ -186,14 +175,14 @@ var GrokImageAdapter = class extends BaseImageAdapter {
186
175
  * Creates a Grok image adapter with explicit API key.
187
176
  * Type resolution happens here at the call site.
188
177
  *
189
- * @param model - The model name (e.g., 'grok-2-image-1212')
178
+ * @param model - The model name (e.g., 'grok-imagine-image-2.0')
190
179
  * @param apiKey - Your xAI API key
191
180
  * @param config - Optional additional configuration
192
181
  * @returns Configured Grok image adapter instance with resolved types
193
182
  *
194
183
  * @example
195
184
  * ```typescript
196
- * const adapter = createGrokImage('grok-2-image-1212', "xai-...");
185
+ * const adapter = createGrokImage('grok-imagine-image-2.0', "xai-...");
197
186
  *
198
187
  * const result = await generateImage({
199
188
  * adapter,
@@ -215,7 +204,7 @@ function createGrokImage(model, apiKey, config) {
215
204
  * - `process.env` (Node.js)
216
205
  * - `window.env` (Browser with injected env)
217
206
  *
218
- * @param model - The model name (e.g., 'grok-2-image-1212')
207
+ * @param model - The model name (e.g., 'grok-imagine-image-2.0')
219
208
  * @param config - Optional configuration (excluding apiKey which is auto-detected)
220
209
  * @returns Configured Grok image adapter instance with resolved types
221
210
  * @throws Error if XAI_API_KEY is not found in environment
@@ -223,7 +212,7 @@ function createGrokImage(model, apiKey, config) {
223
212
  * @example
224
213
  * ```typescript
225
214
  * // Automatically uses XAI_API_KEY from environment
226
- * const adapter = grokImage('grok-2-image-1212');
215
+ * const adapter = grokImage('grok-imagine-image-2.0');
227
216
  *
228
217
  * const result = await generateImage({
229
218
  * adapter,
@@ -1 +1 @@
1
- {"version":3,"file":"image.js","names":[],"sources":["../../../src/adapters/image.ts"],"sourcesContent":["import OpenAI from 'openai'\nimport { resolveMediaPrompt } from '@tanstack/ai'\nimport { BaseImageAdapter } from '@tanstack/ai/adapters'\nimport { toRunErrorPayload } from '@tanstack/ai/adapter-internals'\nimport { buildImagesUsage } from '@tanstack/openai-base'\nimport { generateId } from '@tanstack/ai-utils'\nimport { getGrokApiKeyFromEnv, withGrokDefaults } from '../utils/client'\nimport {\n isGrokImagineImageModel,\n parseGrokImagineSize,\n validateImageSize,\n validateNumberOfImages,\n validatePrompt,\n} from '../image/image-provider-options'\nimport type {\n GeneratedImage,\n ImageGenerationOptions,\n ImageGenerationResult,\n ImagePart,\n MediaInputMetadata,\n ResolvedMediaPrompt,\n} from '@tanstack/ai'\nimport type OpenAI_SDK from 'openai'\nimport type { GrokImageModel } from '../model-meta'\nimport type {\n GrokImageModelInputModalitiesByName,\n GrokImageModelProviderOptionsByName,\n GrokImageModelSizeByName,\n GrokImageProviderOptions,\n} from '../image/image-provider-options'\nimport type { GrokClientConfig } from '../utils/client'\n\n/**\n * Configuration for Grok image adapter\n */\nexport interface GrokImageConfig extends GrokClientConfig {}\n\n/** Maximum source images accepted by xAI's image edit endpoint. */\nconst MAX_EDIT_IMAGES = 3\n\n/**\n * Maps the generic `size` option onto Imagine API parameters: the\n * \"aspectRatio_resolution\" template (\"16:9_2k\") splits into `aspect_ratio`\n * and optional `resolution` request fields.\n */\nfunction imagineSizeParams(size: string | undefined): {\n aspect_ratio?: string\n resolution?: string\n} {\n if (!size) return {}\n const parsed = parseGrokImagineSize(size)\n if (!parsed) return {}\n return {\n aspect_ratio: parsed.aspectRatio,\n ...(parsed.resolution !== undefined && { resolution: parsed.resolution }),\n }\n}\n\n/**\n * Convert a TanStack ImagePart to the URL string accepted by xAI's edit\n * endpoint: public URLs pass through (fetched by xAI's servers), data\n * sources become base64 data URIs.\n */\nfunction imagePartToUrl(part: ImagePart<MediaInputMetadata>): string {\n if (part.source.type === 'url') return part.source.value\n return `data:${part.source.mimeType};base64,${part.source.value}`\n}\n\n/** Response shape of xAI's `/v1/images/edits` endpoint. */\ninterface GrokImageEditResponse {\n data?: Array<{\n url?: string | null\n b64_json?: string | null\n mime_type?: string\n }>\n}\n\n/**\n * Grok Image Generation Adapter\n *\n * Tree-shakeable adapter for Grok image generation functionality.\n * Supports the legacy grok-2-image-1212 model (text-to-image via the\n * OpenAI-compat endpoint) and the grok-imagine image models, which also\n * accept image prompt parts for image-conditioned generation via xAI's\n * `/v1/images/edits` endpoint (up to 3 source images).\n *\n * Features:\n * - Model-specific type-safe provider options\n * - Size / aspect-ratio validation per model\n * - Number of images validation\n */\nexport class GrokImageAdapter<\n TModel extends GrokImageModel,\n> extends BaseImageAdapter<\n TModel,\n GrokImageProviderOptions,\n GrokImageModelProviderOptionsByName,\n GrokImageModelSizeByName,\n GrokImageModelInputModalitiesByName\n> {\n override readonly kind = 'image' as const\n readonly name = 'grok' as const\n\n protected client: OpenAI\n private readonly clientConfig: GrokImageConfig\n\n constructor(config: GrokImageConfig, model: TModel) {\n super(model, {})\n this.clientConfig = withGrokDefaults(config)\n this.client = new OpenAI(this.clientConfig)\n }\n\n async generateImages(\n options: ImageGenerationOptions<GrokImageProviderOptions>,\n ): Promise<ImageGenerationResult> {\n const { model, numberOfImages, size, modelOptions } = options\n\n const resolved = resolveMediaPrompt(options.prompt)\n const prompt = resolved.text\n\n if (resolved.videos.length > 0 || resolved.audios.length > 0) {\n throw new Error(\n `grok.generateImages does not support video / audio prompt parts on model ${model}.`,\n )\n }\n\n if (resolved.images.length > 0) {\n if (!isGrokImagineImageModel(model)) {\n throw new Error(\n `grok: model \"${model}\" does not support image prompt parts. ` +\n `Image-conditioned generation requires an Imagine API model ` +\n `('grok-imagine-image', 'grok-imagine-image-2.0' or ` +\n `'grok-imagine-image-quality').`,\n )\n }\n return await this.editImages(options, resolved)\n }\n\n validatePrompt({ prompt, model })\n validateImageSize(model, size)\n validateNumberOfImages(model, numberOfImages)\n\n // grok-imagine models are aspect-ratio sized: the generic `size` option\n // carries an \"aspectRatio_resolution\" template (e.g. '16:9_2k', like\n // Gemini native image models) and maps to the Imagine API's\n // `aspect_ratio` / `resolution` parameters instead of OpenAI-style `size`.\n const isImagine = isGrokImagineImageModel(model)\n const request = {\n model,\n prompt,\n n: numberOfImages ?? 1,\n ...(isImagine\n ? imagineSizeParams(size)\n : size !== undefined && {\n size: size,\n }),\n stream: false,\n ...modelOptions,\n } as OpenAI_SDK.Images.ImageGenerateParamsNonStreaming\n\n try {\n options.logger.request(\n `activity=image provider=${this.name} model=${model} n=${request.n ?? 1} size=${request.size ?? 'default'}`,\n { provider: this.name, model },\n )\n const response = await this.client.images.generate(request)\n\n const images: Array<GeneratedImage> = (response.data ?? []).flatMap(\n (item): Array<GeneratedImage> => {\n const revisedPrompt = item.revised_prompt\n if (item.b64_json) {\n return [\n {\n b64Json: item.b64_json,\n ...(revisedPrompt !== undefined && { revisedPrompt }),\n },\n ]\n }\n if (item.url) {\n return [\n {\n url: item.url,\n ...(revisedPrompt !== undefined && { revisedPrompt }),\n },\n ]\n }\n return []\n },\n )\n\n const usage = buildImagesUsage(response.usage)\n\n return {\n id: generateId(this.name),\n model,\n images,\n ...(usage ? { usage } : {}),\n }\n } catch (error: unknown) {\n options.logger.errors(`${this.name}.generateImages fatal`, {\n error: toRunErrorPayload(error, `${this.name}.generateImages failed`),\n source: `${this.name}.generateImages`,\n })\n throw error\n }\n }\n\n /**\n * Image-conditioned generation via xAI's Imagine API.\n *\n * The `/v1/images/edits` endpoint takes `application/json` (the OpenAI\n * SDK's `images.edit()` sends `multipart/form-data`, which xAI rejects),\n * so this path issues the request directly. One input is sent as\n * `image: { url }`; multiple inputs (up to 3) as `images: [{ url }, ...]`,\n * addressed by xAI in the order they are sent. The prompt text is sent\n * verbatim — no referencing markers are injected.\n */\n private async editImages(\n options: ImageGenerationOptions<GrokImageProviderOptions>,\n resolved: ResolvedMediaPrompt,\n ): Promise<ImageGenerationResult> {\n const { model, numberOfImages, size, modelOptions, logger } = options\n const prompt = resolved.text\n const imageInputs = resolved.images\n\n const unsupportedRole = imageInputs.find(\n (part) =>\n part.metadata?.role === 'mask' || part.metadata?.role === 'control',\n )\n if (unsupportedRole) {\n throw new Error(\n `grok: the Imagine API has no ${unsupportedRole.metadata?.role} input; ` +\n `only source/reference images are supported.`,\n )\n }\n if (imageInputs.length > MAX_EDIT_IMAGES) {\n throw new Error(\n `grok: model \"${model}\" accepts at most ${MAX_EDIT_IMAGES} source images; received ${imageInputs.length}.`,\n )\n }\n\n validatePrompt({ prompt, model })\n validateImageSize(model, size)\n validateNumberOfImages(model, numberOfImages)\n\n const urls = imageInputs.map((part) => imagePartToUrl(part))\n const request: Record<string, unknown> = {\n model,\n prompt,\n ...(urls.length === 1\n ? { image: { url: urls[0] } }\n : { images: urls.map((url) => ({ url })) }),\n ...(numberOfImages !== undefined && { n: numberOfImages }),\n ...imagineSizeParams(size),\n ...modelOptions,\n }\n\n try {\n logger.request(\n `activity=image provider=${this.name} model=${model} edit images=${urls.length}`,\n { provider: this.name, model },\n )\n\n const response = await fetch(\n `${this.clientConfig.baseURL}/images/edits`,\n {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${this.clientConfig.apiKey}`,\n },\n body: JSON.stringify(request),\n },\n )\n if (!response.ok) {\n const body = await response.text()\n throw new Error(\n `grok: image edit request failed (${response.status} ${response.statusText}): ${body}`,\n )\n }\n\n const result = (await response.json()) as GrokImageEditResponse\n const images: Array<GeneratedImage> = (result.data ?? []).flatMap(\n (item): Array<GeneratedImage> => {\n if (item.b64_json) return [{ b64Json: item.b64_json }]\n if (item.url) return [{ url: item.url }]\n return []\n },\n )\n if (images.length === 0) {\n throw new Error('grok: image edit response contained no images')\n }\n\n return {\n id: generateId(this.name),\n model,\n images,\n }\n } catch (error: unknown) {\n logger.errors(`${this.name}.generateImages fatal`, {\n error: toRunErrorPayload(error, `${this.name}.generateImages failed`),\n source: `${this.name}.generateImages`,\n })\n throw error\n }\n }\n}\n\n/**\n * Creates a Grok image adapter with explicit API key.\n * Type resolution happens here at the call site.\n *\n * @param model - The model name (e.g., 'grok-2-image-1212')\n * @param apiKey - Your xAI API key\n * @param config - Optional additional configuration\n * @returns Configured Grok image adapter instance with resolved types\n *\n * @example\n * ```typescript\n * const adapter = createGrokImage('grok-2-image-1212', \"xai-...\");\n *\n * const result = await generateImage({\n * adapter,\n * prompt: 'A cute baby sea otter'\n * });\n * ```\n */\nexport function createGrokImage<TModel extends GrokImageModel>(\n model: TModel,\n apiKey: string,\n config?: Omit<GrokImageConfig, 'apiKey'>,\n): GrokImageAdapter<TModel> {\n return new GrokImageAdapter({ apiKey, ...config }, model)\n}\n\n/**\n * Creates a Grok image adapter with automatic API key detection from environment variables.\n * Type resolution happens here at the call site.\n *\n * Looks for `XAI_API_KEY` in:\n * - `process.env` (Node.js)\n * - `window.env` (Browser with injected env)\n *\n * @param model - The model name (e.g., 'grok-2-image-1212')\n * @param config - Optional configuration (excluding apiKey which is auto-detected)\n * @returns Configured Grok image adapter instance with resolved types\n * @throws Error if XAI_API_KEY is not found in environment\n *\n * @example\n * ```typescript\n * // Automatically uses XAI_API_KEY from environment\n * const adapter = grokImage('grok-2-image-1212');\n *\n * const result = await generateImage({\n * adapter,\n * prompt: 'A beautiful sunset over mountains'\n * });\n * ```\n */\nexport function grokImage<TModel extends GrokImageModel>(\n model: TModel,\n config?: Omit<GrokImageConfig, 'apiKey'>,\n): GrokImageAdapter<TModel> {\n const api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K,IAAI,CAAC;IACvC,OAAO,CAAC;GACV,CACF;GACA,IAAI,OAAO,WAAW,GACpB,MAAM,IAAI,MAAM,+CAA+C;GAGjE,OAAO;IACL,IAAI,WAAW,KAAK,IAAI;IACxB;IACA;GACF;EACF,SAAS,OAAgB;GACvB,OAAO,OAAO,GAAG,KAAK,KAAK,wBAAwB;IACjD,OAAO,kBAAkB,OAAO,GAAG,KAAK,KAAK,uBAAuB;IACpE,QAAQ,GAAG,KAAK,KAAK;GACvB,CAAC;GACD,MAAM;EACR;CACF;AACF;;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,gBACd,OACA,QACA,QAC0B;CAC1B,OAAO,IAAI,iBAAiB;EAAE;EAAQ,GAAG;CAAO,GAAG,KAAK;AAC1D;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,SAAgB,UACd,OACA,QAC0B;CAE1B,OAAO,gBAAgB,OADR,qBACe,GAAQ,MAAM;AAC9C"}
1
+ {"version":3,"file":"image.js","names":[],"sources":["../../../src/adapters/image.ts"],"sourcesContent":["import OpenAI from 'openai'\nimport { resolveMediaPrompt } from '@tanstack/ai'\nimport { BaseImageAdapter } from '@tanstack/ai/adapters'\nimport { toRunErrorPayload } from '@tanstack/ai/adapter-internals'\nimport { buildImagesUsage } from '@tanstack/openai-base'\nimport { generateId } from '@tanstack/ai-utils'\nimport { getGrokApiKeyFromEnv, withGrokDefaults } from '../utils/client'\nimport {\n isGrokImagineImageModel,\n parseGrokImagineSize,\n validateImageSize,\n validateNumberOfImages,\n validatePrompt,\n} from '../image/image-provider-options'\nimport type {\n GeneratedImage,\n ImageGenerationOptions,\n ImageGenerationResult,\n ImagePart,\n MediaInputMetadata,\n ResolvedMediaPrompt,\n} from '@tanstack/ai'\nimport type OpenAI_SDK from 'openai'\nimport type { GrokImageModel } from '../model-meta'\nimport type {\n GrokImageModelInputModalitiesByName,\n GrokImageModelProviderOptionsByName,\n GrokImageModelSizeByName,\n GrokImagineImageProviderOptions,\n} from '../image/image-provider-options'\nimport type { GrokClientConfig } from '../utils/client'\n\n/**\n * Configuration for Grok image adapter\n */\nexport interface GrokImageConfig extends GrokClientConfig {}\n\n/** Maximum source images accepted by xAI's image edit endpoint. */\nconst MAX_EDIT_IMAGES = 3\n\n/**\n * Maps the generic `size` option onto Imagine API parameters: the\n * \"aspectRatio_resolution\" template (\"16:9_2k\") splits into `aspect_ratio`\n * and optional `resolution` request fields.\n */\nfunction imagineSizeParams(size: string | undefined): {\n aspect_ratio?: string\n resolution?: string\n} {\n if (!size) return {}\n const parsed = parseGrokImagineSize(size)\n if (!parsed) return {}\n return {\n aspect_ratio: parsed.aspectRatio,\n ...(parsed.resolution !== undefined && { resolution: parsed.resolution }),\n }\n}\n\n/**\n * Convert a TanStack ImagePart to the URL string accepted by xAI's edit\n * endpoint: public URLs pass through (fetched by xAI's servers), data\n * sources become base64 data URIs.\n */\nfunction imagePartToUrl(part: ImagePart<MediaInputMetadata>): string {\n if (part.source.type === 'url') return part.source.value\n return `data:${part.source.mimeType};base64,${part.source.value}`\n}\n\n/** Response shape of xAI's `/v1/images/edits` endpoint. */\ninterface GrokImageEditResponse {\n data?: Array<{\n url?: string | null\n b64_json?: string | null\n mime_type?: string\n }>\n}\n\n/**\n * Grok Image Generation Adapter\n *\n * Tree-shakeable adapter for Grok image generation functionality.\n * Supports the grok-imagine image models. Image prompt parts use xAI's\n * `/v1/images/edits` endpoint (up to 3 source images).\n *\n * Features:\n * - Model-specific type-safe provider options\n * - Size / aspect-ratio validation per model\n * - Number of images validation\n */\nexport class GrokImageAdapter<\n TModel extends GrokImageModel,\n> extends BaseImageAdapter<\n TModel,\n GrokImagineImageProviderOptions,\n GrokImageModelProviderOptionsByName,\n GrokImageModelSizeByName,\n GrokImageModelInputModalitiesByName\n> {\n override readonly kind = 'image' as const\n readonly name = 'grok' as const\n\n protected client: OpenAI\n private readonly clientConfig: GrokImageConfig\n\n constructor(config: GrokImageConfig, model: TModel) {\n super(model, {})\n this.clientConfig = withGrokDefaults(config)\n this.client = new OpenAI(this.clientConfig)\n }\n\n async generateImages(\n options: ImageGenerationOptions<GrokImagineImageProviderOptions>,\n ): Promise<ImageGenerationResult> {\n const { model, numberOfImages, size, modelOptions } = options\n\n if (!isGrokImagineImageModel(model)) {\n throw new Error(\n `Unknown image model: ${model}. Supported models: ` +\n `grok-imagine-image, grok-imagine-image-2.0, grok-imagine-image-quality.`,\n )\n }\n\n const resolved = resolveMediaPrompt(options.prompt)\n const prompt = resolved.text\n\n if (resolved.videos.length > 0 || resolved.audios.length > 0) {\n throw new Error(\n `grok.generateImages does not support video / audio prompt parts on model ${model}.`,\n )\n }\n\n if (resolved.images.length > 0) {\n return await this.editImages(options, resolved)\n }\n\n validatePrompt(prompt)\n validateImageSize(model, size)\n validateNumberOfImages(model, numberOfImages)\n\n // The generic `size` option carries an \"aspectRatio_resolution\" template\n // (e.g. '16:9_2k', like Gemini native image models) and maps to the\n // Imagine API's `aspect_ratio` / `resolution` parameters.\n const request = {\n model,\n prompt,\n n: numberOfImages ?? 1,\n ...imagineSizeParams(size),\n stream: false,\n ...modelOptions,\n } as OpenAI_SDK.Images.ImageGenerateParamsNonStreaming\n\n try {\n options.logger.request(\n `activity=image provider=${this.name} model=${model} n=${request.n ?? 1} size=${request.size ?? 'default'}`,\n { provider: this.name, model },\n )\n const response = await this.client.images.generate(request)\n\n const images: Array<GeneratedImage> = (response.data ?? []).flatMap(\n (item): Array<GeneratedImage> => {\n const revisedPrompt = item.revised_prompt\n if (item.b64_json) {\n return [\n {\n b64Json: item.b64_json,\n ...(revisedPrompt !== undefined && { revisedPrompt }),\n },\n ]\n }\n if (item.url) {\n return [\n {\n url: item.url,\n ...(revisedPrompt !== undefined && { revisedPrompt }),\n },\n ]\n }\n return []\n },\n )\n\n const usage = buildImagesUsage(response.usage)\n\n return {\n id: generateId(this.name),\n model,\n images,\n ...(usage ? { usage } : {}),\n }\n } catch (error: unknown) {\n options.logger.errors(`${this.name}.generateImages fatal`, {\n error: toRunErrorPayload(error, `${this.name}.generateImages failed`),\n source: `${this.name}.generateImages`,\n })\n throw error\n }\n }\n\n /**\n * Image-conditioned generation via xAI's Imagine API.\n *\n * The `/v1/images/edits` endpoint takes `application/json` (the OpenAI\n * SDK's `images.edit()` sends `multipart/form-data`, which xAI rejects),\n * so this path issues the request directly. One input is sent as\n * `image: { url }`; multiple inputs (up to 3) as `images: [{ url }, ...]`,\n * addressed by xAI in the order they are sent. The prompt text is sent\n * verbatim — no referencing markers are injected.\n */\n private async editImages(\n options: ImageGenerationOptions<GrokImagineImageProviderOptions>,\n resolved: ResolvedMediaPrompt,\n ): Promise<ImageGenerationResult> {\n const { model, numberOfImages, size, modelOptions, logger } = options\n const prompt = resolved.text\n const imageInputs = resolved.images\n\n const unsupportedRole = imageInputs.find(\n (part) =>\n part.metadata?.role === 'mask' || part.metadata?.role === 'control',\n )\n if (unsupportedRole) {\n throw new Error(\n `grok: the Imagine API has no ${unsupportedRole.metadata?.role} input; ` +\n `only source/reference images are supported.`,\n )\n }\n if (imageInputs.length > MAX_EDIT_IMAGES) {\n throw new Error(\n `grok: model \"${model}\" accepts at most ${MAX_EDIT_IMAGES} source images; received ${imageInputs.length}.`,\n )\n }\n\n validatePrompt(prompt)\n validateImageSize(model, size)\n validateNumberOfImages(model, numberOfImages)\n\n const urls = imageInputs.map((part) => imagePartToUrl(part))\n const request: Record<string, unknown> = {\n model,\n prompt,\n ...(urls.length === 1\n ? { image: { url: urls[0] } }\n : { images: urls.map((url) => ({ url })) }),\n ...(numberOfImages !== undefined && { n: numberOfImages }),\n ...imagineSizeParams(size),\n ...modelOptions,\n }\n\n try {\n logger.request(\n `activity=image provider=${this.name} model=${model} edit images=${urls.length}`,\n { provider: this.name, model },\n )\n\n const response = await fetch(\n `${this.clientConfig.baseURL}/images/edits`,\n {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${this.clientConfig.apiKey}`,\n },\n body: JSON.stringify(request),\n },\n )\n if (!response.ok) {\n const body = await response.text()\n throw new Error(\n `grok: image edit request failed (${response.status} ${response.statusText}): ${body}`,\n )\n }\n\n const result = (await response.json()) as GrokImageEditResponse\n const images: Array<GeneratedImage> = (result.data ?? []).flatMap(\n (item): Array<GeneratedImage> => {\n if (item.b64_json) return [{ b64Json: item.b64_json }]\n if (item.url) return [{ url: item.url }]\n return []\n },\n )\n if (images.length === 0) {\n throw new Error('grok: image edit response contained no images')\n }\n\n return {\n id: generateId(this.name),\n model,\n images,\n }\n } catch (error: unknown) {\n logger.errors(`${this.name}.generateImages fatal`, {\n error: toRunErrorPayload(error, `${this.name}.generateImages failed`),\n source: `${this.name}.generateImages`,\n })\n throw error\n }\n }\n}\n\n/**\n * Creates a Grok image adapter with explicit API key.\n * Type resolution happens here at the call site.\n *\n * @param model - The model name (e.g., 'grok-imagine-image-2.0')\n * @param apiKey - Your xAI API key\n * @param config - Optional additional configuration\n * @returns Configured Grok image adapter instance with resolved types\n *\n * @example\n * ```typescript\n * const adapter = createGrokImage('grok-imagine-image-2.0', \"xai-...\");\n *\n * const result = await generateImage({\n * adapter,\n * prompt: 'A cute baby sea otter'\n * });\n * ```\n */\nexport function createGrokImage<TModel extends GrokImageModel>(\n model: TModel,\n apiKey: string,\n config?: Omit<GrokImageConfig, 'apiKey'>,\n): GrokImageAdapter<TModel> {\n return new GrokImageAdapter({ apiKey, ...config }, model)\n}\n\n/**\n * Creates a Grok image adapter with automatic API key detection from environment variables.\n * Type resolution happens here at the call site.\n *\n * Looks for `XAI_API_KEY` in:\n * - `process.env` (Node.js)\n * - `window.env` (Browser with injected env)\n *\n * @param model - The model name (e.g., 'grok-imagine-image-2.0')\n * @param config - Optional configuration (excluding apiKey which is auto-detected)\n * @returns Configured Grok image adapter instance with resolved types\n * @throws Error if XAI_API_KEY is not found in environment\n *\n * @example\n * ```typescript\n * // Automatically uses XAI_API_KEY from environment\n * const adapter = grokImage('grok-imagine-image-2.0');\n *\n * const result = await generateImage({\n * adapter,\n * prompt: 'A beautiful sunset over mountains'\n * });\n * ```\n */\nexport function grokImage<TModel extends GrokImageModel>(\n model: TModel,\n config?: Omit<GrokImageConfig, 'apiKey'>,\n): GrokImageAdapter<TModel> {\n const apiKey = getGrokApiKeyFromEnv()\n return createGrokImage(model, apiKey, config)\n}\n"],"mappings":";;;;;;;;;;AAsCA,IAAM,kBAAkB;;;;;;AAOxB,SAAS,kBAAkB,MAGzB;CACA,IAAI,CAAC,MAAM,OAAO,CAAC;CACnB,MAAM,SAAS,qBAAqB,IAAI;CACxC,IAAI,CAAC,QAAQ,OAAO,CAAC;CACrB,OAAO;EACL,cAAc,OAAO;EACrB,GAAI,OAAO,eAAe,KAAA,KAAa,EAAE,YAAY,OAAO,WAAW;CACzE;AACF;;;;;;AAOA,SAAS,eAAe,MAA6C;CACnE,IAAI,KAAK,OAAO,SAAS,OAAO,OAAO,KAAK,OAAO;CACnD,OAAO,QAAQ,KAAK,OAAO,SAAS,UAAU,KAAK,OAAO;AAC5D;;;;;;;;;;;;;AAuBA,IAAa,mBAAb,cAEU,iBAMR;CACA,OAAyB;CACzB,OAAgB;CAEhB;CACA;CAEA,YAAY,QAAyB,OAAe;EAClD,MAAM,OAAO,CAAC,CAAC;EACf,KAAK,eAAe,iBAAiB,MAAM;EAC3C,KAAK,SAAS,IAAI,OAAO,KAAK,YAAY;CAC5C;CAEA,MAAM,eACJ,SACgC;EAChC,MAAM,EAAE,OAAO,gBAAgB,MAAM,iBAAiB;EAEtD,IAAI,CAAC,wBAAwB,KAAK,GAChC,MAAM,IAAI,MACR,wBAAwB,MAAM,4FAEhC;EAGF,MAAM,WAAW,mBAAmB,QAAQ,MAAM;EAClD,MAAM,SAAS,SAAS;EAExB,IAAI,SAAS,OAAO,SAAS,KAAK,SAAS,OAAO,SAAS,GACzD,MAAM,IAAI,MACR,4EAA4E,MAAM,EACpF;EAGF,IAAI,SAAS,OAAO,SAAS,GAC3B,OAAO,MAAM,KAAK,WAAW,SAAS,QAAQ;EAGhD,eAAe,MAAM;EACrB,k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,CAAC;IACvC,OAAO,CAAC;GACV,CACF;GACA,IAAI,OAAO,WAAW,GACpB,MAAM,IAAI,MAAM,+CAA+C;GAGjE,OAAO;IACL,IAAI,WAAW,KAAK,IAAI;IACxB;IACA;GACF;EACF,SAAS,OAAgB;GACvB,OAAO,OAAO,GAAG,KAAK,KAAK,wBAAwB;IACjD,OAAO,kBAAkB,OAAO,GAAG,KAAK,KAAK,uBAAuB;IACpE,QAAQ,GAAG,KAAK,KAAK;GACvB,CAAC;GACD,MAAM;EACR;CACF;AACF;;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,gBACd,OACA,QACA,QAC0B;CAC1B,OAAO,IAAI,iBAAiB;EAAE;EAAQ,GAAG;CAAO,GAAG,KAAK;AAC1D;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,SAAgB,UACd,OACA,QAC0B;CAE1B,OAAO,gBAAgB,OADR,qBACe,GAAQ,MAAM;AAC9C"}
@@ -3,12 +3,8 @@
3
3
  *
4
4
  * Provider-specific options for Grok image generation: the aspect-ratio
5
5
  * sized Imagine API models (grok-imagine-image, grok-imagine-image-2.0,
6
- * grok-imagine-image-quality) and the legacy pixel-sized grok-2-image-1212.
6
+ * grok-imagine-image-quality).
7
7
  */
8
- /**
9
- * Supported sizes for grok-2-image-1212 model
10
- */
11
- export type GrokImageSize = '1024x1024' | '1536x1024' | '1024x1536';
12
8
  /**
13
9
  * Aspect ratios accepted by the grok-imagine image models.
14
10
  */
@@ -27,8 +23,7 @@ export type GrokImagineResolution = '1k' | '2k';
27
23
  export type GrokImagineImageSize = GrokImagineAspectRatio | `${GrokImagineAspectRatio}_${GrokImagineResolution}`;
28
24
  /**
29
25
  * Models served by xAI's Imagine API. They are aspect-ratio sized and
30
- * support image-conditioned generation via `/v1/images/edits`; the legacy
31
- * grok-2-image-1212 model is pixel-sized and text-to-image only.
26
+ * support image-conditioned generation via `/v1/images/edits`.
32
27
  */
33
28
  export declare function isGrokImagineImageModel(model: string): boolean;
34
29
  /**
@@ -51,22 +46,6 @@ export interface GrokImageBaseProviderOptions {
51
46
  */
52
47
  user?: string;
53
48
  }
54
- /**
55
- * Provider options for grok-2-image-1212 model
56
- */
57
- export interface GrokImageProviderOptions extends GrokImageBaseProviderOptions {
58
- /**
59
- * The quality of the image.
60
- * @default 'standard'
61
- */
62
- quality?: 'standard' | 'hd';
63
- /**
64
- * The format in which generated images are returned.
65
- * URLs are only valid for 60 minutes after generation.
66
- * @default 'url'
67
- */
68
- response_format?: 'url' | 'b64_json';
69
- }
70
49
  /**
71
50
  * Provider options for the grok-imagine image models (generation and
72
51
  * image-conditioned editing via xAI's Imagine API).
@@ -103,7 +82,6 @@ export interface GrokImagineImage2ProviderOptions extends GrokImagineImageProvid
103
82
  * Type-only map from model name to its specific provider options.
104
83
  */
105
84
  export type GrokImageModelProviderOptionsByName = {
106
- 'grok-2-image-1212': GrokImageProviderOptions;
107
85
  'grok-imagine-image': GrokImagineImageProviderOptions;
108
86
  'grok-imagine-image-2.0': GrokImagineImage2ProviderOptions;
109
87
  'grok-imagine-image-quality': GrokImagineImageProviderOptions;
@@ -112,7 +90,6 @@ export type GrokImageModelProviderOptionsByName = {
112
90
  * Type-only map from model name to its supported sizes.
113
91
  */
114
92
  export type GrokImageModelSizeByName = {
115
- 'grok-2-image-1212': GrokImageSize;
116
93
  'grok-imagine-image': GrokImagineImageSize;
117
94
  'grok-imagine-image-2.0': GrokImagineImageSize;
118
95
  'grok-imagine-image-quality': GrokImagineImageSize;
@@ -120,21 +97,13 @@ export type GrokImageModelSizeByName = {
120
97
  /**
121
98
  * Per-model prompt input modalities. Imagine API models accept image parts
122
99
  * in the prompt (routed to `/v1/images/edits`, up to 3 images, addressed by
123
- * xAI in request order); grok-2-image is text-to-image only.
100
+ * xAI in request order).
124
101
  */
125
102
  export type GrokImageModelInputModalitiesByName = {
126
- 'grok-2-image-1212': readonly [];
127
103
  'grok-imagine-image': readonly ['image'];
128
104
  'grok-imagine-image-2.0': readonly ['image'];
129
105
  'grok-imagine-image-quality': readonly ['image'];
130
106
  };
131
- /**
132
- * Internal options interface for validation
133
- */
134
- interface ImageValidationOptions {
135
- prompt: string;
136
- model: string;
137
- }
138
107
  /**
139
108
  * Validates that the provided size is supported by the model.
140
109
  * Throws a descriptive error if the size is not supported.
@@ -144,5 +113,4 @@ export declare function validateImageSize(model: string, size: string | undefine
144
113
  * Validates that the number of images is within bounds for the model.
145
114
  */
146
115
  export declare function validateNumberOfImages(_model: string, numberOfImages: number | undefined): void;
147
- export declare const validatePrompt: (options: ImageValidationOptions) => void;
148
- export {};
116
+ export declare const validatePrompt: (prompt: string) => void;
@@ -18,8 +18,7 @@ var GROK_IMAGINE_ASPECT_RATIOS = [
18
18
  var GROK_IMAGINE_RESOLUTIONS = ["1k", "2k"];
19
19
  /**
20
20
  * Models served by xAI's Imagine API. They are aspect-ratio sized and
21
- * support image-conditioned generation via `/v1/images/edits`; the legacy
22
- * grok-2-image-1212 model is pixel-sized and text-to-image only.
21
+ * support image-conditioned generation via `/v1/images/edits`.
23
22
  */
24
23
  function isGrokImagineImageModel(model) {
25
24
  return model.startsWith("grok-imagine-image");
@@ -49,13 +48,7 @@ function validateImageSize(model, size) {
49
48
  if (!parsed || !GROK_IMAGINE_ASPECT_RATIOS.includes(parsed.aspectRatio) || parsed.resolution !== void 0 && !GROK_IMAGINE_RESOLUTIONS.includes(parsed.resolution)) throw new Error(`Size "${size}" is not supported by model "${model}". Expected an aspect ratio (${GROK_IMAGINE_ASPECT_RATIOS.join(", ")}) optionally suffixed with a resolution ("16:9_2k"; resolutions: ${GROK_IMAGINE_RESOLUTIONS.join(", ")}).`);
50
49
  return;
51
50
  }
52
- const modelSizes = { "grok-2-image-1212": [
53
- "1024x1024",
54
- "1536x1024",
55
- "1024x1536"
56
- ] }[model];
57
- if (!modelSizes) throw new Error(`Unknown image model: ${model}`);
58
- if (!modelSizes.includes(size)) throw new Error(`Size "${size}" is not supported by model "${model}". Supported sizes: ${modelSizes.join(", ")}`);
51
+ throw new Error(`Unknown image model: ${model}`);
59
52
  }
60
53
  /**
61
54
  * Validates that the number of images is within bounds for the model.
@@ -64,9 +57,8 @@ function validateNumberOfImages(_model, numberOfImages) {
64
57
  if (numberOfImages === void 0) return;
65
58
  if (numberOfImages < 1 || numberOfImages > 10) throw new Error(`Number of images must be between 1 and 10. Requested: ${numberOfImages}`);
66
59
  }
67
- var validatePrompt = (options) => {
68
- if (options.prompt.length === 0) throw new Error("Prompt cannot be empty.");
69
- if (options.prompt.length > 4e3) throw new Error("For grok-2-image-1212, prompt length must be less than or equal to 4000 characters.");
60
+ var validatePrompt = (prompt) => {
61
+ if (prompt.length === 0) throw new Error("Prompt cannot be empty.");
70
62
  };
71
63
  //#endregion
72
64
  export { isGrokImagineImageModel, parseGrokImagineSize, validateImageSize, validateNumberOfImages, validatePrompt };
@@ -1 +1 @@
1
- {"version":3,"file":"image-provider-options.js","names":[],"sources":["../../../src/image/image-provider-options.ts"],"sourcesContent":["/**\n * Grok Image Generation Provider Options\n *\n * Provider-specific options for Grok image generation: the aspect-ratio\n * sized Imagine API models (grok-imagine-image, grok-imagine-image-2.0,\n * grok-imagine-image-quality) and the legacy pixel-sized grok-2-image-1212.\n */\n\n/**\n * Supported sizes for grok-2-image-1212 model\n */\nexport type GrokImageSize = '1024x1024' | '1536x1024' | '1024x1536'\n\n/**\n * Aspect ratios accepted by the grok-imagine image models.\n */\nexport type GrokImagineAspectRatio =\n | '1:1'\n | '3:4'\n | '4:3'\n | '9:16'\n | '16:9'\n | '2:3'\n | '3:2'\n | '9:19.5'\n | '19.5:9'\n | '9:20'\n | '20:9'\n | '1:2'\n | '2:1'\n | 'auto'\n\n/**\n * Resolution tiers for the grok-imagine image models.\n */\nexport type GrokImagineResolution = '1k' | '2k'\n\n/**\n * Size strings for grok-imagine image models. The Imagine API is\n * aspect-ratio based rather than pixel-size based; like Gemini's native\n * image models, the generic `size` option uses an\n * `aspectRatio_resolution` template (\"16:9_2k\") — the resolution suffix is\n * optional (\"16:9\" uses the API default of 1k).\n */\nexport type GrokImagineImageSize =\n | GrokImagineAspectRatio\n | `${GrokImagineAspectRatio}_${GrokImagineResolution}`\n\nconst GROK_IMAGINE_ASPECT_RATIOS: ReadonlyArray<string> = [\n '1:1',\n '3:4',\n '4:3',\n '9:16',\n '16:9',\n '2:3',\n '3:2',\n '9:19.5',\n '19.5:9',\n '9:20',\n '20:9',\n '1:2',\n '2:1',\n 'auto',\n]\n\nconst GROK_IMAGINE_RESOLUTIONS: ReadonlyArray<string> = ['1k', '2k']\n\n/**\n * Models served by xAI's Imagine API. They are aspect-ratio sized and\n * support image-conditioned generation via `/v1/images/edits`; the legacy\n * grok-2-image-1212 model is pixel-sized and text-to-image only.\n */\nexport function isGrokImagineImageModel(model: string): boolean {\n return model.startsWith('grok-imagine-image')\n}\n\n/**\n * Parses a grok-imagine size string into its components.\n * Format: \"aspectRatio\" or \"aspectRatio_resolution\",\n * e.g. \"16:9_2k\" → { aspectRatio: \"16:9\", resolution: \"2k\" }.\n * Returns undefined when the string doesn't match the template.\n */\nexport function parseGrokImagineSize(\n size: string,\n): { aspectRatio: string; resolution?: string } | undefined {\n const match = size.match(/^([\\d.]+:[\\d.]+|auto)(?:_(.+))?$/)\n const [, aspectRatio, resolution] = match ?? []\n if (aspectRatio === undefined) return undefined\n return { aspectRatio, ...(resolution !== undefined && { resolution }) }\n}\n\n/**\n * Base provider options for Grok image models\n */\nexport interface GrokImageBaseProviderOptions {\n /**\n * A unique identifier representing your end-user.\n * Can help xAI to monitor and detect abuse.\n */\n user?: string\n}\n\n/**\n * Provider options for grok-2-image-1212 model\n */\nexport interface GrokImageProviderOptions extends GrokImageBaseProviderOptions {\n /**\n * The quality of the image.\n * @default 'standard'\n */\n quality?: 'standard' | 'hd'\n\n /**\n * The format in which generated images are returned.\n * URLs are only valid for 60 minutes after generation.\n * @default 'url'\n */\n response_format?: 'url' | 'b64_json'\n}\n\n/**\n * Provider options for the grok-imagine image models (generation and\n * image-conditioned editing via xAI's Imagine API).\n */\nexport interface GrokImagineImageProviderOptions extends GrokImageBaseProviderOptions {\n /**\n * The format in which generated images are returned.\n * @default 'url'\n */\n response_format?: 'url' | 'b64_json'\n\n /**\n * Output resolution.\n * @default '1k'\n */\n resolution?: '1k' | '2k'\n\n /**\n * Processing tier for the request.\n * @default 'default'\n */\n service_tier?: 'default' | 'priority'\n}\n\n/**\n * Provider options for grok-imagine-image-2.0, which adds a generation\n * `quality` knob on top of the shared Imagine options.\n */\nexport interface GrokImagineImage2ProviderOptions extends GrokImagineImageProviderOptions {\n /**\n * Generation quality. Only supported by grok-imagine-image-2.0.\n * @default 'medium'\n */\n quality?: 'low' | 'medium'\n}\n\n/**\n * Type-only map from model name to its specific provider options.\n */\nexport type GrokImageModelProviderOptionsByName = {\n 'grok-2-image-1212': GrokImageProviderOptions\n 'grok-imagine-image': GrokImagineImageProviderOptions\n 'grok-imagine-image-2.0': GrokImagineImage2ProviderOptions\n 'grok-imagine-image-quality': GrokImagineImageProviderOptions\n}\n\n/**\n * Type-only map from model name to its supported sizes.\n */\nexport type GrokImageModelSizeByName = {\n 'grok-2-image-1212': GrokImageSize\n 'grok-imagine-image': GrokImagineImageSize\n 'grok-imagine-image-2.0': GrokImagineImageSize\n 'grok-imagine-image-quality': GrokImagineImageSize\n}\n\n/**\n * Per-model prompt input modalities. Imagine API models accept image parts\n * in the prompt (routed to `/v1/images/edits`, up to 3 images, addressed by\n * xAI in request order); grok-2-image is text-to-image only.\n */\nexport type GrokImageModelInputModalitiesByName = {\n 'grok-2-image-1212': readonly []\n 'grok-imagine-image': readonly ['image']\n 'grok-imagine-image-2.0': readonly ['image']\n 'grok-imagine-image-quality': readonly ['image']\n}\n\n/**\n * Internal options interface for validation\n */\ninterface ImageValidationOptions {\n prompt: string\n model: string\n}\n\n/**\n * Validates that the provided size is supported by the model.\n * Throws a descriptive error if the size is not supported.\n */\nexport function validateImageSize(\n model: string,\n size: string | undefined,\n): void {\n if (!size) return\n\n if (isGrokImagineImageModel(model)) {\n const parsed = parseGrokImagineSize(size)\n if (\n !parsed ||\n !GROK_IMAGINE_ASPECT_RATIOS.includes(parsed.aspectRatio) ||\n (parsed.resolution !== undefined &&\n !GROK_IMAGINE_RESOLUTIONS.includes(parsed.resolution))\n ) {\n throw new Error(\n `Size \"${size}\" is not supported by model \"${model}\". ` +\n `Expected an aspect ratio (${GROK_IMAGINE_ASPECT_RATIOS.join(', ')}) ` +\n `optionally suffixed with a resolution (\"16:9_2k\"; resolutions: ${GROK_IMAGINE_RESOLUTIONS.join(', ')}).`,\n )\n }\n return\n }\n\n const validSizes: Record<string, Array<string>> = {\n 'grok-2-image-1212': ['1024x1024', '1536x1024', '1024x1536'],\n }\n\n const modelSizes = validSizes[model]\n if (!modelSizes) {\n throw new Error(`Unknown image model: ${model}`)\n }\n\n if (!modelSizes.includes(size)) {\n throw new Error(\n `Size \"${size}\" is not supported by model \"${model}\". ` +\n `Supported sizes: ${modelSizes.join(', ')}`,\n )\n }\n}\n\n/**\n * Validates that the number of images is within bounds for the model.\n */\nexport function validateNumberOfImages(\n _model: string,\n numberOfImages: number | undefined,\n): void {\n if (numberOfImages === undefined) return\n\n // grok-2-image-1212 supports 1-10 images per request\n if (numberOfImages < 1 || numberOfImages > 10) {\n throw new Error(\n `Number of images must be between 1 and 10. Requested: ${numberOfImages}`,\n )\n }\n}\n\nexport const validatePrompt = (options: ImageValidationOptions) => {\n if (options.prompt.length === 0) {\n throw new Error('Prompt cannot be empty.')\n }\n // Grok image model supports up to 4000 characters\n if (options.prompt.length > 4000) {\n throw new Error(\n 'For grok-2-image-1212, prompt length must be less than or equal to 4000 characters.',\n )\n }\n}\n"],"mappings":";AAgDA,IAAM,6BAAoD;CACxD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,IAAM,2BAAkD,CAAC,MAAM,IAAI;;;;;;AAOnE,SAAgB,wBAAwB,OAAwB;CAC9D,OAAO,MAAM,WAAW,oBAAoB;AAC9C;;;;;;;AAQA,SAAgB,qBACd,MAC0D;CAE1D,MAAM,GAAG,aAAa,cADR,KAAK,MAAM,kCACW,KAAS,CAAC;CAC9C,IAAI,gBAAgB,KAAA,GAAW,OAAO,KAAA;CACtC,OAAO;EAAE;EAAa,GAAI,eAAe,KAAA,KAAa,EAAE,WAAW;CAAG;AACxE;;;;;AA+GA,SAAgB,kBACd,OACA,MACM;CACN,IAAI,CAAC,MAAM;CAEX,IAAI,wBAAwB,KAAK,GAAG;EAClC,MAAM,SAAS,qBAAqB,IAAI;EACxC,IACE,CAAC,UACD,CAAC,2BAA2B,SAAS,OAAO,WAAW,KACtD,OAAO,eAAe,KAAA,KACrB,CAAC,yBAAyB,SAAS,OAAO,UAAU,GAEtD,MAAM,IAAI,MACR,SAAS,KAAK,+BAA+B,MAAM,+BACpB,2BAA2B,KAAK,IAAI,EAAE,mEACD,yBAAyB,KAAK,IAAI,EAAE,GAC1G;EAEF;CACF;CAMA,MAAM,aAAa,EAHjB,qBAAqB;EAAC;EAAa;EAAa;CAAW,EAG1C,EAAW;CAC9B,IAAI,CAAC,YACH,MAAM,IAAI,MAAM,wBAAwB,OAAO;CAGjD,IAAI,CAAC,WAAW,SAAS,IAAI,GAC3B,MAAM,IAAI,MACR,SAAS,KAAK,+BAA+B,MAAM,sBAC7B,WAAW,KAAK,IAAI,GAC5C;AAEJ;;;;AAKA,SAAgB,uBACd,QACA,gBACM;CACN,IAAI,mBAAmB,KAAA,GAAW;CAGlC,IAAI,iBAAiB,KAAK,iBAAiB,IACzC,MAAM,IAAI,MACR,yDAAyD,gBAC3D;AAEJ;AAEA,IAAa,kBAAkB,YAAoC;CACjE,IAAI,QAAQ,OAAO,WAAW,GAC5B,MAAM,IAAI,MAAM,yBAAyB;CAG3C,IAAI,QAAQ,OAAO,SAAS,KAC1B,MAAM,IAAI,MACR,qFACF;AAEJ"}
1
+ {"version":3,"file":"image-provider-options.js","names":[],"sources":["../../../src/image/image-provider-options.ts"],"sourcesContent":["/**\n * Grok Image Generation Provider Options\n *\n * Provider-specific options for Grok image generation: the aspect-ratio\n * sized Imagine API models (grok-imagine-image, grok-imagine-image-2.0,\n * grok-imagine-image-quality).\n */\n\n/**\n * Aspect ratios accepted by the grok-imagine image models.\n */\nexport type GrokImagineAspectRatio =\n | '1:1'\n | '3:4'\n | '4:3'\n | '9:16'\n | '16:9'\n | '2:3'\n | '3:2'\n | '9:19.5'\n | '19.5:9'\n | '9:20'\n | '20:9'\n | '1:2'\n | '2:1'\n | 'auto'\n\n/**\n * Resolution tiers for the grok-imagine image models.\n */\nexport type GrokImagineResolution = '1k' | '2k'\n\n/**\n * Size strings for grok-imagine image models. The Imagine API is\n * aspect-ratio based rather than pixel-size based; like Gemini's native\n * image models, the generic `size` option uses an\n * `aspectRatio_resolution` template (\"16:9_2k\") — the resolution suffix is\n * optional (\"16:9\" uses the API default of 1k).\n */\nexport type GrokImagineImageSize =\n | GrokImagineAspectRatio\n | `${GrokImagineAspectRatio}_${GrokImagineResolution}`\n\nconst GROK_IMAGINE_ASPECT_RATIOS: ReadonlyArray<string> = [\n '1:1',\n '3:4',\n '4:3',\n '9:16',\n '16:9',\n '2:3',\n '3:2',\n '9:19.5',\n '19.5:9',\n '9:20',\n '20:9',\n '1:2',\n '2:1',\n 'auto',\n]\n\nconst GROK_IMAGINE_RESOLUTIONS: ReadonlyArray<string> = ['1k', '2k']\n\n/**\n * Models served by xAI's Imagine API. They are aspect-ratio sized and\n * support image-conditioned generation via `/v1/images/edits`.\n */\nexport function isGrokImagineImageModel(model: string): boolean {\n return model.startsWith('grok-imagine-image')\n}\n\n/**\n * Parses a grok-imagine size string into its components.\n * Format: \"aspectRatio\" or \"aspectRatio_resolution\",\n * e.g. \"16:9_2k\" → { aspectRatio: \"16:9\", resolution: \"2k\" }.\n * Returns undefined when the string doesn't match the template.\n */\nexport function parseGrokImagineSize(\n size: string,\n): { aspectRatio: string; resolution?: string } | undefined {\n const match = size.match(/^([\\d.]+:[\\d.]+|auto)(?:_(.+))?$/)\n const [, aspectRatio, resolution] = match ?? []\n if (aspectRatio === undefined) return undefined\n return { aspectRatio, ...(resolution !== undefined && { resolution }) }\n}\n\n/**\n * Base provider options for Grok image models\n */\nexport interface GrokImageBaseProviderOptions {\n /**\n * A unique identifier representing your end-user.\n * Can help xAI to monitor and detect abuse.\n */\n user?: string\n}\n\n/**\n * Provider options for the grok-imagine image models (generation and\n * image-conditioned editing via xAI's Imagine API).\n */\nexport interface GrokImagineImageProviderOptions extends GrokImageBaseProviderOptions {\n /**\n * The format in which generated images are returned.\n * @default 'url'\n */\n response_format?: 'url' | 'b64_json'\n\n /**\n * Output resolution.\n * @default '1k'\n */\n resolution?: '1k' | '2k'\n\n /**\n * Processing tier for the request.\n * @default 'default'\n */\n service_tier?: 'default' | 'priority'\n}\n\n/**\n * Provider options for grok-imagine-image-2.0, which adds a generation\n * `quality` knob on top of the shared Imagine options.\n */\nexport interface GrokImagineImage2ProviderOptions extends GrokImagineImageProviderOptions {\n /**\n * Generation quality. Only supported by grok-imagine-image-2.0.\n * @default 'medium'\n */\n quality?: 'low' | 'medium'\n}\n\n/**\n * Type-only map from model name to its specific provider options.\n */\nexport type GrokImageModelProviderOptionsByName = {\n 'grok-imagine-image': GrokImagineImageProviderOptions\n 'grok-imagine-image-2.0': GrokImagineImage2ProviderOptions\n 'grok-imagine-image-quality': GrokImagineImageProviderOptions\n}\n\n/**\n * Type-only map from model name to its supported sizes.\n */\nexport type GrokImageModelSizeByName = {\n 'grok-imagine-image': GrokImagineImageSize\n 'grok-imagine-image-2.0': GrokImagineImageSize\n 'grok-imagine-image-quality': GrokImagineImageSize\n}\n\n/**\n * Per-model prompt input modalities. Imagine API models accept image parts\n * in the prompt (routed to `/v1/images/edits`, up to 3 images, addressed by\n * xAI in request order).\n */\nexport type GrokImageModelInputModalitiesByName = {\n 'grok-imagine-image': readonly ['image']\n 'grok-imagine-image-2.0': readonly ['image']\n 'grok-imagine-image-quality': readonly ['image']\n}\n\n/**\n * Validates that the provided size is supported by the model.\n * Throws a descriptive error if the size is not supported.\n */\nexport function validateImageSize(\n model: string,\n size: string | undefined,\n): void {\n if (!size) return\n\n if (isGrokImagineImageModel(model)) {\n const parsed = parseGrokImagineSize(size)\n if (\n !parsed ||\n !GROK_IMAGINE_ASPECT_RATIOS.includes(parsed.aspectRatio) ||\n (parsed.resolution !== undefined &&\n !GROK_IMAGINE_RESOLUTIONS.includes(parsed.resolution))\n ) {\n throw new Error(\n `Size \"${size}\" is not supported by model \"${model}\". ` +\n `Expected an aspect ratio (${GROK_IMAGINE_ASPECT_RATIOS.join(', ')}) ` +\n `optionally suffixed with a resolution (\"16:9_2k\"; resolutions: ${GROK_IMAGINE_RESOLUTIONS.join(', ')}).`,\n )\n }\n return\n }\n\n throw new Error(`Unknown image model: ${model}`)\n}\n\n/**\n * Validates that the number of images is within bounds for the model.\n */\nexport function validateNumberOfImages(\n _model: string,\n numberOfImages: number | undefined,\n): void {\n if (numberOfImages === undefined) return\n\n // Imagine image models accept 1-10 images per request.\n if (numberOfImages < 1 || numberOfImages > 10) {\n throw new Error(\n `Number of images must be between 1 and 10. Requested: ${numberOfImages}`,\n )\n }\n}\n\nexport const validatePrompt = (prompt: string) => {\n if (prompt.length === 0) {\n throw new Error('Prompt cannot be empty.')\n }\n}\n"],"mappings":";AA2CA,IAAM,6BAAoD;CACxD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,IAAM,2BAAkD,CAAC,MAAM,IAAI;;;;;AAMnE,SAAgB,wBAAwB,OAAwB;CAC9D,OAAO,MAAM,WAAW,oBAAoB;AAC9C;;;;;;;AAQA,SAAgB,qBACd,MAC0D;CAE1D,MAAM,GAAG,aAAa,cADR,KAAK,MAAM,kCACW,KAAS,CAAC;CAC9C,IAAI,gBAAgB,KAAA,GAAW,OAAO,KAAA;CACtC,OAAO;EAAE;EAAa,GAAI,eAAe,KAAA,KAAa,EAAE,WAAW;CAAG;AACxE;;;;;AAkFA,SAAgB,kBACd,OACA,MACM;CACN,IAAI,CAAC,MAAM;CAEX,IAAI,wBAAwB,KAAK,GAAG;EAClC,MAAM,SAAS,qBAAqB,IAAI;EACxC,IACE,CAAC,UACD,CAAC,2BAA2B,SAAS,OAAO,WAAW,KACtD,OAAO,eAAe,KAAA,KACrB,CAAC,yBAAyB,SAAS,OAAO,UAAU,GAEtD,MAAM,IAAI,MACR,SAAS,KAAK,+BAA+B,MAAM,+BACpB,2BAA2B,KAAK,IAAI,EAAE,mEACD,yBAAyB,KAAK,IAAI,EAAE,GAC1G;EAEF;CACF;CAEA,MAAM,IAAI,MAAM,wBAAwB,OAAO;AACjD;;;;AAKA,SAAgB,uBACd,QACA,gBACM;CACN,IAAI,mBAAmB,KAAA,GAAW;CAGlC,IAAI,iBAAiB,KAAK,iBAAiB,IACzC,MAAM,IAAI,MACR,yDAAyD,gBAC3D;AAEJ;AAEA,IAAa,kBAAkB,WAAmB;CAChD,IAAI,OAAO,WAAW,GACpB,MAAM,IAAI,MAAM,yBAAyB;AAE7C"}
@@ -1,7 +1,7 @@
1
1
  export { GrokTextAdapter, createGrokText, grokText, type GrokTextConfig, type GrokTextProviderOptions, } from './adapters/text.js';
2
2
  export { createGrokSummarize, grokSummarize, type GrokSummarizeConfig, type GrokSummarizeModel, } from './adapters/summarize.js';
3
3
  export { GrokImageAdapter, createGrokImage, grokImage, type GrokImageConfig, } from './adapters/image.js';
4
- export type { GrokImageProviderOptions, GrokImagineImageProviderOptions, GrokImagineImage2ProviderOptions, GrokImageModelProviderOptionsByName, } from './image/image-provider-options.js';
4
+ export type { GrokImagineImageProviderOptions, GrokImagineImage2ProviderOptions, GrokImageModelProviderOptionsByName, } from './image/image-provider-options.js';
5
5
  export { GrokVideoAdapter, createGrokVideo, grokVideo, type GrokVideoConfig, } from './adapters/video.js';
6
6
  export { GROK_VIDEO_DURATIONS, getGrokVideoDurationOptions, } from './video/video-provider-options.js';
7
7
  export type { GrokVideoMode, GrokVideoBaseProviderOptions, GrokVideoSourceProviderOptions, GrokVideoProviderOptions, GrokVideoRuntimeOptions, GrokVideoModelProviderOptionsByName, GrokVideoModelSizeByName, GrokVideoModelDurationByName, GrokVideoAspectRatio, GrokVideoResolution, GrokVideoSize, } from './video/video-provider-options.js';
@@ -37,6 +37,26 @@ declare const GROK_4_6: {
37
37
  };
38
38
  };
39
39
  };
40
+ declare const GROK_4_7: {
41
+ readonly name: "grok-4.7";
42
+ readonly context_window: 500000;
43
+ readonly max_output_tokens: 450000;
44
+ readonly supports: {
45
+ readonly input: ["text", "image", "document"];
46
+ readonly output: ["text"];
47
+ readonly capabilities: ["reasoning", "structured_outputs", "tool_calling"];
48
+ readonly tools: readonly [];
49
+ };
50
+ readonly pricing: {
51
+ readonly input: {
52
+ readonly normal: 1.6;
53
+ readonly cached: 0.4;
54
+ };
55
+ readonly output: {
56
+ readonly normal: 4.8;
57
+ };
58
+ };
59
+ };
40
60
  export type GrokProviderToolKind = 'web_search' | 'x_search' | 'file_search' | 'mcp';
41
61
  declare const GROK_4_3: {
42
62
  readonly name: "grok-4.3";
@@ -119,7 +139,7 @@ declare const GROK_4_1_FAST_NON_REASONING: {
119
139
  /**
120
140
  * Grok chat models supported by the xAI Responses adapter.
121
141
  */
122
- export declare const GROK_CHAT_MODELS: readonly ["grok-4.5", "grok-4.6", "grok-build-0.1", "grok-4.3"];
142
+ export declare const GROK_CHAT_MODELS: readonly ["grok-4.7", "grok-4.5", "grok-4.6", "grok-build-0.1", "grok-4.3"];
123
143
  /**
124
144
  * Grok chat models on Vertex AI / Gemini Enterprise Agent Platform.
125
145
  * This list is the Google partner catalog, not the xAI API catalog.
@@ -128,7 +148,7 @@ export declare const GROK_VERTEX_CHAT_MODELS: readonly ["grok-4.3", "grok-4.20-r
128
148
  /**
129
149
  * Grok Image Generation Models
130
150
  */
131
- export declare const GROK_IMAGE_MODELS: readonly ["grok-2-image-1212", "grok-imagine-image", "grok-imagine-image-2.0", "grok-imagine-image-quality"];
151
+ export declare const GROK_IMAGE_MODELS: readonly ["grok-imagine-image", "grok-imagine-image-2.0", "grok-imagine-image-quality"];
132
152
  /**
133
153
  * Grok Video Generation Models (xAI Imagine API)
134
154
  *
@@ -165,6 +185,7 @@ export type GrokModelInputModalitiesByName = {
165
185
  [GROK_4_20_NON_REASONING.name]: typeof GROK_4_20_NON_REASONING.supports.input;
166
186
  [GROK_4_1_FAST_REASONING.name]: typeof GROK_4_1_FAST_REASONING.supports.input;
167
187
  [GROK_4_1_FAST_NON_REASONING.name]: typeof GROK_4_1_FAST_NON_REASONING.supports.input;
188
+ [GROK_4_7.name]: typeof GROK_4_7.supports.input;
168
189
  };
169
190
  /**
170
191
  * Type-only map from Grok chat model name to its supported provider tools.
@@ -178,6 +199,7 @@ export type GrokChatModelToolCapabilitiesByName = {
178
199
  [GROK_4_20_NON_REASONING.name]: typeof GROK_4_20_NON_REASONING.supports.tools;
179
200
  [GROK_4_1_FAST_REASONING.name]: typeof GROK_4_1_FAST_REASONING.supports.tools;
180
201
  [GROK_4_1_FAST_NON_REASONING.name]: typeof GROK_4_1_FAST_NON_REASONING.supports.tools;
202
+ [GROK_4_7.name]: typeof GROK_4_7.supports.tools;
181
203
  };
182
204
  export type GrokProviderOptions = GrokTextProviderOptions;
183
205
  /**
@@ -49,23 +49,38 @@ var GROK_4_6 = {
49
49
  output: { normal: 6 }
50
50
  }
51
51
  };
52
+ var GROK_4_7 = {
53
+ name: "grok-4.7",
54
+ context_window: 5e5,
55
+ max_output_tokens: 45e4,
56
+ supports: {
57
+ input: [
58
+ "text",
59
+ "image",
60
+ "document"
61
+ ],
62
+ output: ["text"],
63
+ capabilities: [
64
+ "reasoning",
65
+ "structured_outputs",
66
+ "tool_calling"
67
+ ],
68
+ tools: []
69
+ },
70
+ pricing: {
71
+ input: {
72
+ normal: 1.6,
73
+ cached: .4
74
+ },
75
+ output: { normal: 4.8 }
76
+ }
77
+ };
52
78
  var GROK_RESPONSES_TOOLS = [
53
79
  "web_search",
54
80
  "x_search",
55
81
  "file_search",
56
82
  "mcp"
57
83
  ];
58
- var GROK_2_IMAGE = {
59
- name: "grok-2-image-1212",
60
- supports: {
61
- input: ["text"],
62
- output: ["image"]
63
- },
64
- pricing: {
65
- input: { normal: .07 },
66
- output: { normal: .07 }
67
- }
68
- };
69
84
  var GROK_IMAGINE_IMAGE = {
70
85
  name: "grok-imagine-image",
71
86
  supports: {
@@ -219,6 +234,7 @@ var GROK_4_1_FAST_NON_REASONING = {
219
234
  * Grok chat models supported by the xAI Responses adapter.
220
235
  */
221
236
  var GROK_CHAT_MODELS = [
237
+ GROK_4_7.name,
222
238
  GROK_4_5.name,
223
239
  GROK_4_6.name,
224
240
  GROK_BUILD_0_1.name,
@@ -239,7 +255,6 @@ var GROK_VERTEX_CHAT_MODELS = [
239
255
  * Grok Image Generation Models
240
256
  */
241
257
  var GROK_IMAGE_MODELS = [
242
- GROK_2_IMAGE.name,
243
258
  GROK_IMAGINE_IMAGE.name,
244
259
  GROK_IMAGINE_IMAGE_2_0.name,
245
260
  GROK_IMAGINE_IMAGE_QUALITY.name
@@ -1 +1 @@
1
- {"version":3,"file":"model-meta.js","names":[],"sources":["../../src/model-meta.ts"],"sourcesContent":["/**\n * Model metadata interface for documentation and type inference\n */\nimport type {\n GrokBuildProviderOptions,\n GrokTextProviderOptions,\n} from './text/text-provider-options'\n\ninterface ModelMeta {\n name: string\n supports: {\n input: Array<'text' | 'image' | 'audio' | 'video' | 'document'>\n output: Array<'text' | 'image' | 'audio' | 'video'>\n capabilities?: Array<'reasoning' | 'tool_calling' | 'structured_outputs'>\n tools?: ReadonlyArray<GrokProviderToolKind>\n }\n max_input_tokens?: number\n max_output_tokens?: number\n context_window?: number\n knowledge_cutoff?: string\n pricing?: {\n input: {\n normal: number\n cached?: number\n }\n output: {\n normal: number\n }\n }\n}\n\nconst GROK_4_5 = {\n name: 'grok-4.5',\n context_window: 500_000,\n supports: {\n input: ['text', 'image', 'document'],\n output: ['text'],\n capabilities: ['reasoning', 'structured_outputs', 'tool_calling'],\n tools: [],\n },\n pricing: {\n input: {\n normal: 2,\n cached: 0.3,\n },\n output: {\n normal: 6,\n },\n },\n} as const satisfies ModelMeta\n\nconst GROK_4_6 = {\n name: 'grok-4.6',\n context_window: 500_000,\n supports: {\n input: ['text', 'image', 'document'],\n output: ['text'],\n capabilities: ['reasoning', 'structured_outputs', 'tool_calling'],\n tools: [],\n },\n pricing: {\n input: {\n normal: 2,\n cached: 0.5,\n },\n output: {\n normal: 6,\n },\n },\n} as const satisfies ModelMeta\n\nexport type GrokProviderToolKind =\n | 'web_search'\n | 'x_search'\n | 'file_search'\n | 'mcp'\n\nconst GROK_RESPONSES_TOOLS = [\n 'web_search',\n 'x_search',\n 'file_search',\n 'mcp',\n] as const satisfies ReadonlyArray<GrokProviderToolKind>\n\nconst GROK_2_IMAGE = {\n name: 'grok-2-image-1212',\n supports: {\n input: ['text'],\n output: ['image'],\n },\n pricing: {\n input: {\n normal: 0.07,\n },\n output: {\n normal: 0.07,\n },\n },\n} as const satisfies ModelMeta\n\n// Imagine API image models. Pricing is per generated image (output only).\nconst GROK_IMAGINE_IMAGE = {\n name: 'grok-imagine-image',\n supports: {\n input: ['text', 'image'],\n output: ['image'],\n },\n pricing: {\n input: {\n normal: 0,\n },\n output: {\n normal: 0.02,\n },\n },\n} as const satisfies ModelMeta\n\nconst GROK_IMAGINE_IMAGE_QUALITY = {\n name: 'grok-imagine-image-quality',\n supports: {\n input: ['text', 'image'],\n output: ['image'],\n },\n pricing: {\n input: {\n normal: 0,\n },\n output: {\n normal: 0.05,\n },\n },\n} as const satisfies ModelMeta\n\n// xAI's recommended Imagine image model. Supports the 2.0-only `quality`\n// provider option ('low' | 'medium', default 'medium').\nconst GROK_IMAGINE_IMAGE_2_0 = {\n name: 'grok-imagine-image-2.0',\n supports: {\n input: ['text', 'image'],\n output: ['image'],\n },\n pricing: {\n input: {\n normal: 0,\n },\n output: {\n normal: 0.04,\n },\n },\n} as const satisfies ModelMeta\n\n// Imagine API video models. Pricing is per second of generated video\n// (output only); generated videos carry an audio track.\n//\n// Both models support text-to-video and image-to-video (a starting-frame\n// image is optional). grok-imagine-video-1.5 is the documented default: it\n// adds native 1080p for text-to-video / image-to-video plus\n// reference-to-video (`reference_images` / `reference_audios`; reference\n// output is capped at 720p). Source-video edit (`/v1/videos/edits`) and\n// extend (`/v1/videos/extensions`) are grok-imagine-video only — xAI's\n// 1.5 model page lists text+image input, not video.\nconst GROK_IMAGINE_VIDEO = {\n name: 'grok-imagine-video',\n supports: {\n input: ['text', 'image', 'video'],\n output: ['video', 'audio'],\n },\n pricing: {\n input: {\n normal: 0,\n },\n output: {\n // per second of video\n normal: 0.05,\n },\n },\n} as const satisfies ModelMeta\n\nconst GROK_IMAGINE_VIDEO_1_5 = {\n name: 'grok-imagine-video-1.5',\n supports: {\n input: ['text', 'image'],\n output: ['video', 'audio'],\n },\n pricing: {\n input: {\n normal: 0,\n },\n output: {\n // per second of video\n normal: 0.08,\n },\n },\n} as const satisfies ModelMeta\n\nconst GROK_4_3 = {\n name: 'grok-4.3',\n context_window: 1_000_000,\n supports: {\n input: ['text', 'image'],\n output: ['text'],\n capabilities: ['reasoning', 'structured_outputs', 'tool_calling'],\n tools: GROK_RESPONSES_TOOLS,\n },\n pricing: {\n input: {\n normal: 1.25,\n cached: 0.2,\n },\n output: {\n normal: 2.5,\n },\n },\n} as const satisfies ModelMeta\n\nconst GROK_BUILD_0_1 = {\n name: 'grok-build-0.1',\n context_window: 256_000,\n supports: {\n input: ['text', 'image'],\n output: ['text'],\n capabilities: ['reasoning', 'structured_outputs', 'tool_calling'],\n tools: GROK_RESPONSES_TOOLS,\n },\n pricing: {\n input: {\n normal: 1,\n cached: 0.2,\n },\n output: {\n normal: 2,\n },\n },\n} as const satisfies ModelMeta\n\n// Vertex Model Garden IDs. These are not the xAI API catalog.\n// Source: https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/partner-models/grok\nconst GROK_4_20_REASONING = {\n name: 'grok-4.20-reasoning',\n context_window: 1_000_000,\n supports: {\n input: ['text', 'image'],\n output: ['text'],\n capabilities: ['reasoning', 'structured_outputs', 'tool_calling'],\n tools: [] as const,\n },\n} as const satisfies ModelMeta\n\nconst GROK_4_20_NON_REASONING = {\n name: 'grok-4.20-non-reasoning',\n context_window: 1_000_000,\n supports: {\n input: ['text', 'image'],\n output: ['text'],\n capabilities: ['structured_outputs', 'tool_calling'],\n tools: [] as const,\n },\n} as const satisfies ModelMeta\n\nconst GROK_4_1_FAST_REASONING = {\n name: 'grok-4.1-fast-reasoning',\n context_window: 2_000_000,\n supports: {\n input: ['text', 'image'],\n output: ['text'],\n capabilities: ['reasoning', 'structured_outputs', 'tool_calling'],\n tools: [] as const,\n },\n} as const satisfies ModelMeta\n\nconst GROK_4_1_FAST_NON_REASONING = {\n name: 'grok-4.1-fast-non-reasoning',\n context_window: 2_000_000,\n supports: {\n input: ['text', 'image'],\n output: ['text'],\n capabilities: ['structured_outputs', 'tool_calling'],\n tools: [] as const,\n },\n} as const satisfies ModelMeta\n\n/**\n * Grok chat models supported by the xAI Responses adapter.\n */\nexport const GROK_CHAT_MODELS = [\n GROK_4_5.name,\n GROK_4_6.name,\n GROK_BUILD_0_1.name,\n GROK_4_3.name,\n] as const\n\n/**\n * Grok chat models on Vertex AI / Gemini Enterprise Agent Platform.\n * This list is the Google partner catalog, not the xAI API catalog.\n */\nexport const GROK_VERTEX_CHAT_MODELS = [\n GROK_4_3.name,\n GROK_4_20_REASONING.name,\n GROK_4_20_NON_REASONING.name,\n GROK_4_1_FAST_REASONING.name,\n GROK_4_1_FAST_NON_REASONING.name,\n] as const\n\n/**\n * Grok Image Generation Models\n */\nexport const GROK_IMAGE_MODELS = [\n GROK_2_IMAGE.name,\n GROK_IMAGINE_IMAGE.name,\n GROK_IMAGINE_IMAGE_2_0.name,\n GROK_IMAGINE_IMAGE_QUALITY.name,\n] as const\n\n/**\n * Grok Video Generation Models (xAI Imagine API)\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport const GROK_VIDEO_MODELS = [\n GROK_IMAGINE_VIDEO.name,\n GROK_IMAGINE_VIDEO_1_5.name,\n] as const\n\n// xAI's `/v1/tts` endpoint is endpoint-addressed and does not take a `model`\n// parameter. This synthetic identifier satisfies the SDK's `TTSOptions.model`\n// contract and provides a stable value for logging and fixture matching.\nconst GROK_TTS = {\n name: 'grok-tts',\n supports: {\n input: ['text'],\n output: ['audio'],\n },\n} as const satisfies ModelMeta\n\n// xAI's `/v1/stt` endpoint is endpoint-addressed and does not take a `model`\n// parameter. This synthetic identifier satisfies the SDK's\n// `TranscriptionOptions.model` contract.\nconst GROK_STT = {\n name: 'grok-stt',\n supports: {\n input: ['audio'],\n output: ['text'],\n },\n} as const satisfies ModelMeta\n\nconst GROK_VOICE_FAST_1 = {\n name: 'grok-voice-fast-1.0',\n supports: {\n input: ['audio', 'text'],\n output: ['audio', 'text'],\n capabilities: ['tool_calling'],\n tools: [] as const,\n },\n} as const satisfies ModelMeta\n\n/** @deprecated xAI has deprecated grok-voice-think-fast-1.0 — use grok-voice-think-fast-2.0. */\nconst GROK_VOICE_THINK_FAST_1 = {\n name: 'grok-voice-think-fast-1.0',\n supports: {\n input: ['audio', 'text'],\n output: ['audio', 'text'],\n capabilities: ['reasoning', 'tool_calling'],\n tools: [] as const,\n },\n} as const satisfies ModelMeta\n\n// xAI's current recommended speech-to-speech model.\nconst GROK_VOICE_THINK_FAST_2 = {\n name: 'grok-voice-think-fast-2.0',\n supports: {\n input: ['audio', 'text'],\n output: ['audio', 'text'],\n capabilities: ['reasoning', 'tool_calling'],\n tools: [] as const,\n },\n} as const satisfies ModelMeta\n\n// Rolling alias used by xAI's realtime docs examples; always points at the\n// latest speech-to-speech model.\nconst GROK_VOICE_LATEST = {\n name: 'grok-voice-latest',\n supports: {\n input: ['audio', 'text'],\n output: ['audio', 'text'],\n capabilities: ['reasoning', 'tool_calling'],\n tools: [] as const,\n },\n} as const satisfies ModelMeta\n\nexport const GROK_TTS_MODELS = [GROK_TTS.name] as const\n\nexport const GROK_TRANSCRIPTION_MODELS = [GROK_STT.name] as const\n\nexport const GROK_REALTIME_MODELS = [\n GROK_VOICE_THINK_FAST_2.name,\n GROK_VOICE_LATEST.name,\n GROK_VOICE_FAST_1.name,\n GROK_VOICE_THINK_FAST_1.name,\n] as const\n\n/**\n * Default speech-to-speech model used by the realtime token issuer and the\n * realtime client adapter when no model is specified. Single source of truth\n * so a future default bump cannot leave the two sides disagreeing.\n */\nexport const GROK_DEFAULT_REALTIME_MODEL: GrokRealtimeModel =\n 'grok-voice-think-fast-2.0'\n\nexport type GrokChatModel = (typeof GROK_CHAT_MODELS)[number]\nexport type GrokVertexChatModel = (typeof GROK_VERTEX_CHAT_MODELS)[number]\nexport type GrokTextAdapterModel = GrokChatModel | GrokVertexChatModel\nexport type GrokImageModel = (typeof GROK_IMAGE_MODELS)[number]\nexport type GrokVideoModel = (typeof GROK_VIDEO_MODELS)[number]\nexport type GrokTTSModel = (typeof GROK_TTS_MODELS)[number]\nexport type GrokTranscriptionModel = (typeof GROK_TRANSCRIPTION_MODELS)[number]\nexport type GrokRealtimeModel = (typeof GROK_REALTIME_MODELS)[number]\n\n/**\n * Type-only map from Grok chat model name to its supported input modalities.\n * Used for type inference when constructing multimodal messages.\n */\nexport type GrokModelInputModalitiesByName = {\n [GROK_4_3.name]: typeof GROK_4_3.supports.input\n [GROK_BUILD_0_1.name]: typeof GROK_BUILD_0_1.supports.input\n [GROK_4_5.name]: typeof GROK_4_5.supports.input\n [GROK_4_6.name]: typeof GROK_4_6.supports.input\n [GROK_4_20_REASONING.name]: typeof GROK_4_20_REASONING.supports.input\n [GROK_4_20_NON_REASONING.name]: typeof GROK_4_20_NON_REASONING.supports.input\n [GROK_4_1_FAST_REASONING.name]: typeof GROK_4_1_FAST_REASONING.supports.input\n [GROK_4_1_FAST_NON_REASONING.name]: typeof GROK_4_1_FAST_NON_REASONING.supports.input\n}\n\n/**\n * Type-only map from Grok chat model name to its supported provider tools.\n * Keeps Grok provider-tool factories type-checked against the models that\n * advertise xAI Responses server-side tools.\n */\nexport type GrokChatModelToolCapabilitiesByName = {\n [GROK_4_3.name]: typeof GROK_4_3.supports.tools\n [GROK_BUILD_0_1.name]: typeof GROK_BUILD_0_1.supports.tools\n [GROK_4_20_REASONING.name]: typeof GROK_4_20_REASONING.supports.tools\n [GROK_4_20_NON_REASONING.name]: typeof GROK_4_20_NON_REASONING.supports.tools\n [GROK_4_1_FAST_REASONING.name]: typeof GROK_4_1_FAST_REASONING.supports.tools\n [GROK_4_1_FAST_NON_REASONING.name]: typeof GROK_4_1_FAST_NON_REASONING.supports.tools\n}\n\nexport type GrokProviderOptions = GrokTextProviderOptions\n\n/**\n * Type-only map from Grok chat model name to its provider options type.\n */\nexport type GrokChatModelProviderOptionsByName = {\n [GROK_4_3.name]: GrokProviderOptions\n [GROK_BUILD_0_1.name]: GrokBuildProviderOptions\n [GROK_4_20_REASONING.name]: GrokProviderOptions\n [GROK_4_20_NON_REASONING.name]: GrokProviderOptions\n [GROK_4_1_FAST_REASONING.name]: GrokProviderOptions\n [GROK_4_1_FAST_NON_REASONING.name]: GrokProviderOptions\n}\n\n// ===========================\n// Type Resolution Helpers\n// ===========================\n\n/**\n * Resolve provider options for a specific model.\n * If the model has explicit options in the map, use those; otherwise use base options.\n */\nexport type ResolveProviderOptions<TModel extends string> =\n TModel extends keyof GrokChatModelProviderOptionsByName\n ? GrokChatModelProviderOptionsByName[TModel]\n : GrokProviderOptions\n\n/**\n * Resolve input modalities for a specific model.\n * If the model has explicit modalities in the map, use those; otherwise use text only.\n */\nexport type ResolveInputModalities<TModel extends string> =\n TModel extends keyof GrokModelInputModalitiesByName\n ? GrokModelInputModalitiesByName[TModel]\n : readonly ['text']\n"],"mappings":";AA+BA,IAAM,WAAW;CACf,MAAM;CACN,gBAAgB;CAChB,UAAU;EACR,OAAO;GAAC;GAAQ;GAAS;EAAU;EACnC,QAAQ,CAAC,MAAM;EACf,cAAc;GAAC;GAAa;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xB,cAAc,CAAC,aAAa,cAAc;EAC1C,OAAO,CAAC;CACV;AACF;AAIA,IAAM,oBAAoB;CACxB,MAAM;CACN,UAAU;EACR,OAAO,CAAC,SAAS,MAAM;EACvB,QAAQ,CAAC,SAAS,MAAM;EACxB,cAAc,CAAC,aAAa,cAAc;EAC1C,OAAO,CAAC;CACV;AACF;AAEA,IAAa,kBAAkB,CAAC,SAAS,IAAI;AAE7C,IAAa,4BAA4B,CAAC,SAAS,IAAI;AAEvD,IAAa,uBAAuB;CAClC,wBAAwB;CACxB,kBAAkB;CAClB,kBAAkB;CAClB,wBAAwB;AAC1B;;;;;;AAOA,IAAa,8BACX"}
1
+ {"version":3,"file":"model-meta.js","names":[],"sources":["../../src/model-meta.ts"],"sourcesContent":["/**\n * Model metadata interface for documentation and type inference\n */\nimport type {\n GrokBuildProviderOptions,\n GrokTextProviderOptions,\n} from './text/text-provider-options'\n\ninterface ModelMeta {\n name: string\n supports: {\n input: Array<'text' | 'image' | 'audio' | 'video' | 'document'>\n output: Array<'text' | 'image' | 'audio' | 'video'>\n capabilities?: Array<'reasoning' | 'tool_calling' | 'structured_outputs'>\n tools?: ReadonlyArray<GrokProviderToolKind>\n }\n max_input_tokens?: number\n max_output_tokens?: number\n context_window?: number\n knowledge_cutoff?: string\n pricing?: {\n input: {\n normal: number\n cached?: number\n }\n output: {\n normal: number\n }\n }\n}\n\nconst GROK_4_5 = {\n name: 'grok-4.5',\n context_window: 500_000,\n supports: {\n input: ['text', 'image', 'document'],\n output: ['text'],\n capabilities: ['reasoning', 'structured_outputs', 'tool_calling'],\n tools: [],\n },\n pricing: {\n input: {\n normal: 2,\n cached: 0.3,\n },\n output: {\n normal: 6,\n },\n },\n} as const satisfies ModelMeta\n\nconst GROK_4_6 = {\n name: 'grok-4.6',\n context_window: 500_000,\n supports: {\n input: ['text', 'image', 'document'],\n output: ['text'],\n capabilities: ['reasoning', 'structured_outputs', 'tool_calling'],\n tools: [],\n },\n pricing: {\n input: {\n normal: 2,\n cached: 0.5,\n },\n output: {\n normal: 6,\n },\n },\n} as const satisfies ModelMeta\n\nconst GROK_4_7 = {\n name: 'grok-4.7',\n context_window: 500_000,\n max_output_tokens: 450_000,\n supports: {\n input: ['text', 'image', 'document'],\n output: ['text'],\n capabilities: ['reasoning', 'structured_outputs', 'tool_calling'],\n tools: [],\n },\n pricing: {\n input: {\n normal: 1.6,\n cached: 0.4,\n },\n output: {\n normal: 4.8,\n },\n },\n} as const satisfies ModelMeta\n\nexport type GrokProviderToolKind =\n | 'web_search'\n | 'x_search'\n | 'file_search'\n | 'mcp'\n\nconst GROK_RESPONSES_TOOLS = [\n 'web_search',\n 'x_search',\n 'file_search',\n 'mcp',\n] as const satisfies ReadonlyArray<GrokProviderToolKind>\n\n// Imagine API image models. Pricing is per generated image (output only).\nconst GROK_IMAGINE_IMAGE = {\n name: 'grok-imagine-image',\n supports: {\n input: ['text', 'image'],\n output: ['image'],\n },\n pricing: {\n input: {\n normal: 0,\n },\n output: {\n normal: 0.02,\n },\n },\n} as const satisfies ModelMeta\n\nconst GROK_IMAGINE_IMAGE_QUALITY = {\n name: 'grok-imagine-image-quality',\n supports: {\n input: ['text', 'image'],\n output: ['image'],\n },\n pricing: {\n input: {\n normal: 0,\n },\n output: {\n normal: 0.05,\n },\n },\n} as const satisfies ModelMeta\n\n// xAI's recommended Imagine image model. Supports the 2.0-only `quality`\n// provider option ('low' | 'medium', default 'medium').\nconst GROK_IMAGINE_IMAGE_2_0 = {\n name: 'grok-imagine-image-2.0',\n supports: {\n input: ['text', 'image'],\n output: ['image'],\n },\n pricing: {\n input: {\n normal: 0,\n },\n output: {\n normal: 0.04,\n },\n },\n} as const satisfies ModelMeta\n\n// Imagine API video models. Pricing is per second of generated video\n// (output only); generated videos carry an audio track.\n//\n// Both models support text-to-video and image-to-video (a starting-frame\n// image is optional). grok-imagine-video-1.5 is the documented default: it\n// adds native 1080p for text-to-video / image-to-video plus\n// reference-to-video (`reference_images` / `reference_audios`; reference\n// output is capped at 720p). Source-video edit (`/v1/videos/edits`) and\n// extend (`/v1/videos/extensions`) are grok-imagine-video only — xAI's\n// 1.5 model page lists text+image input, not video.\nconst GROK_IMAGINE_VIDEO = {\n name: 'grok-imagine-video',\n supports: {\n input: ['text', 'image', 'video'],\n output: ['video', 'audio'],\n },\n pricing: {\n input: {\n normal: 0,\n },\n output: {\n // per second of video\n normal: 0.05,\n },\n },\n} as const satisfies ModelMeta\n\nconst GROK_IMAGINE_VIDEO_1_5 = {\n name: 'grok-imagine-video-1.5',\n supports: {\n input: ['text', 'image'],\n output: ['video', 'audio'],\n },\n pricing: {\n input: {\n normal: 0,\n },\n output: {\n // per second of video\n normal: 0.08,\n },\n },\n} as const satisfies ModelMeta\n\nconst GROK_4_3 = {\n name: 'grok-4.3',\n context_window: 1_000_000,\n supports: {\n input: ['text', 'image'],\n output: ['text'],\n capabilities: ['reasoning', 'structured_outputs', 'tool_calling'],\n tools: GROK_RESPONSES_TOOLS,\n },\n pricing: {\n input: {\n normal: 1.25,\n cached: 0.2,\n },\n output: {\n normal: 2.5,\n },\n },\n} as const satisfies ModelMeta\n\nconst GROK_BUILD_0_1 = {\n name: 'grok-build-0.1',\n context_window: 256_000,\n supports: {\n input: ['text', 'image'],\n output: ['text'],\n capabilities: ['reasoning', 'structured_outputs', 'tool_calling'],\n tools: GROK_RESPONSES_TOOLS,\n },\n pricing: {\n input: {\n normal: 1,\n cached: 0.2,\n },\n output: {\n normal: 2,\n },\n },\n} as const satisfies ModelMeta\n\n// Vertex Model Garden IDs. These are not the xAI API catalog.\n// Source: https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/partner-models/grok\nconst GROK_4_20_REASONING = {\n name: 'grok-4.20-reasoning',\n context_window: 1_000_000,\n supports: {\n input: ['text', 'image'],\n output: ['text'],\n capabilities: ['reasoning', 'structured_outputs', 'tool_calling'],\n tools: [] as const,\n },\n} as const satisfies ModelMeta\n\nconst GROK_4_20_NON_REASONING = {\n name: 'grok-4.20-non-reasoning',\n context_window: 1_000_000,\n supports: {\n input: ['text', 'image'],\n output: ['text'],\n capabilities: ['structured_outputs', 'tool_calling'],\n tools: [] as const,\n },\n} as const satisfies ModelMeta\n\nconst GROK_4_1_FAST_REASONING = {\n name: 'grok-4.1-fast-reasoning',\n context_window: 2_000_000,\n supports: {\n input: ['text', 'image'],\n output: ['text'],\n capabilities: ['reasoning', 'structured_outputs', 'tool_calling'],\n tools: [] as const,\n },\n} as const satisfies ModelMeta\n\nconst GROK_4_1_FAST_NON_REASONING = {\n name: 'grok-4.1-fast-non-reasoning',\n context_window: 2_000_000,\n supports: {\n input: ['text', 'image'],\n output: ['text'],\n capabilities: ['structured_outputs', 'tool_calling'],\n tools: [] as const,\n },\n} as const satisfies ModelMeta\n\n/**\n * Grok chat models supported by the xAI Responses adapter.\n */\nexport const GROK_CHAT_MODELS = [\n GROK_4_7.name,\n GROK_4_5.name,\n GROK_4_6.name,\n GROK_BUILD_0_1.name,\n GROK_4_3.name,\n] as const\n\n/**\n * Grok chat models on Vertex AI / Gemini Enterprise Agent Platform.\n * This list is the Google partner catalog, not the xAI API catalog.\n */\nexport const GROK_VERTEX_CHAT_MODELS = [\n GROK_4_3.name,\n GROK_4_20_REASONING.name,\n GROK_4_20_NON_REASONING.name,\n GROK_4_1_FAST_REASONING.name,\n GROK_4_1_FAST_NON_REASONING.name,\n] as const\n\n/**\n * Grok Image Generation Models\n */\nexport const GROK_IMAGE_MODELS = [\n GROK_IMAGINE_IMAGE.name,\n GROK_IMAGINE_IMAGE_2_0.name,\n GROK_IMAGINE_IMAGE_QUALITY.name,\n] as const\n\n/**\n * Grok Video Generation Models (xAI Imagine API)\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport const GROK_VIDEO_MODELS = [\n GROK_IMAGINE_VIDEO.name,\n GROK_IMAGINE_VIDEO_1_5.name,\n] as const\n\n// xAI's `/v1/tts` endpoint is endpoint-addressed and does not take a `model`\n// parameter. This synthetic identifier satisfies the SDK's `TTSOptions.model`\n// contract and provides a stable value for logging and fixture matching.\nconst GROK_TTS = {\n name: 'grok-tts',\n supports: {\n input: ['text'],\n output: ['audio'],\n },\n} as const satisfies ModelMeta\n\n// xAI's `/v1/stt` endpoint is endpoint-addressed and does not take a `model`\n// parameter. This synthetic identifier satisfies the SDK's\n// `TranscriptionOptions.model` contract.\nconst GROK_STT = {\n name: 'grok-stt',\n supports: {\n input: ['audio'],\n output: ['text'],\n },\n} as const satisfies ModelMeta\n\nconst GROK_VOICE_FAST_1 = {\n name: 'grok-voice-fast-1.0',\n supports: {\n input: ['audio', 'text'],\n output: ['audio', 'text'],\n capabilities: ['tool_calling'],\n tools: [] as const,\n },\n} as const satisfies ModelMeta\n\n/** @deprecated xAI has deprecated grok-voice-think-fast-1.0 — use grok-voice-think-fast-2.0. */\nconst GROK_VOICE_THINK_FAST_1 = {\n name: 'grok-voice-think-fast-1.0',\n supports: {\n input: ['audio', 'text'],\n output: ['audio', 'text'],\n capabilities: ['reasoning', 'tool_calling'],\n tools: [] as const,\n },\n} as const satisfies ModelMeta\n\n// xAI's current recommended speech-to-speech model.\nconst GROK_VOICE_THINK_FAST_2 = {\n name: 'grok-voice-think-fast-2.0',\n supports: {\n input: ['audio', 'text'],\n output: ['audio', 'text'],\n capabilities: ['reasoning', 'tool_calling'],\n tools: [] as const,\n },\n} as const satisfies ModelMeta\n\n// Rolling alias used by xAI's realtime docs examples; always points at the\n// latest speech-to-speech model.\nconst GROK_VOICE_LATEST = {\n name: 'grok-voice-latest',\n supports: {\n input: ['audio', 'text'],\n output: ['audio', 'text'],\n capabilities: ['reasoning', 'tool_calling'],\n tools: [] as const,\n },\n} as const satisfies ModelMeta\n\nexport const GROK_TTS_MODELS = [GROK_TTS.name] as const\n\nexport const GROK_TRANSCRIPTION_MODELS = [GROK_STT.name] as const\n\nexport const GROK_REALTIME_MODELS = [\n GROK_VOICE_THINK_FAST_2.name,\n GROK_VOICE_LATEST.name,\n GROK_VOICE_FAST_1.name,\n GROK_VOICE_THINK_FAST_1.name,\n] as const\n\n/**\n * Default speech-to-speech model used by the realtime token issuer and the\n * realtime client adapter when no model is specified. Single source of truth\n * so a future default bump cannot leave the two sides disagreeing.\n */\nexport const GROK_DEFAULT_REALTIME_MODEL: GrokRealtimeModel =\n 'grok-voice-think-fast-2.0'\n\nexport type GrokChatModel = (typeof GROK_CHAT_MODELS)[number]\nexport type GrokVertexChatModel = (typeof GROK_VERTEX_CHAT_MODELS)[number]\nexport type GrokTextAdapterModel = GrokChatModel | GrokVertexChatModel\nexport type GrokImageModel = (typeof GROK_IMAGE_MODELS)[number]\nexport type GrokVideoModel = (typeof GROK_VIDEO_MODELS)[number]\nexport type GrokTTSModel = (typeof GROK_TTS_MODELS)[number]\nexport type GrokTranscriptionModel = (typeof GROK_TRANSCRIPTION_MODELS)[number]\nexport type GrokRealtimeModel = (typeof GROK_REALTIME_MODELS)[number]\n\n/**\n * Type-only map from Grok chat model name to its supported input modalities.\n * Used for type inference when constructing multimodal messages.\n */\nexport type GrokModelInputModalitiesByName = {\n [GROK_4_3.name]: typeof GROK_4_3.supports.input\n [GROK_BUILD_0_1.name]: typeof GROK_BUILD_0_1.supports.input\n [GROK_4_5.name]: typeof GROK_4_5.supports.input\n [GROK_4_6.name]: typeof GROK_4_6.supports.input\n [GROK_4_20_REASONING.name]: typeof GROK_4_20_REASONING.supports.input\n [GROK_4_20_NON_REASONING.name]: typeof GROK_4_20_NON_REASONING.supports.input\n [GROK_4_1_FAST_REASONING.name]: typeof GROK_4_1_FAST_REASONING.supports.input\n [GROK_4_1_FAST_NON_REASONING.name]: typeof GROK_4_1_FAST_NON_REASONING.supports.input\n [GROK_4_7.name]: typeof GROK_4_7.supports.input\n}\n\n/**\n * Type-only map from Grok chat model name to its supported provider tools.\n * Keeps Grok provider-tool factories type-checked against the models that\n * advertise xAI Responses server-side tools.\n */\nexport type GrokChatModelToolCapabilitiesByName = {\n [GROK_4_3.name]: typeof GROK_4_3.supports.tools\n [GROK_BUILD_0_1.name]: typeof GROK_BUILD_0_1.supports.tools\n [GROK_4_20_REASONING.name]: typeof GROK_4_20_REASONING.supports.tools\n [GROK_4_20_NON_REASONING.name]: typeof GROK_4_20_NON_REASONING.supports.tools\n [GROK_4_1_FAST_REASONING.name]: typeof GROK_4_1_FAST_REASONING.supports.tools\n [GROK_4_1_FAST_NON_REASONING.name]: typeof GROK_4_1_FAST_NON_REASONING.supports.tools\n [GROK_4_7.name]: typeof GROK_4_7.supports.tools\n}\n\nexport type GrokProviderOptions = GrokTextProviderOptions\n\n/**\n * Type-only map from Grok chat model name to its provider options type.\n */\nexport type GrokChatModelProviderOptionsByName = {\n [GROK_4_3.name]: GrokProviderOptions\n [GROK_BUILD_0_1.name]: GrokBuildProviderOptions\n [GROK_4_20_REASONING.name]: GrokProviderOptions\n [GROK_4_20_NON_REASONING.name]: GrokProviderOptions\n [GROK_4_1_FAST_REASONING.name]: GrokProviderOptions\n [GROK_4_1_FAST_NON_REASONING.name]: GrokProviderOptions\n}\n\n// ===========================\n// Type Resolution Helpers\n// ===========================\n\n/**\n * Resolve provider options for a specific model.\n * If the model has explicit options in the map, use those; otherwise use base options.\n */\nexport type ResolveProviderOptions<TModel extends string> =\n TModel extends keyof GrokChatModelProviderOptionsByName\n ? GrokChatModelProviderOptionsByName[TModel]\n : GrokProviderOptions\n\n/**\n * Resolve input modalities for a specific model.\n * If the model has explicit modalities in the map, use those; otherwise use text only.\n */\nexport type ResolveInputModalities<TModel extends string> =\n TModel extends keyof GrokModelInputModalitiesByName\n ? GrokModelInputModalitiesByName[TModel]\n : readonly ['text']\n"],"mappings":";AA+BA,IAAM,WAAW;CACf,MAAM;CACN,gBAAgB;CAChB,UAAU;EACR,OAAO;GAAC;GAAQ;GAAS;EAAU;EACnC,QAAQ,CAAC,MAAM;EACf,cAAc;GAAC;GAAa;GAAsB;EAAc;EAChE,OAAO,CAAC;CACV;CACA,SAAS;EACP,OAAO;GACL,QAAQ;GACR,QAAQ;EACV;EACA,QAAQ,EACN,QAAQ,EACV;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,CAAC,aAAa,cAAc;EAC1C,OAAO,CAAC;CACV;AACF;AAIA,IAAM,oBAAoB;CACxB,MAAM;CACN,UAAU;EACR,OAAO,CAAC,SAAS,MAAM;EACvB,QAAQ,CAAC,SAAS,MAAM;EACxB,cAAc,CAAC,aAAa,cAAc;EAC1C,OAAO,CAAC;CACV;AACF;AAEA,IAAa,kBAAkB,CAAC,SAAS,IAAI;AAE7C,IAAa,4BAA4B,CAAC,SAAS,IAAI;AAEvD,IAAa,uBAAuB;CAClC,wBAAwB;CACxB,kBAAkB;CAClB,kBAAkB;CAClB,wBAAwB;AAC1B;;;;;;AAOA,IAAa,8BACX"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/ai-grok",
3
- "version": "0.18.10",
3
+ "version": "0.19.1",
4
4
  "description": "xAI Grok adapter for TanStack AI chat, image generation, realtime, and structured outputs.",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -59,17 +59,17 @@
59
59
  "dependencies": {
60
60
  "openai": "^6.41.0",
61
61
  "@tanstack/ai-utils": "^0.4.1",
62
- "@tanstack/openai-base": "^0.10.15"
62
+ "@tanstack/openai-base": "^0.10.16"
63
63
  },
64
64
  "devDependencies": {
65
65
  "@vitest/coverage-v8": "4.1.10",
66
66
  "google-auth-library": "^10.5.0",
67
67
  "vite": "^8.2.1",
68
- "@tanstack/ai": "0.58.0"
68
+ "@tanstack/ai": "0.59.0"
69
69
  },
70
70
  "peerDependencies": {
71
71
  "google-auth-library": "^10.5.0",
72
- "@tanstack/ai": "^0.58.0"
72
+ "@tanstack/ai": "^0.59.0"
73
73
  },
74
74
  "peerDependenciesMeta": {
75
75
  "google-auth-library": {
@@ -26,7 +26,7 @@ import type {
26
26
  GrokImageModelInputModalitiesByName,
27
27
  GrokImageModelProviderOptionsByName,
28
28
  GrokImageModelSizeByName,
29
- GrokImageProviderOptions,
29
+ GrokImagineImageProviderOptions,
30
30
  } from '../image/image-provider-options'
31
31
  import type { GrokClientConfig } from '../utils/client'
32
32
 
@@ -79,9 +79,7 @@ interface GrokImageEditResponse {
79
79
  * Grok Image Generation Adapter
80
80
  *
81
81
  * Tree-shakeable adapter for Grok image generation functionality.
82
- * Supports the legacy grok-2-image-1212 model (text-to-image via the
83
- * OpenAI-compat endpoint) and the grok-imagine image models, which also
84
- * accept image prompt parts for image-conditioned generation via xAI's
82
+ * Supports the grok-imagine image models. Image prompt parts use xAI's
85
83
  * `/v1/images/edits` endpoint (up to 3 source images).
86
84
  *
87
85
  * Features:
@@ -93,7 +91,7 @@ export class GrokImageAdapter<
93
91
  TModel extends GrokImageModel,
94
92
  > extends BaseImageAdapter<
95
93
  TModel,
96
- GrokImageProviderOptions,
94
+ GrokImagineImageProviderOptions,
97
95
  GrokImageModelProviderOptionsByName,
98
96
  GrokImageModelSizeByName,
99
97
  GrokImageModelInputModalitiesByName
@@ -111,10 +109,17 @@ export class GrokImageAdapter<
111
109
  }
112
110
 
113
111
  async generateImages(
114
- options: ImageGenerationOptions<GrokImageProviderOptions>,
112
+ options: ImageGenerationOptions<GrokImagineImageProviderOptions>,
115
113
  ): Promise<ImageGenerationResult> {
116
114
  const { model, numberOfImages, size, modelOptions } = options
117
115
 
116
+ if (!isGrokImagineImageModel(model)) {
117
+ throw new Error(
118
+ `Unknown image model: ${model}. Supported models: ` +
119
+ `grok-imagine-image, grok-imagine-image-2.0, grok-imagine-image-quality.`,
120
+ )
121
+ }
122
+
118
123
  const resolved = resolveMediaPrompt(options.prompt)
119
124
  const prompt = resolved.text
120
125
 
@@ -125,35 +130,21 @@ export class GrokImageAdapter<
125
130
  }
126
131
 
127
132
  if (resolved.images.length > 0) {
128
- if (!isGrokImagineImageModel(model)) {
129
- throw new Error(
130
- `grok: model "${model}" does not support image prompt parts. ` +
131
- `Image-conditioned generation requires an Imagine API model ` +
132
- `('grok-imagine-image', 'grok-imagine-image-2.0' or ` +
133
- `'grok-imagine-image-quality').`,
134
- )
135
- }
136
133
  return await this.editImages(options, resolved)
137
134
  }
138
135
 
139
- validatePrompt({ prompt, model })
136
+ validatePrompt(prompt)
140
137
  validateImageSize(model, size)
141
138
  validateNumberOfImages(model, numberOfImages)
142
139
 
143
- // grok-imagine models are aspect-ratio sized: the generic `size` option
144
- // carries an "aspectRatio_resolution" template (e.g. '16:9_2k', like
145
- // Gemini native image models) and maps to the Imagine API's
146
- // `aspect_ratio` / `resolution` parameters instead of OpenAI-style `size`.
147
- const isImagine = isGrokImagineImageModel(model)
140
+ // The generic `size` option carries an "aspectRatio_resolution" template
141
+ // (e.g. '16:9_2k', like Gemini native image models) and maps to the
142
+ // Imagine API's `aspect_ratio` / `resolution` parameters.
148
143
  const request = {
149
144
  model,
150
145
  prompt,
151
146
  n: numberOfImages ?? 1,
152
- ...(isImagine
153
- ? imagineSizeParams(size)
154
- : size !== undefined && {
155
- size: size,
156
- }),
147
+ ...imagineSizeParams(size),
157
148
  stream: false,
158
149
  ...modelOptions,
159
150
  } as OpenAI_SDK.Images.ImageGenerateParamsNonStreaming
@@ -216,7 +207,7 @@ export class GrokImageAdapter<
216
207
  * verbatim — no referencing markers are injected.
217
208
  */
218
209
  private async editImages(
219
- options: ImageGenerationOptions<GrokImageProviderOptions>,
210
+ options: ImageGenerationOptions<GrokImagineImageProviderOptions>,
220
211
  resolved: ResolvedMediaPrompt,
221
212
  ): Promise<ImageGenerationResult> {
222
213
  const { model, numberOfImages, size, modelOptions, logger } = options
@@ -239,7 +230,7 @@ export class GrokImageAdapter<
239
230
  )
240
231
  }
241
232
 
242
- validatePrompt({ prompt, model })
233
+ validatePrompt(prompt)
243
234
  validateImageSize(model, size)
244
235
  validateNumberOfImages(model, numberOfImages)
245
236
 
@@ -310,14 +301,14 @@ export class GrokImageAdapter<
310
301
  * Creates a Grok image adapter with explicit API key.
311
302
  * Type resolution happens here at the call site.
312
303
  *
313
- * @param model - The model name (e.g., 'grok-2-image-1212')
304
+ * @param model - The model name (e.g., 'grok-imagine-image-2.0')
314
305
  * @param apiKey - Your xAI API key
315
306
  * @param config - Optional additional configuration
316
307
  * @returns Configured Grok image adapter instance with resolved types
317
308
  *
318
309
  * @example
319
310
  * ```typescript
320
- * const adapter = createGrokImage('grok-2-image-1212', "xai-...");
311
+ * const adapter = createGrokImage('grok-imagine-image-2.0', "xai-...");
321
312
  *
322
313
  * const result = await generateImage({
323
314
  * adapter,
@@ -341,7 +332,7 @@ export function createGrokImage<TModel extends GrokImageModel>(
341
332
  * - `process.env` (Node.js)
342
333
  * - `window.env` (Browser with injected env)
343
334
  *
344
- * @param model - The model name (e.g., 'grok-2-image-1212')
335
+ * @param model - The model name (e.g., 'grok-imagine-image-2.0')
345
336
  * @param config - Optional configuration (excluding apiKey which is auto-detected)
346
337
  * @returns Configured Grok image adapter instance with resolved types
347
338
  * @throws Error if XAI_API_KEY is not found in environment
@@ -349,7 +340,7 @@ export function createGrokImage<TModel extends GrokImageModel>(
349
340
  * @example
350
341
  * ```typescript
351
342
  * // Automatically uses XAI_API_KEY from environment
352
- * const adapter = grokImage('grok-2-image-1212');
343
+ * const adapter = grokImage('grok-imagine-image-2.0');
353
344
  *
354
345
  * const result = await generateImage({
355
346
  * adapter,
@@ -3,14 +3,9 @@
3
3
  *
4
4
  * Provider-specific options for Grok image generation: the aspect-ratio
5
5
  * sized Imagine API models (grok-imagine-image, grok-imagine-image-2.0,
6
- * grok-imagine-image-quality) and the legacy pixel-sized grok-2-image-1212.
6
+ * grok-imagine-image-quality).
7
7
  */
8
8
 
9
- /**
10
- * Supported sizes for grok-2-image-1212 model
11
- */
12
- export type GrokImageSize = '1024x1024' | '1536x1024' | '1024x1536'
13
-
14
9
  /**
15
10
  * Aspect ratios accepted by the grok-imagine image models.
16
11
  */
@@ -67,8 +62,7 @@ const GROK_IMAGINE_RESOLUTIONS: ReadonlyArray<string> = ['1k', '2k']
67
62
 
68
63
  /**
69
64
  * Models served by xAI's Imagine API. They are aspect-ratio sized and
70
- * support image-conditioned generation via `/v1/images/edits`; the legacy
71
- * grok-2-image-1212 model is pixel-sized and text-to-image only.
65
+ * support image-conditioned generation via `/v1/images/edits`.
72
66
  */
73
67
  export function isGrokImagineImageModel(model: string): boolean {
74
68
  return model.startsWith('grok-imagine-image')
@@ -100,24 +94,6 @@ export interface GrokImageBaseProviderOptions {
100
94
  user?: string
101
95
  }
102
96
 
103
- /**
104
- * Provider options for grok-2-image-1212 model
105
- */
106
- export interface GrokImageProviderOptions extends GrokImageBaseProviderOptions {
107
- /**
108
- * The quality of the image.
109
- * @default 'standard'
110
- */
111
- quality?: 'standard' | 'hd'
112
-
113
- /**
114
- * The format in which generated images are returned.
115
- * URLs are only valid for 60 minutes after generation.
116
- * @default 'url'
117
- */
118
- response_format?: 'url' | 'b64_json'
119
- }
120
-
121
97
  /**
122
98
  * Provider options for the grok-imagine image models (generation and
123
99
  * image-conditioned editing via xAI's Imagine API).
@@ -158,7 +134,6 @@ export interface GrokImagineImage2ProviderOptions extends GrokImagineImageProvid
158
134
  * Type-only map from model name to its specific provider options.
159
135
  */
160
136
  export type GrokImageModelProviderOptionsByName = {
161
- 'grok-2-image-1212': GrokImageProviderOptions
162
137
  'grok-imagine-image': GrokImagineImageProviderOptions
163
138
  'grok-imagine-image-2.0': GrokImagineImage2ProviderOptions
164
139
  'grok-imagine-image-quality': GrokImagineImageProviderOptions
@@ -168,7 +143,6 @@ export type GrokImageModelProviderOptionsByName = {
168
143
  * Type-only map from model name to its supported sizes.
169
144
  */
170
145
  export type GrokImageModelSizeByName = {
171
- 'grok-2-image-1212': GrokImageSize
172
146
  'grok-imagine-image': GrokImagineImageSize
173
147
  'grok-imagine-image-2.0': GrokImagineImageSize
174
148
  'grok-imagine-image-quality': GrokImagineImageSize
@@ -177,23 +151,14 @@ export type GrokImageModelSizeByName = {
177
151
  /**
178
152
  * Per-model prompt input modalities. Imagine API models accept image parts
179
153
  * in the prompt (routed to `/v1/images/edits`, up to 3 images, addressed by
180
- * xAI in request order); grok-2-image is text-to-image only.
154
+ * xAI in request order).
181
155
  */
182
156
  export type GrokImageModelInputModalitiesByName = {
183
- 'grok-2-image-1212': readonly []
184
157
  'grok-imagine-image': readonly ['image']
185
158
  'grok-imagine-image-2.0': readonly ['image']
186
159
  'grok-imagine-image-quality': readonly ['image']
187
160
  }
188
161
 
189
- /**
190
- * Internal options interface for validation
191
- */
192
- interface ImageValidationOptions {
193
- prompt: string
194
- model: string
195
- }
196
-
197
162
  /**
198
163
  * Validates that the provided size is supported by the model.
199
164
  * Throws a descriptive error if the size is not supported.
@@ -221,21 +186,7 @@ export function validateImageSize(
221
186
  return
222
187
  }
223
188
 
224
- const validSizes: Record<string, Array<string>> = {
225
- 'grok-2-image-1212': ['1024x1024', '1536x1024', '1024x1536'],
226
- }
227
-
228
- const modelSizes = validSizes[model]
229
- if (!modelSizes) {
230
- throw new Error(`Unknown image model: ${model}`)
231
- }
232
-
233
- if (!modelSizes.includes(size)) {
234
- throw new Error(
235
- `Size "${size}" is not supported by model "${model}". ` +
236
- `Supported sizes: ${modelSizes.join(', ')}`,
237
- )
238
- }
189
+ throw new Error(`Unknown image model: ${model}`)
239
190
  }
240
191
 
241
192
  /**
@@ -247,7 +198,7 @@ export function validateNumberOfImages(
247
198
  ): void {
248
199
  if (numberOfImages === undefined) return
249
200
 
250
- // grok-2-image-1212 supports 1-10 images per request
201
+ // Imagine image models accept 1-10 images per request.
251
202
  if (numberOfImages < 1 || numberOfImages > 10) {
252
203
  throw new Error(
253
204
  `Number of images must be between 1 and 10. Requested: ${numberOfImages}`,
@@ -255,14 +206,8 @@ export function validateNumberOfImages(
255
206
  }
256
207
  }
257
208
 
258
- export const validatePrompt = (options: ImageValidationOptions) => {
259
- if (options.prompt.length === 0) {
209
+ export const validatePrompt = (prompt: string) => {
210
+ if (prompt.length === 0) {
260
211
  throw new Error('Prompt cannot be empty.')
261
212
  }
262
- // Grok image model supports up to 4000 characters
263
- if (options.prompt.length > 4000) {
264
- throw new Error(
265
- 'For grok-2-image-1212, prompt length must be less than or equal to 4000 characters.',
266
- )
267
- }
268
213
  }
package/src/index.ts CHANGED
@@ -27,7 +27,6 @@ export {
27
27
  type GrokImageConfig,
28
28
  } from './adapters/image'
29
29
  export type {
30
- GrokImageProviderOptions,
31
30
  GrokImagineImageProviderOptions,
32
31
  GrokImagineImage2ProviderOptions,
33
32
  GrokImageModelProviderOptionsByName,
package/src/model-meta.ts CHANGED
@@ -69,6 +69,27 @@ const GROK_4_6 = {
69
69
  },
70
70
  } as const satisfies ModelMeta
71
71
 
72
+ const GROK_4_7 = {
73
+ name: 'grok-4.7',
74
+ context_window: 500_000,
75
+ max_output_tokens: 450_000,
76
+ supports: {
77
+ input: ['text', 'image', 'document'],
78
+ output: ['text'],
79
+ capabilities: ['reasoning', 'structured_outputs', 'tool_calling'],
80
+ tools: [],
81
+ },
82
+ pricing: {
83
+ input: {
84
+ normal: 1.6,
85
+ cached: 0.4,
86
+ },
87
+ output: {
88
+ normal: 4.8,
89
+ },
90
+ },
91
+ } as const satisfies ModelMeta
92
+
72
93
  export type GrokProviderToolKind =
73
94
  | 'web_search'
74
95
  | 'x_search'
@@ -82,22 +103,6 @@ const GROK_RESPONSES_TOOLS = [
82
103
  'mcp',
83
104
  ] as const satisfies ReadonlyArray<GrokProviderToolKind>
84
105
 
85
- const GROK_2_IMAGE = {
86
- name: 'grok-2-image-1212',
87
- supports: {
88
- input: ['text'],
89
- output: ['image'],
90
- },
91
- pricing: {
92
- input: {
93
- normal: 0.07,
94
- },
95
- output: {
96
- normal: 0.07,
97
- },
98
- },
99
- } as const satisfies ModelMeta
100
-
101
106
  // Imagine API image models. Pricing is per generated image (output only).
102
107
  const GROK_IMAGINE_IMAGE = {
103
108
  name: 'grok-imagine-image',
@@ -283,6 +288,7 @@ const GROK_4_1_FAST_NON_REASONING = {
283
288
  * Grok chat models supported by the xAI Responses adapter.
284
289
  */
285
290
  export const GROK_CHAT_MODELS = [
291
+ GROK_4_7.name,
286
292
  GROK_4_5.name,
287
293
  GROK_4_6.name,
288
294
  GROK_BUILD_0_1.name,
@@ -305,7 +311,6 @@ export const GROK_VERTEX_CHAT_MODELS = [
305
311
  * Grok Image Generation Models
306
312
  */
307
313
  export const GROK_IMAGE_MODELS = [
308
- GROK_2_IMAGE.name,
309
314
  GROK_IMAGINE_IMAGE.name,
310
315
  GROK_IMAGINE_IMAGE_2_0.name,
311
316
  GROK_IMAGINE_IMAGE_QUALITY.name,
@@ -428,6 +433,7 @@ export type GrokModelInputModalitiesByName = {
428
433
  [GROK_4_20_NON_REASONING.name]: typeof GROK_4_20_NON_REASONING.supports.input
429
434
  [GROK_4_1_FAST_REASONING.name]: typeof GROK_4_1_FAST_REASONING.supports.input
430
435
  [GROK_4_1_FAST_NON_REASONING.name]: typeof GROK_4_1_FAST_NON_REASONING.supports.input
436
+ [GROK_4_7.name]: typeof GROK_4_7.supports.input
431
437
  }
432
438
 
433
439
  /**
@@ -442,6 +448,7 @@ export type GrokChatModelToolCapabilitiesByName = {
442
448
  [GROK_4_20_NON_REASONING.name]: typeof GROK_4_20_NON_REASONING.supports.tools
443
449
  [GROK_4_1_FAST_REASONING.name]: typeof GROK_4_1_FAST_REASONING.supports.tools
444
450
  [GROK_4_1_FAST_NON_REASONING.name]: typeof GROK_4_1_FAST_NON_REASONING.supports.tools
451
+ [GROK_4_7.name]: typeof GROK_4_7.supports.tools
445
452
  }
446
453
 
447
454
  export type GrokProviderOptions = GrokTextProviderOptions