Skip to content

fix(ai-grok): accept 21:9, 5:2, 1.5k and quality auto on grok-imagine-image-2.0 - #2287

Merged
AlemTuzlak merged 1 commit into
TanStack:mainfrom
Jaaneek:feat/grok-image-2-options
Nov 30, 2026
Merged

AlemTuzlak merged 1 commit into
TanStack:mainfrom
Jaaneek:feat/grok-image-2-options

Conversation

@Jaaneek

@Jaaneek Jaaneek commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

generateImage() with grok-imagine-image-2.0 throws on the sizes 21:9, 5:2 and every _1.5k size before it sends a request. The types also reject quality: 'auto'. The xAI API accepts all four on this model. This PR adds them for grok-imagine-image-2.0 only.

🎯 Changes

  • grok-imagine-image-2.0 gets its own aspect-ratio, resolution and size lists and types: the shared ones plus 21:9, 5:2 and 1.5k.
  • quality is 'low' | 'medium' | 'auto'. The documented default is 'auto'.
  • grok-imagine-image and grok-imagine-image-quality take the same sizes as before.
  • Docs (docs/adapters/grok.md), unit tests, an E2E route and spec, and a patch changeset are included.

Sources in the xAI docs:

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with pnpm run test:pr, or these tests do not apply to this pull request.
  • I fully understand the code in this pull request, including any code generated with AI assistance.
  • Docs: I updated docs/ for this change, or this change is not user-facing.
  • Changeset: I added a changeset (pnpm changeset), or this PR does not change a published package.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Root cause

Issue. A caller of generateImage() on grok-imagine-image-2.0 gets a local error for size: '21:9', '5:2' or any _1.5k size. TypeScript also rejects quality: 'auto' and resolution: '1.5k' in modelOptions.

Cause. validateImageSize() in packages/ai-grok/src/image/image-provider-options.ts checks every Imagine image model against one shared list. That list has no 21:9, 5:2 or 1.5k. GrokImagineImage2ProviderOptions types quality as 'low' | 'medium'.

Fix. grok-imagine-image-2.0 has its own lists and types with the new values. validateImageSize() uses them for that model only.

Possible alternatives

  • Add the values to the shared lists. Then the two other image models accept them too. The xAI docs name grok-imagine-image-2.0 for quality, 21:9 and 5:2 (migration guide), and they list 1.5K prices for that model only. So this PR does not do that.
  • Remove the local size check. Then the API reports a wrong size. The adapter checks the size before the request for every image model today, and this PR keeps that.

Testing

Commands run. Unit tests and tsc for @tanstack/ai-grok, on the 1.1.1 source with @tanstack/ai 1.8.0. packages/ai-grok/src on main is identical to that source.

  • With only the new tests added: 4 of 192 tests fail, and tsc reports 3 errors.
  • With this change: 192 tests pass, and tsc reports no error.
  • oxfmt --check passes on the changed files. oxlint reports nothing new on packages/ai-grok/src.
  • Not run: pnpm run test:pr as a whole, and the new Playwright spec on this base.

Manual test.

  1. On @tanstack/ai-grok 1.1.1 as published, make the two calls below. Each call throws, and no request reaches the API.
generateImage({ adapter: createGrokImage('grok-imagine-image-2.0', apiKey), prompt, size: '21:9_1.5k', modelOptions: { quality: 'auto' } })
  Error: Size "21:9_1.5k" is not supported by model "grok-imagine-image-2.0". Expected an aspect ratio (...)
generateImage({ adapter: createGrokImage('grok-imagine-image-2.0', apiKey), prompt, size: '5:2' })
  Error: Size "5:2" is not supported by model "grok-imagine-image-2.0". Expected an aspect ratio (...)

requests that reached api.x.ai: 0
  1. Apply this change to the same release and make the same calls against the xAI API. Each call returns one image.
generateImage({ adapter: createGrokImage('grok-imagine-image-2.0', apiKey), prompt, size: '21:9_1.5k', modelOptions: { quality: 'auto' } })
  POST /v1/images/generations  aspect_ratio 21:9, resolution 1.5k, quality auto  ->  HTTP 200, 1 image
generateImage({ adapter: createGrokImage('grok-imagine-image-2.0', apiKey), prompt, size: '5:2' })
  POST /v1/images/generations  aspect_ratio 5:2  ->  HTTP 200, 1 image

requests that reached api.x.ai: 2, images returned: 2

How this PR makes testing easy.

  • New unit tests in packages/ai-grok/tests/grok-adapter.test.ts: the four new sizes, quality: 'auto' with resolution: '1.5k', the same rejection as before on the two other image models, and the types.
  • New E2E spec against aimock: pnpm --filter @tanstack/ai-e2e exec playwright test tests/grok-image-2-options.spec.ts.

Risk / rollback

Low. A matrix of 3,032 SDK calls ran before and after the change against a local recording mock. It has every chat, image and video model with every size, option and tool list, plus speech, transcription and files. All 1,488 requests that were sent before are byte-identical. The 304 calls that changed are all on grok-imagine-image-2.0: 157 with a new value are now sent, and 147 are still rejected, with the new values in the error message. To undo, revert this PR.

Public API change

GrokImagineImage2ProviderOptions and the size type of grok-imagine-image-2.0 accept more values. No value is removed.

Before

await generateImage({
  adapter: grokImage('grok-imagine-image-2.0'),
  prompt: 'A futuristic cityscape at sunset',
  threadId: 'thread-1',
  size: '16:9_2k',
  modelOptions: { quality: 'medium' },
})

After

await generateImage({
  adapter: grokImage('grok-imagine-image-2.0'),
  prompt: 'A futuristic cityscape at sunset',
  threadId: 'thread-1',
  size: '21:9_1.5k', // also '21:9', '5:2', and every other ratio with '_1.5k'
  modelOptions: { quality: 'auto' },
})

Summary by CodeRabbit

  • New Features
    • Grok Imagine Image 2.0 now supports the 21:9 and 5:2 aspect ratios, 1.5k resolution, and automatic quality selection.
    • Existing Grok Imagine models retain their previous supported image sizes.
  • Documentation
    • Updated the Grok image-generation documentation to include automatic quality selection as the default.

…-image-2.0

generateImage() rejected the sizes 21:9, 5:2 and the 1.5k resolution on
grok-imagine-image-2.0 before it sent a request, and the types rejected
quality 'auto'. The xAI docs list all four, and 'auto' is the default
quality.

The new values are typed and validated for grok-imagine-image-2.0 only.
grok-imagine-image and grok-imagine-image-quality take the same sizes as
before.
@changeset-bot

changeset-bot Bot commented Nov 30, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 102a96f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@tanstack/ai-grok Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@AlemTuzlak
AlemTuzlak enabled auto-merge (squash) November 30, 2026 17:26
@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Grok Image 2.0 adds support for aspect ratios 21:9 and 5:2, resolution 1.5k, and quality auto. Validation, adapter tests, and an end-to-end route cover these options. The documentation and changeset describe the updated options and default quality.

Changes: Grok Image 2.0 options

Layer / File(s) Summary
Image 2.0 options and validation
packages/ai-grok/src/image/image-provider-options.ts, .changeset/grok-image-2-options.md, docs/adapters/grok.md, docs/config.json
Image 2.0 now has separate aspect-ratio, resolution, and size types. Validation selects the expanded values only for grok-imagine-image-2.0. The documentation and changeset list the added options and auto as the default quality.
Adapter option coverage
packages/ai-grok/tests/grok-adapter.test.ts
Tests cover Image 2.0 size and option forwarding, rejection of the new sizes by older Imagine models, and model-specific type checks.
End-to-end option coverage
testing/e2e/src/routes/api.grok-image-2-options.ts, testing/e2e/src/routeTree.gen.ts, testing/e2e/tests/grok-image-2-options.spec.ts
A POST route requests images for three sizes and records each result or error. The route tree registers the endpoint, and Playwright tests check each size’s response.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Playwright
  participant GrokImage2OptionsRoute
  participant GrokImage2Adapter
  participant MockImageAPI
  Playwright->>GrokImage2OptionsRoute: POST image-size request
  GrokImage2OptionsRoute->>GrokImage2Adapter: Generate image with size and auto quality
  GrokImage2Adapter->>MockImageAPI: Send image request
  MockImageAPI-->>GrokImage2Adapter: Return image result
  GrokImage2Adapter-->>GrokImage2OptionsRoute: Return generated image
  GrokImage2OptionsRoute-->>Playwright: Return image count or error
Loading

Suggested reviewers: tombeckenham, alemtuzlak

Merge Risk: Minimal · up to 102a9

This change lets grok-imagine-image-2.0 accept the 21:9 and 5:2 aspect ratios, the 1.5k resolution and quality: 'auto'. The older Imagine models keep their existing accepted sizes. No concrete defect was found in the change, and unit and end-to-end tests cover the new options. The remaining risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the package, the models, and the four new values (21:9, 5:2, 1.5k, quality auto), which matches the changeset. It is specific and accurate. The title uses the 'fix' prefix even though …
Description check Passed The description covers the problem, the fix, the changed files, the testing done, the risk and rollback plan, and the public API change. It follows the template's Changes and Checklist sections, and i…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the package, the models, and the four new values (21:9, 5:2, 1.5k, quality auto), which matches the changeset. It is specific and accurate. The title uses the 'fix' prefix even though the change adds new values; the core subject is still the main change.

Full details: Description check

Explanation

The description covers the problem, the fix, the changed files, the testing done, the risk and rollback plan, and the public API change. It follows the template's Changes and Checklist sections, and it adds Release Impact. Two checklist items are unchecked: the author did not run 'pnpm run test:pr' as a whole, and the 'I fully understand the code' item is open. The template asks for tests or a reason they do not apply, and the author gives a partial reason. The description is mostly complete.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: TanStack/ai
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: f302e8b
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2e5221c0-c4e0-4b88-a9b0-108824b787fc
Commits

Reviewing files that changed from the base of the PR and between f302e8b and 102a96f.

Files selected for processing: 8

  • .changeset/grok-image-2-options.md
  • docs/adapters/grok.md
  • docs/config.json
  • packages/ai-grok/src/image/image-provider-options.ts
  • packages/ai-grok/tests/grok-adapter.test.ts
  • testing/e2e/src/routeTree.gen.ts
  • testing/e2e/src/routes/api.grok-image-2-options.ts
  • testing/e2e/tests/grok-image-2-options.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@nx-cloud

nx-cloud Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 102a96f

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 1m 47s View ↗
nx run-many --targets=test:coverage --projects=... ✅ Succeeded <1s View ↗
nx run-many --targets=build --exclude=examples/... ✅ Succeeded 16s View ↗

💡 With Ultracache enabled, Nx Cloud learns each task's file inputs in CI and uses them on later runs. Turn on Ultracache in workspace settings ↗ · Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-11-30 17:35:45 UTC

@AlemTuzlak
AlemTuzlak merged commit 2d49b19 into TanStack:main Nov 30, 2026
13 of 14 checks passed
@github-actions github-actions Bot mentioned this pull request Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants