match codex image request payload

This commit is contained in:
Anton Bogdanovich 2026-05-05 14:33:40 -07:00
parent 135f721dfc
commit 05e4538883
2 changed files with 33 additions and 2 deletions

View file

@ -14,6 +14,7 @@ import (
const (
codexDefaultImageGenerationModel = "gpt-image-2"
codexDefaultImageGenerationSize = "1024x1024"
maxImageGenerationResults = 4
maxImageGenerationSSEBytes = 64 * 1024 * 1024
maxImageGenerationEvents = 512
@ -93,9 +94,14 @@ func (p *CodexProvider) requestOptions() ([]option.RequestOption, string, error)
}
func buildCodexImageParams(req ImageGenerationRequest) responses.ResponseNewParams {
size := strings.TrimSpace(req.Size)
if size == "" {
size = codexDefaultImageGenerationSize
}
tool := responses.ToolUnionParam{OfImageGeneration: &responses.ToolImageGenerationParam{
Model: req.Model,
Size: req.Size,
Size: size,
}}
if req.Quality != "" {
tool.OfImageGeneration.Quality = req.Quality
@ -104,10 +110,17 @@ func buildCodexImageParams(req ImageGenerationRequest) responses.ResponseNewPara
tool.OfImageGeneration.OutputFormat = req.OutputFormat
}
content := responses.ResponseInputMessageContentListParam{
responses.ResponseInputContentParamOfInputText(req.Prompt),
}
input := responses.ResponseInputParam{
responses.ResponseInputItemParamOfMessage(content, responses.EasyInputMessageRoleUser),
}
return responses.ResponseNewParams{
Model: "gpt-5.4",
Input: responses.ResponseNewParamsInputUnion{
OfString: openai.Opt(req.Prompt),
OfInputItemList: input,
},
Instructions: openai.Opt("You are an image generation assistant."),
Tools: []responses.ToolUnionParam{tool},

View file

@ -2,6 +2,8 @@ package oauthprovider
import (
"encoding/base64"
"encoding/json"
"strings"
"testing"
"github.com/openai/openai-go/v3/responses"
@ -51,6 +53,22 @@ func TestBuildCodexImageParams(t *testing.T) {
if params.Model != "gpt-5.4" {
t.Fatalf("request model = %q, want gpt-5.4", params.Model)
}
if params.Input.OfString.Valid() {
t.Fatalf("input uses string form, want structured message input")
}
if len(params.Input.OfInputItemList) != 1 {
t.Fatalf("input item count = %d, want 1", len(params.Input.OfInputItemList))
}
data, err := json.Marshal(params)
if err != nil {
t.Fatalf("marshal params: %v", err)
}
payload := string(data)
for _, want := range []string{`"input":[`, `"role":"user"`, `"type":"input_text"`, `"text":"make a tiny icon"`} {
if !strings.Contains(payload, want) {
t.Fatalf("payload missing %s: %s", want, payload)
}
}
if len(params.Tools) != 1 || params.Tools[0].OfImageGeneration == nil {
t.Fatalf("expected one image_generation tool, got %#v", params.Tools)
}