feat(xai): add Grok Imagine for image and video generation#128
feat(xai): add Grok Imagine for image and video generation#128Kamilbenkirane merged 3 commits intomainfrom
Conversation
Add xAI Grok Imagine support for image and video generation: Images (grok-imagine-image): - Generate and edit operations - Parameters: aspect_ratio, num_images, output_format - Aspect ratios: 1:1, 3:4, 4:3, 9:16, 16:9, 2:3, 3:2, and more Videos (grok-imagine-video): - Generate and edit operations - Async polling pattern (HTTP 200=ready, 202=processing) - Parameters: duration (1-15s), aspect_ratio, resolution Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Pull Request Review: xAI Grok Imagine IntegrationOverviewThis PR adds xAI's Grok Imagine models for image and video generation/editing. The implementation follows established patterns in the codebase and demonstrates solid understanding of the architecture. ✅ Strengths1. Excellent Architectural Consistency
2. Async Polling ImplementationThe video polling implementation is well-designed with proper handling of immediate responses, async polling flow, configurable timeout, and clean error handling. 3. Good Error Handling
4. Clean Code Quality
🔍 Issues & RecommendationsCRITICAL: Potential Bug in Video Edit OperationLocation: src/celeste/modalities/videos/providers/xai/client.py:28 Issue: This assumes VideoArtifact always has a url attribute, but artifacts can also have data (bytes) or path (local file). This will fail with AttributeError for non-URL artifacts. Recommendation: Add proper handling for non-URL artifacts or raise a clear error message. MEDIUM: Image Edit Missing Proper SerializationLocation: src/celeste/modalities/images/providers/xai/client.py:32 Issue: Passing the ImageArtifact object directly to the request. Verify this matches xAI API specification. MEDIUM: Missing Video Edit TestsIssue: No automated integration test for video editing. Images has test_edit.py, but videos doesn't. LOW: Polling Configuration Could Be More RobustLocation: src/celeste/providers/xai/videos/config.py:16-17 5-minute timeout might be insufficient for longer videos. Consider increasing default timeout to 10-15 minutes. LOW: Missing Type ValidationAdd type validation in _parse_content methods to prevent silent failures. 🔒 Security: No Issues Found
⚡ PerformanceThe polling implementation could benefit from exponential backoff to reduce API calls. 📋 Test Coverage
🎯 Action ItemsBefore Merge (MUST FIX)
Recommended (SHOULD FIX)
Optional (NICE TO HAVE)
🎉 ConclusionThis is a solid implementation that follows best practices and integrates cleanly with the existing codebase. The main concerns are around edge case handling for different artifact types in edit operations and missing test coverage for video editing. Recommendation: Approve with changes requested ✅ (after fixing the critical issues) Great work on maintaining consistency with the codebase patterns! 🚀 |
- Image edit: serialize ImageArtifact to URL or base64 string instead of passing object directly (xAI API expects string) - Video edit: validate video has URL before using, raise clear error if not (xAI only supports URL, not base64/path) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Let the xAI API handle validation for video edit requests. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
PR Review: xAI Grok Imagine IntegrationSummaryThis PR adds comprehensive support for xAI's Grok Imagine models for image and video generation. The implementation follows the existing codebase patterns well and integrates cleanly with the Celeste architecture. ✅ StrengthsArchitecture & Design
Code Quality
🔍 Issues & Recommendations🐛 Critical: Video Polling Logic BugLocation: # Parse response for error handling
video_obj = status_response.json()
status = video_obj.get("status", "")
if status == config.STATUS_FAILED:
error = video_obj.get("error", "Video generation failed")
raise RuntimeError(error)Issue: This code is unreachable because:
Recommendation: Either remove the unreachable code or restructure the logic: # Option 1: Remove unreachable code
if status_response.status_code == 200:
return status_response.json()
if status_response.status_code == 202:
continue
# _handle_error_response will handle any other status codes
self._handle_error_response(status_response)
|
Summary
Add xAI's Grok Imagine models for image and video generation:
grok-imagine-image- AI image generation and editinggrok-imagine-video- AI video generation and editingFeatures
Images (
grok-imagine-image)generatePOST /v1/images/generationseditPOST /v1/images/editsSupported Parameters:
aspect_ratio1:1,3:4,4:3,9:16,16:9,2:3,3:2,9:19.5,19.5:9,9:20,20:9,1:2,2:1,autonum_imagesoutput_formaturl,b64_jsonVideos (
grok-imagine-video)generatePOST /v1/videos/generationseditPOST /v1/videos/editsAsync Polling Pattern:
request_idGET /v1/videos/{request_id}until completionSupported Parameters:
durationaspect_ratio16:9,4:3,1:1,9:16,3:4,3:2,2:3resolution720p,480pUsage
```python
import celeste
Image generation
image = await celeste.images.generate(
prompt="A cat in a tree",
model="grok-imagine-image",
aspect_ratio="16:9",
num_images=1,
)
print(image.content.url)
Image editing
edited = await celeste.images.edit(
image=image.content,
prompt="Add a bird in the tree",
model="grok-imagine-image",
)
Video generation
video = await celeste.videos.generate(
prompt="A ball bouncing",
model="grok-imagine-video",
duration=5,
aspect_ratio="16:9",
)
print(video.content.url)
Video editing
edited = await celeste.videos.edit(
video=video.content,
prompt="Change the ball color to blue",
model="grok-imagine-video",
)
```
Files Changed
Provider-level (HTTP/API handling)
Modality-level (Celeste interface)
Tests
Test plan
🤖 Generated with Claude Code