Repository navigation
fix(ai-grok): accept 21:9, 5:2, 1.5k and quality auto on grok-imagine-image-2.0 - #2287
Conversation
…-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 detectedLatest commit: 102a96f The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
View your CI Pipeline Execution ↗ for commit 102a96f
💡 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 |
generateImage()withgrok-imagine-image-2.0throws on the sizes21:9,5:2and every_1.5ksize before it sends a request. The types also rejectquality: 'auto'. The xAI API accepts all four on this model. This PR adds them forgrok-imagine-image-2.0only.🎯 Changes
grok-imagine-image-2.0gets its own aspect-ratio, resolution and size lists and types: the shared ones plus21:9,5:2and1.5k.qualityis'low' | 'medium' | 'auto'. The documented default is'auto'.grok-imagine-imageandgrok-imagine-image-qualitytake the same sizes as before.docs/adapters/grok.md), unit tests, an E2E route and spec, and a patch changeset are included.Sources in the xAI docs:
21:9,5:2, andqualitywithautoas the default.resolutiontakes1k,2kand1.5k.grok-imagine-image-2.0: prices for1.5K. The page ofgrok-imagine-imagelists1Kand2Konly.✅ Checklist
pnpm run test:pr, or these tests do not apply to this pull request.docs/for this change, or this change is not user-facing.pnpm changeset), or this PR does not change a published package.🚀 Release Impact
Root cause
Issue. A caller of
generateImage()ongrok-imagine-image-2.0gets a local error forsize: '21:9','5:2'or any_1.5ksize. TypeScript also rejectsquality: 'auto'andresolution: '1.5k'inmodelOptions.Cause.
validateImageSize()inpackages/ai-grok/src/image/image-provider-options.tschecks every Imagine image model against one shared list. That list has no21:9,5:2or1.5k.GrokImagineImage2ProviderOptionstypesqualityas'low' | 'medium'.Fix.
grok-imagine-image-2.0has its own lists and types with the new values.validateImageSize()uses them for that model only.Possible alternatives
grok-imagine-image-2.0forquality,21:9and5:2(migration guide), and they list1.5Kprices for that model only. So this PR does not do that.Testing
Commands run. Unit tests and
tscfor@tanstack/ai-grok, on the 1.1.1 source with@tanstack/ai1.8.0.packages/ai-grok/srconmainis identical to that source.tscreports 3 errors.tscreports no error.oxfmt --checkpasses on the changed files.oxlintreports nothing new onpackages/ai-grok/src.pnpm run test:pras a whole, and the new Playwright spec on this base.Manual test.
@tanstack/ai-grok1.1.1 as published, make the two calls below. Each call throws, and no request reaches the API.How this PR makes testing easy.
packages/ai-grok/tests/grok-adapter.test.ts: the four new sizes,quality: 'auto'withresolution: '1.5k', the same rejection as before on the two other image models, and the types.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
GrokImagineImage2ProviderOptionsand thesizetype ofgrok-imagine-image-2.0accept more values. No value is removed.Before
After
Summary by CodeRabbit
21:9and5:2aspect ratios,1.5kresolution, and automatic quality selection.