Skip to content

Commit 66ab8db

Browse files
committed
fix(codex): add missing stream=true flag to responses request
The Codex Responses API requires stream=true when using the text/event-stream Accept header. Without it, the API returns 400 with 'Stream must be set to true'.
1 parent c6acfa5 commit 66ab8db

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

provider/codex/client.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ func (c *Client) Capabilities(_ string) provider.Capability {
121121
SupportsThinking: false,
122122
SupportsReferences: false,
123123
SupportsBatch: false,
124+
SupportsQuality: true,
124125
Sizes: []string{"1024x1024", "1536x1024", "1024x1536"},
125126
MaxReferences: 0,
126127
}
@@ -138,6 +139,12 @@ func (c *Client) Generate(ctx context.Context, req provider.GenerateRequest) (*p
138139
}
139140
meta, _ := resolveTier(modelID)
140141

142+
// Allow --quality flag to override the tier default.
143+
quality := meta.Quality
144+
if req.Quality != "" {
145+
quality = req.Quality
146+
}
147+
141148
size, warnings := mapSize(req.Size, req.AspectRatio)
142149
background := defaultBackground
143150
if req.Background != "" {
@@ -147,6 +154,7 @@ func (c *Client) Generate(ctx context.Context, req provider.GenerateRequest) (*p
147154
apiReq := responsesRequest{
148155
Model: defaultChatModel,
149156
Store: false,
157+
Stream: true,
150158
Instructions: "You are an assistant that must fulfill image generation requests by using the image_generation tool when provided.",
151159
Input: []inputItem{
152160
{
@@ -162,7 +170,7 @@ func (c *Client) Generate(ctx context.Context, req provider.GenerateRequest) (*p
162170
Type: "image_generation",
163171
Model: defaultAPIModel,
164172
Size: size,
165-
Quality: meta.Quality,
173+
Quality: quality,
166174
OutputFormat: "png",
167175
Background: background,
168176
PartialImages: 1,
@@ -281,6 +289,12 @@ func mapSize(size, aspect string) (string, []string) {
281289
// extractImageB64 reads an SSE stream and extracts the base64 image.
282290
func (c *Client) extractImageB64(r io.Reader) (string, error) {
283291
scanner := bufio.NewScanner(r)
292+
// Increase buffer beyond the default 64 KiB — SSE data lines can carry
293+
// large base64-encoded image payloads.
294+
const maxCapacity = 8 * 1024 * 1024 // 8 MiB
295+
buf := make([]byte, 64*1024)
296+
scanner.Buffer(buf, maxCapacity)
297+
284298
var currentEvent string
285299
var currentData strings.Builder
286300

@@ -386,6 +400,7 @@ func digString(m map[string]any, keys ...string) string {
386400
type responsesRequest struct {
387401
Model string `json:"model"`
388402
Store bool `json:"store"`
403+
Stream bool `json:"stream"`
389404
Instructions string `json:"instructions"`
390405
Input []inputItem `json:"input"`
391406
Tools []toolItem `json:"tools"`

0 commit comments

Comments
 (0)