diff --git a/sdk/api/handlers/openai/openai_images_handlers.go b/sdk/api/handlers/openai/openai_images_handlers.go index f73d8a9848..ae350d2cae 100644 --- a/sdk/api/handlers/openai/openai_images_handlers.go +++ b/sdk/api/handlers/openai/openai_images_handlers.go @@ -301,6 +301,8 @@ func xaiImagesAspectRatio(raw string, fallback string) string { return "9:16" case "9:20": return "9:20" + case "20:9": + return "20:9" case "4:3": return "4:3" case "3:4": @@ -325,6 +327,8 @@ func xaiImagesAspectRatioFromSize(size string, fallback string) string { return "9:16" case "9:20": return "9:20" + case "20:9": + return "20:9" case "1536x1024", "3:2": return "3:2" case "1024x1536", "2:3": diff --git a/sdk/api/handlers/openai/openai_images_handlers_test.go b/sdk/api/handlers/openai/openai_images_handlers_test.go index 51a8d3e454..8ec4298d34 100644 --- a/sdk/api/handlers/openai/openai_images_handlers_test.go +++ b/sdk/api/handlers/openai/openai_images_handlers_test.go @@ -164,16 +164,48 @@ func TestBuildXAIImagesGenerationsRequestNineByTwentyFromSize(t *testing.T) { } } +func TestBuildXAIImagesGenerationsRequestTwentyByNine(t *testing.T) { + rawJSON := []byte(`{"model":"grok-imagine-image-quality","prompt":"kitten","aspect_ratio":"20:9","resolution":"2k","n":1,"response_format":"b64_json"}`) + + req := buildXAIImagesGenerationsRequest(rawJSON, "grok-imagine-image-quality", "b64_json") + + if got := gjson.GetBytes(req, "aspect_ratio").String(); got != "20:9" { + t.Fatalf("aspect_ratio = %q, want 20:9", got) + } + if got := gjson.GetBytes(req, "resolution").String(); got != "2k" { + t.Fatalf("resolution = %q, want 2k", got) + } +} + +func TestBuildXAIImagesGenerationsRequestTwentyByNineFromSize(t *testing.T) { + rawJSON := []byte(`{"model":"grok-imagine-image-quality","prompt":"kitten","size":"20:9","resolution":"2k"}`) + + req := buildXAIImagesGenerationsRequest(rawJSON, "grok-imagine-image-quality", "b64_json") + + if got := gjson.GetBytes(req, "aspect_ratio").String(); got != "20:9" { + t.Fatalf("aspect_ratio from size = %q, want 20:9", got) + } + if got := gjson.GetBytes(req, "resolution").String(); got != "2k" { + t.Fatalf("resolution = %q, want 2k", got) + } +} + func TestXAIImagesAspectRatioNineByTwenty(t *testing.T) { if got := xaiImagesAspectRatio("9:20", "1:1"); got != "9:20" { t.Fatalf("xaiImagesAspectRatio(9:20) = %q, want 9:20", got) } + if got := xaiImagesAspectRatio("20:9", "1:1"); got != "20:9" { + t.Fatalf("xaiImagesAspectRatio(20:9) = %q, want 20:9", got) + } if got := xaiImagesAspectRatio("9:21", "1:1"); got != "1:1" { t.Fatalf("unknown ratio should keep fallback, got %q", got) } if got := xaiImagesAspectRatioFromSize("9:20", ""); got != "9:20" { t.Fatalf("xaiImagesAspectRatioFromSize(9:20) = %q, want 9:20", got) } + if got := xaiImagesAspectRatioFromSize("20:9", ""); got != "20:9" { + t.Fatalf("xaiImagesAspectRatioFromSize(20:9) = %q, want 20:9", got) + } } func TestBuildXAIImagesEditRequest(t *testing.T) {