SpyBara
Go Premium

Documentation 2026-08-04 22:59 UTC to 2026-08-05 18:01 UTC

59 files changed +8,166 −41. View all changes and history on the product overview
2026
Thu 13 04:57 Wed 12 02:57 Tue 11 19:59 Mon 10 19:00 Fri 7 00:58 Thu 6 21:58 Wed 5 18:01 Tue 4 22:59 Mon 3 18:01
Details

36)36)

37```37```

38 38 

39```go

40input, err := os.Open("revenue-forecast.csv")

41if err != nil {

42 panic(err)

43}

44defer input.Close()

45file, err := client.Files.New(context.Background(), openai.FileNewParams{

46 File: input,

47 Purpose: openai.FilePurposeAssistants,

48})

49if err != nil {

50 panic(err)

51}

52```

53 

39```bash54```bash

40curl https://api.openai.com/v1/files \55curl https://api.openai.com/v1/files \

41 -H "Authorization: Bearer $OPENAI_API_KEY" \56 -H "Authorization: Bearer $OPENAI_API_KEY" \


71)86)

72```87```

73 88 

89```go

90assistant, err := client.Beta.Assistants.New(context.Background(), openai.BetaAssistantNewParams{

91 Name: openai.String("Data visualizer"),

92 Description: openai.String("You are great at creating beautiful data visualizations. You analyze data present in .csv files, understand trends, and come up with data visualizations relevant to those trends. You also share a brief text summary of the trends observed."),

93 Model: shared.ChatModelGPT4o,

94 Tools: []openai.AssistantToolUnionParam{{OfCodeInterpreter: &openai.CodeInterpreterToolParam{}}},

95 ToolResources: openai.BetaAssistantNewParamsToolResources{

96 CodeInterpreter: openai.BetaAssistantNewParamsToolResourcesCodeInterpreter{FileIDs: []string{"file-BK7bzQj3FfZFXr7DbL6xJwfo"}},

97 },

98})

99if err != nil {

100 panic(err)

101}

102```

103 

74```bash104```bash

75curl https://api.openai.com/v1/assistants \105curl https://api.openai.com/v1/assistants \

76 -H "Authorization: Bearer $OPENAI_API_KEY" \106 -H "Authorization: Bearer $OPENAI_API_KEY" \


131)161)

132```162```

133 163 

164```go

165thread, err := client.Beta.Threads.New(context.Background(), openai.BetaThreadNewParams{

166 Messages: []openai.BetaThreadNewParamsMessage{{

167 Role: "user",

168 Content: openai.BetaThreadNewParamsMessageContentUnion{

169 OfString: openai.String("Create 3 data visualizations based on the trends in this file."),

170 },

171 Attachments: []openai.BetaThreadNewParamsMessageAttachment{{

172 FileID: openai.String("file-ACq8OjcLQm2eIG0BvRM4z5qX"),

173 Tools: []openai.BetaThreadNewParamsMessageAttachmentToolUnion{{OfCodeInterpreter: &openai.CodeInterpreterToolParam{}}},

174 }},

175 }},

176})

177if err != nil {

178 panic(err)

179}

180```

181 

134```bash182```bash

135curl https://api.openai.com/v1/threads \183curl https://api.openai.com/v1/threads \

136 -H "Authorization: Bearer $OPENAI_API_KEY" \184 -H "Authorization: Bearer $OPENAI_API_KEY" \


217)265)

218```266```

219 267 

268```go

269image, err := os.Open("myimage.png")

270if err != nil {

271 panic(err)

272}

273defer image.Close()

274file, err := client.Files.New(context.Background(), openai.FileNewParams{

275 File: image,

276 Purpose: openai.FilePurposeVision,

277})

278if err != nil {

279 panic(err)

280}

281thread, err := client.Beta.Threads.New(context.Background(), openai.BetaThreadNewParams{

282 Messages: []openai.BetaThreadNewParamsMessage{{

283 Role: "user",

284 Content: openai.BetaThreadNewParamsMessageContentUnion{OfArrayOfContentParts: []openai.MessageContentPartParamUnion{

285 openai.MessageContentPartParamOfText("What is the difference between these images?"),

286 openai.MessageContentPartParamOfImageURL(openai.ImageURLParam{URL: "https://openai-documentation.vercel.app/images/cat_and_otter.png"}),

287 openai.MessageContentPartParamOfImageFile(openai.ImageFileParam{FileID: file.ID}),

288 }},

289 }},

290})

291if err != nil {

292 panic(err)

293}

294```

295 

220```bash296```bash

221# Upload a file with an "vision" purpose297# Upload a file with an "vision" purpose

222curl https://api.openai.com/v1/files \298curl https://api.openai.com/v1/files \


304)380)

305```381```

306 382 

383```go

384thread, err := client.Beta.Threads.New(context.Background(), openai.BetaThreadNewParams{

385 Messages: []openai.BetaThreadNewParamsMessage{{

386 Role: "user",

387 Content: openai.BetaThreadNewParamsMessageContentUnion{OfArrayOfContentParts: []openai.MessageContentPartParamUnion{

388 openai.MessageContentPartParamOfText("What is this an image of?"),

389 openai.MessageContentPartParamOfImageURL(openai.ImageURLParam{

390 URL: "https://openai-documentation.vercel.app/images/cat_and_otter.png",

391 Detail: openai.ImageURLDetailHigh,

392 }),

393 }},

394 }},

395})

396if err != nil {

397 panic(err)

398}

399```

400 

307```bash401```bash

308curl https://api.openai.com/v1/threads \402curl https://api.openai.com/v1/threads \

309 -H "Authorization: Bearer $OPENAI_API_KEY" \403 -H "Authorization: Bearer $OPENAI_API_KEY" \


410message_content.value += "\n" + "\n".join(citations)504message_content.value += "\n" + "\n".join(citations)

411```505```

412 506 

507```go

508message, err := client.Beta.Threads.Messages.Get(context.Background(), "thread_abc123", "msg_abc123")

509if err != nil {

510 panic(err)

511}

512if len(message.Content) == 0 || message.Content[0].Type != "text" {

513 panic("message does not contain text")

514}

515messageContent := message.Content[0].AsText().Text

516citations := make([]string, 0, len(messageContent.Annotations))

517for index, annotation := range messageContent.Annotations {

518 messageContent.Value = strings.ReplaceAll(messageContent.Value, annotation.Text, fmt.Sprintf(" [%d]", index))

519 switch annotation.Type {

520 case "file_citation":

521 citation := annotation.AsFileCitation()

522 file, err := client.Files.Get(context.Background(), citation.FileCitation.FileID)

523 if err != nil {

524 panic(err)

525 }

526 citations = append(citations, fmt.Sprintf("[%d] %s", index, file.Filename))

527 case "file_path":

528 filePath := annotation.AsFilePath()

529 file, err := client.Files.Get(context.Background(), filePath.FilePath.FileID)

530 if err != nil {

531 panic(err)

532 }

533 response, err := client.Files.Content(context.Background(), filePath.FilePath.FileID)

534 if err != nil {

535 panic(err)

536 }

537 defer response.Body.Close()

538 if err := os.MkdirAll("downloads", 0o755); err != nil {

539 panic(err)

540 }

541 outputPath := filepath.Join("downloads", filepath.Base(file.Filename))

542 output, err := os.Create(outputPath)

543 if err != nil {

544 panic(err)

545 }

546 if _, err := io.Copy(output, response.Body); err != nil {

547 output.Close()

548 panic(err)

549 }

550 if err := output.Close(); err != nil {

551 panic(err)

552 }

553 citations = append(citations, fmt.Sprintf("[%d] Downloaded %s", index, outputPath))

554 }

555}

556messageContent.Value += "\n" + strings.Join(citations, "\n")

557fmt.Println(messageContent.Value)

558```

559 

413 560 

414## Runs and Run Steps561## Runs and Run Steps

415 562 


428)575)

429```576```

430 577 

578```go

579_, err := client.Beta.Threads.Runs.New(context.Background(), "thread_abc123", openai.BetaThreadRunNewParams{

580 AssistantID: "asst_ToSF7Gb04YMj8AMMm50ZLLtY",

581})

582if err != nil {

583 panic(err)

584}

585```

586 

431```bash587```bash

432curl https://api.openai.com/v1/threads/THREAD_ID/runs \588curl https://api.openai.com/v1/threads/THREAD_ID/runs \

433 -H "Authorization: Bearer $OPENAI_API_KEY" \589 -H "Authorization: Bearer $OPENAI_API_KEY" \


460)616)

461```617```

462 618 

619```go

620_, err := client.Beta.Threads.Runs.New(context.Background(), "thread_abc123", openai.BetaThreadRunNewParams{

621 AssistantID: "asst_ToSF7Gb04YMj8AMMm50ZLLtY",

622 Model: shared.ChatModelGPT4o,

623 Instructions: openai.String("New instructions that override the Assistant instructions"),

624 Tools: []openai.AssistantToolUnionParam{

625 {OfCodeInterpreter: &openai.CodeInterpreterToolParam{}},

626 {OfFileSearch: &openai.FileSearchToolParam{}},

627 },

628})

629if err != nil {

630 panic(err)

631}

632```

633 

463```bash634```bash

464curl https://api.openai.com/v1/threads/THREAD_ID/runs \635curl https://api.openai.com/v1/threads/THREAD_ID/runs \

465 -H "Authorization: Bearer $OPENAI_API_KEY" \636 -H "Authorization: Bearer $OPENAI_API_KEY" \

Details

81 81 

82### Request example82### Request example

83 83 

84#### Python

85 

86#### Go

87 

84### Response example88### Response example

85 89 

86 90 


124 128 

125### Request example129### Request example

126 130 

131#### Python

132 

133#### Go

134 

127### Response example135### Response example

128 136 

129 137 

Details

35)35)

36```36```

37 37 

38```go

39assistant, err := client.Beta.Assistants.New(context.Background(), openai.BetaAssistantNewParams{

40 Instructions: openai.String("You are a personal math tutor. When asked a math question, write and run code to answer the question."),

41 Model: shared.ChatModelGPT4o,

42 Tools: []openai.AssistantToolUnionParam{{OfCodeInterpreter: &openai.CodeInterpreterToolParam{}}},

43})

44if err != nil {

45 panic(err)

46}

47```

48 

38```bash49```bash

39curl https://api.openai.com/v1/assistants \50curl https://api.openai.com/v1/assistants \

40 -u :$OPENAI_API_KEY \51 -u :$OPENAI_API_KEY \


90)101)

91```102```

92 103 

104```go

105input, err := os.Open("mydata.csv")

106if err != nil {

107 panic(err)

108}

109defer input.Close()

110file, err := client.Files.New(context.Background(), openai.FileNewParams{

111 File: input,

112 Purpose: openai.FilePurposeAssistants,

113})

114if err != nil {

115 panic(err)

116}

117assistant, err := client.Beta.Assistants.New(context.Background(), openai.BetaAssistantNewParams{

118 Instructions: openai.String("You are a personal math tutor. When asked a math question, write and run code to answer the question."),

119 Model: shared.ChatModelGPT4o,

120 Tools: []openai.AssistantToolUnionParam{{OfCodeInterpreter: &openai.CodeInterpreterToolParam{}}},

121 ToolResources: openai.BetaAssistantNewParamsToolResources{

122 CodeInterpreter: openai.BetaAssistantNewParamsToolResourcesCodeInterpreter{FileIDs: []string{file.ID}},

123 },

124})

125if err != nil {

126 panic(err)

127}

128```

129 

93```bash130```bash

94# Upload a file with an "assistants" purpose131# Upload a file with an "assistants" purpose

95curl https://api.openai.com/v1/files \132curl https://api.openai.com/v1/files \


148)185)

149```186```

150 187 

188```go

189thread, err := client.Beta.Threads.New(context.Background(), openai.BetaThreadNewParams{

190 Messages: []openai.BetaThreadNewParamsMessage{{

191 Role: "user",

192 Content: openai.BetaThreadNewParamsMessageContentUnion{OfString: openai.String("I need to solve the equation `3x + 11 = 14`. Can you help me?")},

193 Attachments: []openai.BetaThreadNewParamsMessageAttachment{{

194 FileID: openai.String("file-ACq8OjcLQm2eIG0BvRM4z5qX"),

195 Tools: []openai.BetaThreadNewParamsMessageAttachmentToolUnion{{OfCodeInterpreter: &openai.CodeInterpreterToolParam{}}},

196 }},

197 }},

198})

199if err != nil {

200 panic(err)

201}

202```

203 

151```bash204```bash

152curl https://api.openai.com/v1/threads/thread_abc123/messages \205curl https://api.openai.com/v1/threads/thread_abc123/messages \

153 -u :$OPENAI_API_KEY \206 -u :$OPENAI_API_KEY \


235 file.write(image_data_bytes)288 file.write(image_data_bytes)

236```289```

237 290 

291```go

292response, err := client.Files.Content(context.Background(), "file-abc123")

293if err != nil {

294 panic(err)

295}

296defer response.Body.Close()

297output, err := os.Create("./my-image.png")

298if err != nil {

299 panic(err)

300}

301if _, err := io.Copy(output, response.Body); err != nil {

302 output.Close()

303 panic(err)

304}

305if err := output.Close(); err != nil {

306 panic(err)

307}

308```

309 

238```bash310```bash

239curl https://api.openai.com/v1/files/file-abc123/content \311curl https://api.openai.com/v1/files/file-abc123/content \

240 -H "Authorization: Bearer $OPENAI_API_KEY" \312 -H "Authorization: Bearer $OPENAI_API_KEY" \


291)363)

292```364```

293 365 

366```go

367runSteps, err := client.Beta.Threads.Runs.Steps.List(context.Background(), "thread_abc123", "run_abc123", openai.BetaThreadRunStepListParams{})

368if err != nil {

369 panic(err)

370}

371fmt.Println(runSteps.Data)

372```

373 

294```bash374```bash

295curl https://api.openai.com/v1/threads/thread_abc123/runs/RUN_ID/steps \375curl https://api.openai.com/v1/threads/thread_abc123/runs/RUN_ID/steps \

296 -H "Authorization: Bearer $OPENAI_API_KEY" \376 -H "Authorization: Bearer $OPENAI_API_KEY" \

Details

129)129)

130```130```

131 131 

132```go

133assistant, err := client.Beta.Assistants.New(context.Background(), openai.BetaAssistantNewParams{

134 Model: shared.ChatModelGPT4o,

135 Instructions: openai.String("You are a weather bot. Use the provided functions to answer questions."),

136 Tools: weatherTools(false),

137})

138if err != nil {

139 panic(err)

140}

141 

142func weatherTools(strict bool) []openai.AssistantToolUnionParam {

143 return []openai.AssistantToolUnionParam{

144 openai.AssistantToolParamOfFunction(shared.FunctionDefinitionParam{

145 Name: "get_current_temperature",

146 Description: openai.String("Get the current temperature for a specific location"),

147 Parameters: map[string]any{

148 "type": "object",

149 "properties": map[string]any{

150 "location": map[string]any{"type": "string", "description": "The city and state, e.g., San Francisco, CA"},

151 "unit": map[string]any{"type": "string", "enum": []string{"Celsius", "Fahrenheit"}, "description": "The temperature unit to use. Infer this from the user's location."},

152 },

153 "required": []string{"location", "unit"},

154 },

155 Strict: openai.Bool(strict),

156 }),

157 openai.AssistantToolParamOfFunction(shared.FunctionDefinitionParam{

158 Name: "get_rain_probability",

159 Description: openai.String("Get the probability of rain for a specific location"),

160 Parameters: map[string]any{

161 "type": "object",

162 "properties": map[string]any{

163 "location": map[string]any{"type": "string", "description": "The city and state, e.g., San Francisco, CA"},

164 },

165 "required": []string{"location"},

166 },

167 Strict: openai.Bool(strict),

168 }),

169 }

170}

171```

172 

132 173 

133### Step 2: Create a Thread and add Messages174### Step 2: Create a Thread and add Messages

134 175 


152)193)

153```194```

154 195 

196```go

197thread, err := client.Beta.Threads.New(context.Background(), openai.BetaThreadNewParams{})

198if err != nil {

199 panic(err)

200}

201_, err = client.Beta.Threads.Messages.New(context.Background(), thread.ID, openai.BetaThreadMessageNewParams{

202 Role: "user",

203 Content: openai.BetaThreadMessageNewParamsContentUnion{

204 OfString: openai.String("What's the weather in San Francisco today and the likelihood it'll rain?"),

205 },

206})

207if err != nil {

208 panic(err)

209}

210```

211 

155 212 

156### Step 3: Initiate a Run213### Step 3: Initiate a Run

157 214 


346 403

347 404 

348Runs are asynchronous, which means you'll want to monitor their `status` by polling the Run object until a405Runs are asynchronous, which means you'll want to monitor their `status` by polling the Run object until a

349[terminal status](https://developers.openai.com/api/docs/assistants/deep-dive#runs-and-run-steps) is reached. For convenience, the 'create and poll' SDK helpers assist both in406[terminal status](https://developers.openai.com/api/docs/assistants/deep-dive#runs-and-run-steps) is reached. For convenience, where available, the 'create and poll' SDK helpers assist both in

350creating the run and then polling for its completion. Once the Run completes, you can list the407creating the run and then polling for its completion. The Go tab shows the equivalent workflow with manual polling. Once the Run completes, you can list the

351Messages added to the Thread by the Assistant. Finally, you would retrieve all the `tool_outputs` from408Messages added to the Thread by the Assistant. Finally, you would retrieve all the `tool_outputs` from

352`required_action` and submit them at the same time to the 'submit tool outputs and poll' helper.409`required_action` and submit them at the same time to the 'submit tool outputs and poll' helper.

353 410 


456 print(run.status)513 print(run.status)

457```514```

458 515 

516```go

517run, err := client.Beta.Threads.Runs.New(context.Background(), thread.ID, openai.BetaThreadRunNewParams{

518 AssistantID: assistant.ID,

519})

520if err != nil {

521 panic(err)

522}

523run = pollRun(client, thread.ID, run)

524if run.Status == openai.RunStatusRequiresAction {

525 outputs := make([]openai.BetaThreadRunSubmitToolOutputsParamsToolOutput, 0)

526 for _, toolCall := range run.RequiredAction.SubmitToolOutputs.ToolCalls {

527 switch toolCall.Function.Name {

528 case "get_current_temperature":

529 outputs = append(outputs, openai.BetaThreadRunSubmitToolOutputsParamsToolOutput{

530 ToolCallID: openai.String(toolCall.ID), Output: openai.String("57"),

531 })

532 case "get_rain_probability":

533 outputs = append(outputs, openai.BetaThreadRunSubmitToolOutputsParamsToolOutput{

534 ToolCallID: openai.String(toolCall.ID), Output: openai.String("0.06"),

535 })

536 }

537 }

538 if len(outputs) > 0 {

539 run, err = client.Beta.Threads.Runs.SubmitToolOutputs(

540 context.Background(), thread.ID, run.ID,

541 openai.BetaThreadRunSubmitToolOutputsParams{ToolOutputs: outputs},

542 )

543 if err != nil {

544 panic(err)

545 }

546 run = pollRun(client, thread.ID, run)

547 }

548}

549if run.Status == openai.RunStatusCompleted {

550 messages, err := client.Beta.Threads.Messages.List(context.Background(), thread.ID, openai.BetaThreadMessageListParams{})

551 if err != nil {

552 panic(err)

553 }

554 fmt.Println(messages.Data)

555} else {

556 fmt.Println(run.Status)

557}

558 

559func pollRun(client openai.Client, threadID string, run *openai.Run) *openai.Run {

560 for run.Status == openai.RunStatusQueued || run.Status == openai.RunStatusInProgress {

561 time.Sleep(time.Second)

562 next, err := client.Beta.Threads.Runs.Get(context.Background(), threadID, run.ID)

563 if err != nil {

564 panic(err)

565 }

566 run = next

567 }

568 return run

569}

570```

571 

459 572 

460 573 

461### Using Structured Outputs574### Using Structured Outputs


587 ],700 ],

588)701)

589```702```

703 

704```go

705assistant, err := client.Beta.Assistants.New(context.Background(), openai.BetaAssistantNewParams{

706 Model: shared.ChatModelGPT4o2024_08_06,

707 Instructions: openai.String("You are a weather bot. Use the provided functions to answer questions."),

708 Tools: weatherTools(),

709})

710if err != nil {

711 panic(err)

712}

713 

714func weatherTools() []openai.AssistantToolUnionParam {

715 return []openai.AssistantToolUnionParam{

716 openai.AssistantToolParamOfFunction(shared.FunctionDefinitionParam{

717 Name: "get_current_temperature",

718 Description: openai.String("Get the current temperature for a specific location"),

719 Parameters: map[string]any{

720 "type": "object",

721 "properties": map[string]any{

722 "location": map[string]any{"type": "string", "description": "The city and state, e.g., San Francisco, CA"},

723 "unit": map[string]any{"type": "string", "enum": []string{"Celsius", "Fahrenheit"}, "description": "The temperature unit to use. Infer this from the user's location."},

724 },

725 "required": []string{"location", "unit"},

726 "additionalProperties": false,

727 },

728 Strict: openai.Bool(true),

729 }),

730 openai.AssistantToolParamOfFunction(shared.FunctionDefinitionParam{

731 Name: "get_rain_probability",

732 Description: openai.String("Get the probability of rain for a specific location"),

733 Parameters: map[string]any{

734 "type": "object",

735 "properties": map[string]any{

736 "location": map[string]any{"type": "string", "description": "The city and state, e.g., San Francisco, CA"},

737 },

738 "required": []string{"location"},

739 "additionalProperties": false,

740 },

741 Strict: openai.Bool(true),

742 }),

743 }

744}

745```

deprecations.md +11 −12

Details

153 153 

154| Shutdown date | Model snapshot | Recommended replacement base model |154| Shutdown date | Model snapshot | Recommended replacement base model |

155| ---------------- | ---------------------------- | ---------------------------------- |155| ---------------- | ---------------------------- | ---------------------------------- |

156| October 23, 2026 | `ft-gpt-3.5-turbo` | `gpt-5.4-mini` |156| October 23, 2026 | `ft-gpt-3.5-turbo` | `gpt-5.6-terra` |

157| October 23, 2026 | `ft-gpt-4` | `gpt-5.5` |157| October 23, 2026 | `ft-gpt-4` | `gpt-5.6-sol` |

158| October 23, 2026 | `ft-gpt-4.1-nano-2025-04-14` | `gpt-5.4-nano` |158| October 23, 2026 | `ft-gpt-4.1-nano-2025-04-14` | `gpt-5.6-luna` |

159| October 23, 2026 | `ft-babbage-002` | `gpt-5.4-mini` |159| October 23, 2026 | `ft-babbage-002` | `gpt-5.6-terra` |

160| October 23, 2026 | `ft-davinci-002` | `gpt-5.4-mini` |160| October 23, 2026 | `ft-davinci-002` | `gpt-5.6-terra` |

161 161 

162### 2026-03-24: Sora 2 video generation models and Videos API162### 2026-03-24: Sora 2 video generation models and Videos API

163 163 


177To improve reliability and make it easier for developers to choose the right models, we are deprecating a set of older OpenAI models with declining usage over the next six to twelve months. Access to these models will be shut down on the dates below.177To improve reliability and make it easier for developers to choose the right models, we are deprecating a set of older OpenAI models with declining usage over the next six to twelve months. Access to these models will be shut down on the dates below.

178 178 

179| Shutdown date | Model / system | Recommended replacement |179| Shutdown date | Model / system | Recommended replacement |

180| ------------- | ------------------------ | ------------------------------ |180| ------------- | ------------------------ | ----------------------- |

181| 2026-09-28 | `gpt-3.5-turbo-instruct` | `gpt-5.4-mini` or `gpt-5-mini` |181| 2026-09-28 | `gpt-3.5-turbo-instruct` | `gpt-5.6-terra` |

182| 2026-09-28 | `babbage-002` | `gpt-5.4-mini` or `gpt-5-mini` |182| 2026-09-28 | `babbage-002` | `gpt-5.6-terra` |

183| 2026-09-28 | `davinci-002` | `gpt-5.4-mini` or `gpt-5-mini` |183| 2026-09-28 | `davinci-002` | `gpt-5.6-terra` |

184| 2026-09-28 | `gpt-3.5-turbo-1106` | `gpt-5.4-mini` or `gpt-5-mini` |184| 2026-09-28 | `gpt-3.5-turbo-1106` | `gpt-5.6-terra` |

185 185 

186### 2025-08-20: Assistants API186### 2025-08-20: Assistants API

187 187 


204On April 22, 2026, we announced the deprecation of the following older OpenAI models. Access to these models was shut down on July 23, 2026.204On April 22, 2026, we announced the deprecation of the following older OpenAI models. Access to these models was shut down on July 23, 2026.

205 205 

206| Shutdown date | Model snapshot | Substitute model |206| Shutdown date | Model snapshot | Substitute model |

207| ------------- | ------------------------------------------------------------- | ---------------------------- |207| ------------- | ------------------------------------------------------------- | ----------------------- |

208| July 23, 2026 | `computer-use-preview-2025-03-11` \| `computer-use-preview` | `gpt-5.6-terra` |208| July 23, 2026 | `computer-use-preview-2025-03-11` \| `computer-use-preview` | `gpt-5.6-terra` |

209| July 23, 2026 | `gpt-4o-mini-search-preview-2025-03-11` | `gpt-5.6-terra` |209| July 23, 2026 | `gpt-4o-mini-search-preview-2025-03-11` | `gpt-5.6-terra` |

210| July 23, 2026 | `gpt-4o-mini-tts-2025-03-20` | `gpt-4o-mini-tts-2025-12-15` |

211| July 23, 2026 | `gpt-4o-search-preview-2025-03-11` | `gpt-5.6-terra` |210| July 23, 2026 | `gpt-4o-search-preview-2025-03-11` | `gpt-5.6-terra` |

212| July 23, 2026 | `gpt-5-chat-latest` | `gpt-5.6-sol` |211| July 23, 2026 | `gpt-5-chat-latest` | `gpt-5.6-sol` |

213| July 23, 2026 | `gpt-5-codex` | `gpt-5.6-sol` |212| July 23, 2026 | `gpt-5-codex` | `gpt-5.6-sol` |

Details

220| Function calling | Available | Available |220| Function calling | Available | Available |

221| Streaming responses | Available | Available |221| Streaming responses | Available | Available |

222| WebSocket connections | Available | Not available |222| WebSocket connections | Available | Not available |

223| Context window | Model-dependent | 272,000 tokens for GPT-5.4, GPT-5.5, and GPT-5.6 |223| Context window | Model-dependent | 272,000 tokens for GPT-5.4 and GPT-5.5 |

224| Context window | Model-dependent | 1,050,000 tokens for GPT-5.6 Sol, Terra, and Luna |

224| Reasoning effort | Available | Available, including `max` on supported models |225| Reasoning effort | Available | Available, including `max` on supported models |

225| Pro mode | Available on supported models | Not available |226| Pro mode | Available on supported models | Not available |

226| Persisted reasoning | Available on supported models | Available on supported models |227| Persisted reasoning | Available on supported models | Available on supported models |


229| Multi-agent | Beta on supported models | Not available |230| Multi-agent | Beta on supported models | Not available |

230| Custom tools | Available | Available |231| Custom tools | Available | Available |

231| Client-side `tool_search` | Available | Available |232| Client-side `tool_search` | Available | Available |

232| Hosted web search | Available | Not available |233| Hosted web search | Available | Available |

233| Hosted file search | Available | Not available |234| Hosted file search | Available | Not available |

234| Computer use | Available | Not available |235| Computer use | Available | Not available |

235| Shell tool | Available | Not available |236| Shell tool | Available | Not available |


238| Service tiers | Available where supported | On-demand inference only |239| Service tiers | Available where supported | On-demand inference only |

239 240 

240Client-side `tool_search` is distinct from hosted tools and remote MCP server241Client-side `tool_search` is distinct from hosted tools and remote MCP server

241support. Hosted tools run through OpenAI-operated service infrastructure and242support. Hosted web search is available on Amazon Bedrock, but hosted file

242are unavailable on Amazon Bedrock.243search and remote MCP servers are unavailable.

243 244 

244GPT-5.4, GPT-5.5, and GPT-5.6 have a 272,000-token context window on Amazon245GPT-5.4 and GPT-5.5 have a 272,000-token context window on Amazon Bedrock.

245Bedrock. Amazon Bedrock rejects requests that exceed this limit. See the AWS246GPT-5.6 Sol, Terra, and Luna have a 1,050,000-token context window. Amazon

247Bedrock rejects requests that exceed the applicable model limit. See the AWS

246model cards for current model-specific limits.248model cards for current model-specific limits.

247 249 

248Treat feature parity as workload-specific. If your application depends on a250Treat feature parity as workload-specific. If your application depends on a

guides/audio.md +77 −0

Details

134 f.write(wav_bytes)134 f.write(wav_bytes)

135```135```

136 136 

137```go

138package main

139 

140import (

141 "context"

142 "encoding/base64"

143 "fmt"

144 "os"

145 

146 "github.com/openai/openai-go/v3"

147)

148 

149func main() {

150 client := openai.NewClient()

151 response, err := client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{

152 Model: "gpt-audio-1.5",

153 Modalities: []string{"text", "audio"},

154 Audio: openai.ChatCompletionAudioParam{

155 Voice: openai.ChatCompletionAudioParamVoiceUnion{OfString: openai.String("alloy")},

156 Format: openai.ChatCompletionAudioParamFormatWAV,

157 },

158 Messages: []openai.ChatCompletionMessageParamUnion{openai.UserMessage("Is a golden retriever a good family dog?")},

159 })

160 if err != nil {

161 panic(err)

162 }

163 fmt.Println(response.Choices[0])

164 audio, err := base64.StdEncoding.DecodeString(response.Choices[0].Message.Audio.Data)

165 if err != nil {

166 panic(err)

167 }

168 if err := os.WriteFile("dog.wav", audio, 0o600); err != nil {

169 panic(err)

170 }

171}

172```

173 

137```bash174```bash

138curl "https://api.openai.com/v1/chat/completions" \175curl "https://api.openai.com/v1/chat/completions" \

139 -H "Content-Type: application/json" \176 -H "Content-Type: application/json" \


227print(completion.choices[0].message)264print(completion.choices[0].message)

228```265```

229 266 

267```go

268package main

269 

270import (

271 "context"

272 "encoding/base64"

273 "fmt"

274 "os"

275 

276 "github.com/openai/openai-go/v3"

277)

278 

279func main() {

280 audio, err := os.ReadFile("fixtures/audio.wav")

281 if err != nil {

282 panic(err)

283 }

284 client := openai.NewClient()

285 response, err := client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{

286 Model: "gpt-audio-1.5",

287 Modalities: []string{"text", "audio"},

288 Audio: openai.ChatCompletionAudioParam{

289 Voice: openai.ChatCompletionAudioParamVoiceUnion{OfString: openai.String("alloy")},

290 Format: openai.ChatCompletionAudioParamFormatWAV,

291 },

292 Messages: []openai.ChatCompletionMessageParamUnion{openai.UserMessage([]openai.ChatCompletionContentPartUnionParam{

293 openai.TextContentPart("What is in this recording?"),

294 openai.InputAudioContentPart(openai.ChatCompletionContentPartInputAudioInputAudioParam{

295 Data: base64.StdEncoding.EncodeToString(audio),

296 Format: "wav",

297 }),

298 })},

299 })

300 if err != nil {

301 panic(err)

302 }

303 fmt.Println(response.Choices[0])

304}

305```

306 

230```bash307```bash

231curl "https://api.openai.com/v1/chat/completions" \308curl "https://api.openai.com/v1/chat/completions" \

232 -H "Content-Type: application/json" \309 -H "Content-Type: application/json" \

Details

50print(resp.status)50print(resp.status)

51```51```

52 52 

53```go

54package main

55 

56import (

57 "context"

58 "fmt"

59 

60 "github.com/openai/openai-go/v3"

61 "github.com/openai/openai-go/v3/responses"

62)

63 

64func main() {

65 client := openai.NewClient()

66 

67 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

68 Model: "gpt-5.6",

69 Background: openai.Bool(true),

70 Input: responses.ResponseNewParamsInputUnion{

71 OfString: openai.String("Write a very long novel about otters in space."),

72 },

73 })

74 if err != nil {

75 panic(err)

76 }

77 

78 fmt.Println(response.Status)

79}

80```

81 

53 82 

54## Polling background responses83## Polling background responses

55 84 


102print(f"Final status: {resp.status}\nOutput:\n{resp.output_text}")131print(f"Final status: {resp.status}\nOutput:\n{resp.output_text}")

103```132```

104 133 

134```go

135package main

136 

137import (

138 "context"

139 "fmt"

140 "time"

141 

142 "github.com/openai/openai-go/v3"

143 "github.com/openai/openai-go/v3/responses"

144)

145 

146func main() {

147 client := openai.NewClient()

148 

149 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

150 Model: "gpt-5.6",

151 Background: openai.Bool(true),

152 Input: responses.ResponseNewParamsInputUnion{

153 OfString: openai.String("Write a very long novel about otters in space."),

154 },

155 })

156 if err != nil {

157 panic(err)

158 }

159 

160 for response.Status == "queued" || response.Status == "in_progress" {

161 fmt.Println("Current status:", response.Status)

162 time.Sleep(2 * time.Second)

163 response, err = client.Responses.Get(context.Background(), response.ID, responses.ResponseGetParams{})

164 if err != nil {

165 panic(err)

166 }

167 }

168 

169 fmt.Printf("Final status: %s\nOutput:\n%s\n", response.Status, response.OutputText())

170}

171```

172 

105 173 

106## Cancelling a background response174## Cancelling a background response

107 175 


137print(resp.status)205print(resp.status)

138```206```

139 207 

208```go

209package main

210 

211import (

212 "context"

213 "fmt"

214 

215 "github.com/openai/openai-go/v3"

216)

217 

218func main() {

219 client := openai.NewClient()

220 

221 canceled, err := client.Responses.Cancel(context.Background(), "resp_123")

222 if err != nil {

223 panic(err)

224 }

225 

226 fmt.Println(canceled.Status)

227}

228```

229 

140 230 

141Cancelling twice is idempotent - subsequent calls simply return the final `Response` object.231Cancelling twice is idempotent - subsequent calls simply return the final `Response` object.

142 232 


213# print(event)303# print(event)

214```304```

215 305 

306```go

307package main

308 

309import (

310 "context"

311 "fmt"

312 

313 "github.com/openai/openai-go/v3"

314 "github.com/openai/openai-go/v3/responses"

315)

316 

317func main() {

318 client := openai.NewClient()

319 

320 stream := client.Responses.NewStreaming(context.Background(), responses.ResponseNewParams{

321 Model: "gpt-5.6",

322 Background: openai.Bool(true),

323 Input: responses.ResponseNewParamsInputUnion{

324 OfString: openai.String("Write a very long novel about otters in space."),

325 },

326 })

327 var cursor int64

328 var responseID string

329 for stream.Next() {

330 event := stream.Current()

331 fmt.Println(event.Type)

332 cursor = event.SequenceNumber

333 if event.Response.ID != "" {

334 responseID = event.Response.ID

335 }

336 }

337 if err := stream.Err(); err != nil {

338 panic(err)

339 }

340 fmt.Printf("response %s last cursor %d\n", responseID, cursor)

341 

342 // If the connection drops, resume streaming from the last cursor:

343 // resumed := client.Responses.GetStreaming(

344 // context.Background(),

345 // responseID,

346 // responses.ResponseGetParams{StartingAfter: openai.Int(cursor)},

347 // )

348 // for resumed.Next() {

349 // fmt.Println(resumed.Current().Type)

350 // }

351}

352```

353 

216 354 

217## Limits355## Limits

218 356 

guides/batch.md +142 −0

Details

130print(batch_input_file)130print(batch_input_file)

131```131```

132 132 

133```go

134package main

135 

136import (

137 "context"

138 "fmt"

139 "os"

140 

141 "github.com/openai/openai-go/v3"

142)

143 

144func main() {

145 client := openai.NewClient()

146 file, err := os.Open("batchinput.jsonl")

147 if err != nil {

148 panic(err)

149 }

150 defer file.Close()

151 

152 uploaded, err := client.Files.New(context.Background(), openai.FileNewParams{

153 File: file,

154 Purpose: openai.FilePurposeBatch,

155 })

156 if err != nil {

157 panic(err)

158 }

159 fmt.Println(uploaded.ID)

160}

161```

162 

133```bash163```bash

134curl https://api.openai.com/v1/files \164curl https://api.openai.com/v1/files \

135 -H "Authorization: Bearer $OPENAI_API_KEY" \165 -H "Authorization: Bearer $OPENAI_API_KEY" \


173print(batch)203print(batch)

174```204```

175 205 

206```go

207package main

208 

209import (

210 "context"

211 "fmt"

212 

213 "github.com/openai/openai-go/v3"

214)

215 

216func main() {

217 client := openai.NewClient()

218 batch, err := client.Batches.New(context.Background(), openai.BatchNewParams{

219 InputFileID: "file-abc123",

220 Endpoint: openai.BatchNewParamsEndpointV1ChatCompletions,

221 CompletionWindow: openai.BatchNewParamsCompletionWindow24h,

222 })

223 if err != nil {

224 panic(err)

225 }

226 fmt.Println(batch.ID)

227}

228```

229 

176```bash230```bash

177curl https://api.openai.com/v1/batches \231curl https://api.openai.com/v1/batches \

178 -H "Authorization: Bearer $OPENAI_API_KEY" \232 -H "Authorization: Bearer $OPENAI_API_KEY" \


239print(batch)293print(batch)

240```294```

241 295 

296```go

297package main

298 

299import (

300 "context"

301 "fmt"

302 

303 "github.com/openai/openai-go/v3"

304)

305 

306func main() {

307 client := openai.NewClient()

308 batch, err := client.Batches.Get(context.Background(), "batch_abc123")

309 if err != nil {

310 panic(err)

311 }

312 fmt.Println(batch.Status)

313}

314```

315 

242```bash316```bash

243curl https://api.openai.com/v1/batches/batch_abc123 \317curl https://api.openai.com/v1/batches/batch_abc123 \

244 -H "Authorization: Bearer $OPENAI_API_KEY" \318 -H "Authorization: Bearer $OPENAI_API_KEY" \


292print(file_response.text)366print(file_response.text)

293```367```

294 368 

369```go

370package main

371 

372import (

373 "context"

374 "fmt"

375 "io"

376 

377 "github.com/openai/openai-go/v3"

378)

379 

380func main() {

381 client := openai.NewClient()

382 response, err := client.Files.Content(context.Background(), "file-xyz123")

383 if err != nil {

384 panic(err)

385 }

386 defer response.Body.Close()

387 contents, err := io.ReadAll(response.Body)

388 if err != nil {

389 panic(err)

390 }

391 fmt.Println(string(contents))

392}

393```

394 

295```bash395```bash

296curl https://api.openai.com/v1/files/file-xyz123/content \396curl https://api.openai.com/v1/files/file-xyz123/content \

297 -H "Authorization: Bearer $OPENAI_API_KEY" > batch_output.jsonl397 -H "Authorization: Bearer $OPENAI_API_KEY" > batch_output.jsonl


345client.batches.cancel(batch_id)445client.batches.cancel(batch_id)

346```446```

347 447 

448```go

449package main

450 

451import (

452 "context"

453 "fmt"

454 

455 "github.com/openai/openai-go/v3"

456)

457 

458func main() {

459 client := openai.NewClient()

460 batch, err := client.Batches.Cancel(context.Background(), "batch_abc123")

461 if err != nil {

462 panic(err)

463 }

464 fmt.Println(batch.Status)

465}

466```

467 

348```bash468```bash

349curl https://api.openai.com/v1/batches/batch_abc123/cancel \469curl https://api.openai.com/v1/batches/batch_abc123/cancel \

350 -H "Authorization: Bearer $OPENAI_API_KEY" \470 -H "Authorization: Bearer $OPENAI_API_KEY" \


383client.batches.list(limit=10)503client.batches.list(limit=10)

384```504```

385 505 

506```go

507package main

508 

509import (

510 "context"

511 "fmt"

512 

513 "github.com/openai/openai-go/v3"

514)

515 

516func main() {

517 client := openai.NewClient()

518 list := client.Batches.ListAutoPaging(context.Background(), openai.BatchListParams{Limit: openai.Int(10)})

519 for list.Next() {

520 fmt.Println(list.Current().ID)

521 }

522 if err := list.Err(); err != nil {

523 panic(err)

524 }

525}

526```

527 

386```bash528```bash

387curl https://api.openai.com/v1/batches?limit=10 \529curl https://api.openai.com/v1/batches?limit=10 \

388 -H "Authorization: Bearer $OPENAI_API_KEY" \530 -H "Authorization: Bearer $OPENAI_API_KEY" \

Details

68print(result.output_text)68print(result.output_text)

69```69```

70 70 

71```go

72package main

73 

74import (

75 "context"

76 "fmt"

77 

78 "github.com/openai/openai-go/v3"

79 "github.com/openai/openai-go/v3/responses"

80 "github.com/openai/openai-go/v3/shared"

81)

82 

83func main() {

84 client := openai.NewClient()

85 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

86 Model: "gpt-5.6",

87 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String(`Find the null pointer exception in this code:

88 

89def display_name(user):

90 return user.profile.name

91 

92print(display_name(None))`)},

93 Reasoning: shared.ReasoningParam{Effort: shared.ReasoningEffortHigh},

94 })

95 if err != nil {

96 panic(err)

97 }

98 fmt.Println(response.OutputText())

99}

100```

101 

71```bash102```bash

72curl https://api.openai.com/v1/responses \103curl https://api.openai.com/v1/responses \

73 -H "Content-Type: application/json" \104 -H "Content-Type: application/json" \

Details

80 )80 )

81```81```

82 82 

83```go

84package main

85 

86import (

87 "bufio"

88 "context"

89 "encoding/json"

90 "fmt"

91 "os"

92 

93 "github.com/openai/openai-go/v3"

94 "github.com/openai/openai-go/v3/responses"

95)

96 

97func main() {

98 client := openai.NewClient()

99 conversation := []responses.ResponseInputItemUnionParam{

100 responses.ResponseInputItemParamOfMessage("Let's begin a long coding task.", responses.EasyInputMessageRoleUser),

101 }

102 scanner := bufio.NewScanner(os.Stdin)

103 for {

104 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

105 Model: "gpt-5.3-codex",

106 Store: openai.Bool(false),

107 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: conversation},

108 ContextManagement: []responses.ResponseNewParamsContextManagement{{

109 Type: "compaction", CompactThreshold: openai.Int(200000),

110 }},

111 })

112 if err != nil {

113 panic(err)

114 }

115 conversation = append(conversation, outputAsInput(response.Output)...)

116 fmt.Println(response.OutputText())

117 if !scanner.Scan() {

118 break

119 }

120 conversation = append(conversation,

121 responses.ResponseInputItemParamOfMessage(scanner.Text(), responses.EasyInputMessageRoleUser),

122 )

123 }

124 if err := scanner.Err(); err != nil {

125 panic(err)

126 }

127}

128 

129func outputAsInput(output []responses.ResponseOutputItemUnion) []responses.ResponseInputItemUnionParam {

130 input := make([]responses.ResponseInputItemUnionParam, 0, len(output))

131 for _, item := range output {

132 var converted responses.ResponseInputItemUnion

133 if err := json.Unmarshal([]byte(item.RawJSON()), &converted); err != nil {

134 panic(err)

135 }

136 input = append(input, converted.ToParam())

137 }

138 return input

139}

140```

141 

83 142 

84## Standalone compact endpoint143## Standalone compact endpoint

85 144 


144 store=False, # Keep the flow ZDR-friendly203 store=False, # Keep the flow ZDR-friendly

145)204)

146```205```

206 

207```go

208package main

209 

210import (

211 "bufio"

212 "context"

213 "encoding/json"

214 "fmt"

215 "os"

216 

217 "github.com/openai/openai-go/v3"

218 "github.com/openai/openai-go/v3/responses"

219)

220 

221func main() {

222 client := openai.NewClient()

223 longInputItems := []responses.ResponseInputItemUnionParam{

224 responses.ResponseInputItemParamOfMessage("Plan a trip to Kyoto.", responses.EasyInputMessageRoleUser),

225 }

226 compacted, err := client.Responses.Compact(context.Background(), responses.ResponseCompactParams{

227 Model: "gpt-5.6",

228 Input: responses.ResponseCompactParamsInputUnion{OfResponseInputItemArray: longInputItems},

229 })

230 if err != nil {

231 panic(err)

232 }

233 scanner := bufio.NewScanner(os.Stdin)

234 if !scanner.Scan() {

235 return

236 }

237 nextInput := append(outputAsInput(compacted.Output),

238 responses.ResponseInputItemParamOfMessage(scanner.Text(), responses.EasyInputMessageRoleUser),

239 )

240 nextResponse, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

241 Model: "gpt-5.6",

242 Store: openai.Bool(false),

243 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: nextInput},

244 })

245 if err != nil {

246 panic(err)

247 }

248 fmt.Println(nextResponse.OutputText())

249}

250 

251func outputAsInput(output []responses.ResponseOutputItemUnion) []responses.ResponseInputItemUnionParam {

252 input := make([]responses.ResponseInputItemUnionParam, 0, len(output))

253 for _, item := range output {

254 var converted responses.ResponseInputItemUnion

255 if err := json.Unmarshal([]byte(item.RawJSON()), &converted); err != nil {

256 panic(err)

257 }

258 input = append(input, converted.ToParam())

259 }

260 return input

261}

262```

Details

23)23)

24```24```

25 25 

26```go

27package main

28 

29import (

30 "context"

31 "fmt"

32 

33 "github.com/openai/openai-go/v3"

34)

35 

36func main() {

37 client := openai.NewClient()

38 response, err := client.Completions.New(context.Background(), openai.CompletionNewParams{

39 Model: "gpt-3.5-turbo-instruct",

40 Prompt: openai.CompletionNewParamsPromptUnion{OfString: openai.String("Write a tagline for an ice cream shop.")},

41 })

42 if err != nil {

43 panic(err)

44 }

45 fmt.Println(response.Choices[0].Text)

46}

47```

48 

26 49 

27See the full [API reference documentation](https://platform.openai.com/docs/api-reference/completions) to learn more.50See the full [API reference documentation](https://platform.openai.com/docs/api-reference/completions) to learn more.

28 51 

Details

53print(response.output_text)53print(response.output_text)

54```54```

55 55 

56```go

57package main

58 

59import (

60 "context"

61 "fmt"

62 

63 "github.com/openai/openai-go/v3"

64 "github.com/openai/openai-go/v3/responses"

65)

66 

67func main() {

68 client := openai.NewClient()

69 

70 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

71 Model: "gpt-5.6",

72 Input: responses.ResponseNewParamsInputUnion{

73 OfInputItemList: responses.ResponseInputParam{

74 responses.ResponseInputItemParamOfMessage("Knock knock.", responses.EasyInputMessageRoleUser),

75 responses.ResponseInputItemParamOfMessage("Who's there?", responses.EasyInputMessageRoleAssistant),

76 responses.ResponseInputItemParamOfMessage("Orange.", responses.EasyInputMessageRoleUser),

77 },

78 },

79 })

80 if err != nil {

81 panic(err)

82 }

83 

84 fmt.Println(response.OutputText())

85}

86```

87 

56 88 

57 89 

58By using alternating `user` and `assistant` messages, you capture the previous state of a conversation in one request to the model.90By using alternating `user` and `assistant` messages, you capture the previous state of a conversation in one request to the model.


135print(second_response.output_text)167print(second_response.output_text)

136```168```

137 169 

170```go

171package main

172 

173import (

174 "context"

175 "encoding/json"

176 "fmt"

177 

178 "github.com/openai/openai-go/v3"

179 "github.com/openai/openai-go/v3/responses"

180)

181 

182func main() {

183 client := openai.NewClient()

184 history := responses.ResponseInputParam{

185 responses.ResponseInputItemParamOfMessage("tell me a joke", responses.EasyInputMessageRoleUser),

186 }

187 first, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

188 Model: "gpt-5.6",

189 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: history},

190 Store: openai.Bool(false),

191 })

192 if err != nil {

193 panic(err)

194 }

195 fmt.Println(first.OutputText())

196 

197 history = append(history, outputAsInput(first.Output)...)

198 history = append(history, responses.ResponseInputItemParamOfMessage("tell me another", responses.EasyInputMessageRoleUser))

199 second, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

200 Model: "gpt-5.6",

201 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: history},

202 Store: openai.Bool(false),

203 })

204 if err != nil {

205 panic(err)

206 }

207 fmt.Println(second.OutputText())

208}

209 

210func outputAsInput(output []responses.ResponseOutputItemUnion) []responses.ResponseInputItemUnionParam {

211 input := make([]responses.ResponseInputItemUnionParam, 0, len(output))

212 for _, item := range output {

213 var converted responses.ResponseInputItemUnion

214 if err := json.Unmarshal([]byte(item.RawJSON()), &converted); err != nil {

215 panic(err)

216 }

217 input = append(input, converted.ToParam())

218 }

219 return input

220}

221```

222 

138 223 

139 224 

140## OpenAI APIs for conversation state225## OpenAI APIs for conversation state


157conversation = openai.conversations.create()242conversation = openai.conversations.create()

158```243```

159 244 

245```go

246conversation, err := client.Conversations.New(context.Background(), conversations.ConversationNewParams{})

247if err != nil {

248 panic(err)

249}

250```

251 

160 252 

161In a multi-turn interaction, you can pass the `conversation` into subsequent responses to persist state and share context across subsequent responses, rather than having to chain multiple response items together.253In a multi-turn interaction, you can pass the `conversation` into subsequent responses to persist state and share context across subsequent responses, rather than having to chain multiple response items together.

162 254 


170)262)

171```263```

172 264 

265```go

266response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

267 Model: "gpt-5.6",

268 Conversation: responses.ResponseNewParamsConversationUnion{

269 OfString: openai.String(conversation.ID),

270 },

271 Input: responses.ResponseNewParamsInputUnion{

272 OfString: openai.String("What are the five Ds of dodgeball?"),

273 },

274})

275if err != nil {

276 panic(err)

277}

278fmt.Println(response.OutputText())

279```

280 

173 281 

174### Passing context from the previous response282### Passing context from the previous response

175 283 


219print(second_response.output_text)327print(second_response.output_text)

220```328```

221 329 

330```go

331package main

332 

333import (

334 "context"

335 "fmt"

336 

337 "github.com/openai/openai-go/v3"

338 "github.com/openai/openai-go/v3/responses"

339)

340 

341func main() {

342 client := openai.NewClient()

343 

344 first, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

345 Model: "gpt-5.6",

346 Input: responses.ResponseNewParamsInputUnion{

347 OfString: openai.String("Tell me a joke."),

348 },

349 })

350 if err != nil {

351 panic(err)

352 }

353 fmt.Println(first.OutputText())

354 

355 second, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

356 Model: "gpt-5.6",

357 PreviousResponseID: openai.String(first.ID),

358 Input: responses.ResponseNewParamsInputUnion{

359 OfString: openai.String("Explain why this is funny."),

360 },

361 })

362 if err != nil {

363 panic(err)

364 }

365 fmt.Println(second.OutputText())

366}

367```

368 

222 369 

223In the following example, we ask the model to tell a joke. Separately, we ask the model to explain why it's funny, and the model has all necessary context to deliver a good response.370In the following example, we ask the model to tell a joke. Separately, we ask the model to explain why it's funny, and the model has all necessary context to deliver a good response.

224 371 


267print(second_response.output_text)414print(second_response.output_text)

268```415```

269 416 

417```go

418package main

419 

420import (

421 "context"

422 "fmt"

423 

424 "github.com/openai/openai-go/v3"

425 "github.com/openai/openai-go/v3/responses"

426)

427 

428func main() {

429 client := openai.NewClient()

430 

431 first, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

432 Model: "gpt-5.6",

433 Input: responses.ResponseNewParamsInputUnion{

434 OfString: openai.String("Tell me a joke."),

435 },

436 })

437 if err != nil {

438 panic(err)

439 }

440 fmt.Println(first.OutputText())

441 

442 second, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

443 Model: "gpt-5.6",

444 PreviousResponseID: openai.String(first.ID),

445 Input: responses.ResponseNewParamsInputUnion{

446 OfString: openai.String("Explain why this is funny."),

447 },

448 })

449 if err != nil {

450 panic(err)

451 }

452 fmt.Println(second.OutputText())

453}

454```

455 

270 456 

271#### `previous_response_id` in WebSocket mode457#### `previous_response_id` in WebSocket mode

272 458 

Details

90print(response.output_text)90print(response.output_text)

91```91```

92 92 

93```go

94package main

95 

96import (

97 "context"

98 "fmt"

99 

100 "github.com/openai/openai-go/v3"

101 "github.com/openai/openai-go/v3/responses"

102)

103 

104const researchInput = `

105Research the economic impact of semaglutide on global healthcare systems.

106Do:

107- Include specific figures, trends, statistics, and measurable outcomes.

108- Prioritize reliable, up-to-date sources: peer-reviewed research, health organizations (e.g., WHO, CDC), regulatory agencies, or pharmaceutical earnings reports.

109- Include inline citations and return all source metadata.

110 

111Be analytical, avoid generalities, and ensure that each section supports data-backed reasoning that could inform healthcare policy or financial modeling.

112`

113 

114func main() {

115 client := openai.NewClient()

116 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

117 Model: "o3-deep-research",

118 Background: openai.Bool(true),

119 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String(researchInput)},

120 Tools: []responses.ToolUnionParam{

121 responses.ToolParamOfWebSearchPreview(responses.WebSearchPreviewToolTypeWebSearchPreview),

122 responses.ToolParamOfFileSearch([]string{"vs_68870b8868b88191894165101435eef6", "vs_12345abcde6789fghijk101112131415"}),

123 responses.ToolParamOfCodeInterpreter(responses.ToolCodeInterpreterContainerCodeInterpreterContainerAutoParam{}),

124 },

125 })

126 if err != nil {

127 panic(err)

128 }

129 fmt.Println(response)

130}

131```

132 

93```bash133```bash

94curl https://api.openai.com/v1/responses \134curl https://api.openai.com/v1/responses \

95 -H "Authorization: Bearer $OPENAI_API_KEY" \135 -H "Authorization: Bearer $OPENAI_API_KEY" \


242print(response.output_text)282print(response.output_text)

243```283```

244 284 

285```go

286package main

287 

288import (

289 "context"

290 "fmt"

291 

292 "github.com/openai/openai-go/v3"

293 "github.com/openai/openai-go/v3/responses"

294)

295 

296const instructions = `

297You are talking to a user who is asking for a research task to be conducted. Your job is to gather more information from the user to successfully complete the task.

298 

299GUIDELINES:

300- Be concise while gathering all necessary information.

301- Make sure to gather all the information needed to carry out the research task in a concise, well-structured manner.

302- Use bullet points or numbered lists if appropriate for clarity.

303- Don't ask for unnecessary information, or information that the user has already provided.

304 

305IMPORTANT: Do NOT conduct any research yourself, just gather information that will be given to a researcher to conduct the research task.

306`

307 

308func main() {

309 client := openai.NewClient()

310 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

311 Model: "gpt-5.6",

312 Instructions: openai.String(instructions),

313 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Research surfboards for me. I'm interested in ...")},

314 })

315 if err != nil {

316 panic(err)

317 }

318 fmt.Println(response.OutputText())

319}

320```

321 

245```bash322```bash

246curl https://api.openai.com/v1/responses \323curl https://api.openai.com/v1/responses \

247-H "Authorization: Bearer $OPENAI_API_KEY" \324-H "Authorization: Bearer $OPENAI_API_KEY" \


419print(response.output_text)496print(response.output_text)

420```497```

421 498 

499```go

500package main

501 

502import (

503 "context"

504 "fmt"

505 

506 "github.com/openai/openai-go/v3"

507 "github.com/openai/openai-go/v3/responses"

508)

509 

510const instructions = `

511You will be given a research task by a user. Your job is to produce a set of

512instructions for a researcher that will complete the task. Do NOT complete the

513task yourself, just provide instructions on how to complete it.

514 

515GUIDELINES:

5161. **Maximize Specificity and Detail**

517- Include all known user preferences and explicitly list key attributes or

518 dimensions to consider.

519- It is of utmost importance that all details from the user are included in

520 the instructions.

521 

5222. **Fill in Unstated But Necessary Dimensions as Open-Ended**

523- If certain attributes are essential for a meaningful output but the user

524 has not provided them, explicitly state that they are open-ended or default

525 to no specific constraint.

526 

5273. **Avoid Unwarranted Assumptions**

528- If the user has not provided a particular detail, do not invent one.

529- Instead, state the lack of specification and guide the researcher to treat

530 it as flexible or accept all possible options.

531 

5324. **Use the First Person**

533- Phrase the request from the perspective of the user.

534 

5355. **Tables**

536- If you determine that including a table will help illustrate, organize, or

537 enhance the information in the research output, you must explicitly request

538 that the researcher provide them.

539 

540Examples:

541- Product Comparison (Consumer): When comparing different smartphone models,

542 request a table listing each model's features, price, and consumer ratings

543 side-by-side.

544- Project Tracking (Work): When outlining project deliverables, create a table

545 showing tasks, deadlines, responsible team members, and status updates.

546- Budget Planning (Consumer): When creating a personal or household budget,

547 request a table detailing income sources, monthly expenses, and savings goals.

548- Competitor Analysis (Work): When evaluating competitor products, request a

549 table with key metrics, such as market share, pricing, and main differentiators.

550 

5516. **Headers and Formatting**

552- You should include the expected output format in the prompt.

553- If the user is asking for content that would be best returned in a

554 structured format (e.g. a report, plan, etc.), ask the researcher to format

555 as a report with the appropriate headers and formatting that ensures clarity

556 and structure.

557 

5587. **Language**

559- If the user input is in a language other than English, tell the researcher

560 to respond in this language, unless the user query explicitly asks for the

561 response in a different language.

562 

5638. **Sources**

564- If specific sources should be prioritized, specify them in the prompt.

565- For product and travel research, prefer linking directly to official or

566 primary websites (e.g., official brand sites, manufacturer pages, or

567 reputable e-commerce platforms like Amazon for user reviews) rather than

568 aggregator sites or SEO-heavy blogs.

569- For academic or scientific queries, prefer linking directly to the original

570 paper or official journal publication rather than survey papers or secondary

571 summaries.

572- If the query is in a specific language, prioritize sources published in that

573 language.

574`

575 

576func main() {

577 client := openai.NewClient()

578 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

579 Model: "gpt-5.6",

580 Instructions: openai.String(instructions),

581 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Research surfboards for me. I'm interested in ...")},

582 })

583 if err != nil {

584 panic(err)

585 }

586 fmt.Println(response.OutputText())

587}

588```

589 

422```bash590```bash

423curl https://api.openai.com/v1/responses \591curl https://api.openai.com/v1/responses \

424 -H "Authorization: Bearer $OPENAI_API_KEY" \592 -H "Authorization: Bearer $OPENAI_API_KEY" \


541print(resp.output_text)709print(resp.output_text)

542```710```

543 711 

712```go

713package main

714 

715import (

716 "context"

717 "fmt"

718 

719 "github.com/openai/openai-go/v3"

720 "github.com/openai/openai-go/v3/responses"

721 "github.com/openai/openai-go/v3/shared"

722)

723 

724func main() {

725 client := openai.NewClient()

726 tool := responses.ToolParamOfMcp("mycompany_mcp_server")

727 tool.OfMcp.ServerURL = openai.String("https://mycompany.com/mcp")

728 tool.OfMcp.RequireApproval = responses.ToolMcpRequireApprovalUnionParam{OfMcpToolApprovalSetting: openai.String("never")}

729 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

730 Model: "o3-deep-research",

731 Background: openai.Bool(true),

732 Reasoning: shared.ReasoningParam{Summary: shared.ReasoningSummaryAuto},

733 Tools: []responses.ToolUnionParam{tool},

734 Instructions: openai.String("<deep research instructions...>"),

735 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("What similarities are in the notes for our closed/lost Salesforce opportunities?")},

736 })

737 if err != nil {

738 panic(err)

739 }

740 fmt.Println(response.OutputText())

741}

742```

743 

544 744 

545[Build a deep research compatible remote MCP server745[Build a deep research compatible remote MCP server

546 746 

Details

113print(response.output_text)113print(response.output_text)

114```114```

115 115 

116```go

117package main

118 

119import (

120 "context"

121 "fmt"

122 "strings"

123 

124 "github.com/openai/openai-go/v3"

125 "github.com/openai/openai-go/v3/responses"

126 "github.com/openai/openai-go/v3/shared"

127)

128 

129func main() {

130 client := openai.NewClient()

131 prompt := strings.Join([]string{

132 "Our CI job started failing after a dependency bump.",

133 "",

134 "Error:",

135 "TypeError: Timeout.__init__() got an unexpected keyword argument 'connect'",

136 "",

137 "Identify the likeliest root cause and the smallest safe fix.",

138 }, "\n")

139 reasoning := shared.ReasoningParam{Effort: shared.ReasoningEffortXhigh}

140 reasoning.SetExtraFields(map[string]any{"mode": "pro"})

141 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

142 Model: "gpt-5.6",

143 Reasoning: reasoning,

144 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String(prompt)},

145 })

146 if err != nil {

147 panic(err)

148 }

149 fmt.Println(response.OutputText())

150}

151```

152 

116 153 

117## Set up `text.verbosity`154## Set up `text.verbosity`

118 155 


175print(response.output_text)212print(response.output_text)

176```213```

177 214 

215```go

216package main

217 

218import (

219 "context"

220 "fmt"

221 "strings"

222 

223 "github.com/openai/openai-go/v3"

224 "github.com/openai/openai-go/v3/responses"

225)

226 

227func main() {

228 client := openai.NewClient()

229 incident := strings.Join([]string{

230 "Summarize this incident for the next on-call engineer.",

231 "- checkout latency spiked from 220 ms to 4.8 s",

232 "- only us-east-1 was affected",

233 "- rollback is complete",

234 "- likely trigger: cache stampede after deploy",

235 }, "\n")

236 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

237 Model: "gpt-5.6",

238 Text: responses.ResponseTextConfigParam{Verbosity: "low"},

239 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String(incident)},

240 })

241 if err != nil {

242 panic(err)

243 }

244 fmt.Println(response.OutputText())

245}

246```

247 

178 248 

179## Set up the assistant `phase` parameter249## Set up the assistant `phase` parameter

180 250 


379print(response.output)449print(response.output)

380```450```

381 451 

452```go

453package main

454 

455import (

456 "context"

457 "fmt"

458 

459 "github.com/openai/openai-go/v3"

460 "github.com/openai/openai-go/v3/responses"

461)

462 

463func main() {

464 client := openai.NewClient()

465 billing := namespaceTool(

466 "billing",

467 "Billing tools for invoices, payments, taxes, and credits.",

468 "lookup_invoice",

469 "Look up invoice state, taxes, credits, and payment attempts.",

470 "invoice_id",

471 )

472 crm := namespaceTool(

473 "crm",

474 "CRM tools for account ownership, plans, health, and payment history.",

475 "get_account",

476 "Fetch account owner, plan, health, and payment history.",

477 "account_id",

478 )

479 toolSearch := responses.ToolUnionParam{OfToolSearch: &responses.ToolSearchToolParam{}}

480 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

481 Model: "gpt-5.6",

482 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String(

483 "Find the right billing tool and explain why invoice INV-1043 still shows overdue after a payment yesterday.",

484 )},

485 Tools: []responses.ToolUnionParam{billing, crm, toolSearch},

486 })

487 if err != nil {

488 panic(err)

489 }

490 fmt.Println(response.Output)

491}

492 

493func namespaceTool(namespace, namespaceDescription, name, description, argument string) responses.ToolUnionParam {

494 parameters := map[string]any{

495 "type": "object",

496 "properties": map[string]any{

497 argument: map[string]any{"type": "string"},

498 },

499 "required": []string{argument},

500 "additionalProperties": false,

501 }

502 function := responses.NamespaceToolToolFunctionParam{

503 Name: name, Description: openai.String(description), Parameters: parameters, Strict: openai.Bool(true), DeferLoading: openai.Bool(true),

504 }

505 return responses.ToolParamOfNamespace(

506 namespaceDescription,

507 namespace,

508 []responses.NamespaceToolToolUnionParam{{OfFunction: &function}},

509 )

510}

511```

512 

382 513 

383## Use Programmatic Tool Calling514## Use Programmatic Tool Calling

384 515 


555print(next_response.output_text)686print(next_response.output_text)

556```687```

557 688 

689```go

690package main

691 

692import (

693 "context"

694 "encoding/json"

695 "fmt"

696 

697 "github.com/openai/openai-go/v3"

698 "github.com/openai/openai-go/v3/responses"

699)

700 

701func main() {

702 client := openai.NewClient()

703 longWindow := []responses.ResponseInputItemUnionParam{

704 responses.ResponseInputItemParamOfMessage("Find the cache invalidation bug in this debugging session.", responses.EasyInputMessageRoleUser),

705 }

706 compacted, err := client.Responses.Compact(context.Background(), responses.ResponseCompactParams{

707 Model: "gpt-5.6",

708 Input: responses.ResponseCompactParamsInputUnion{OfResponseInputItemArray: longWindow},

709 })

710 if err != nil {

711 panic(err)

712 }

713 input := append(outputAsInput(compacted.Output),

714 responses.ResponseInputItemParamOfMessage(

715 "We found the bad cache invalidation path. Write the fix plan and the verification checklist.",

716 responses.EasyInputMessageRoleUser,

717 ),

718 )

719 nextResponse, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

720 Model: "gpt-5.6",

721 Store: openai.Bool(false),

722 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: input},

723 })

724 if err != nil {

725 panic(err)

726 }

727 fmt.Println(nextResponse.OutputText())

728}

729 

730func outputAsInput(output []responses.ResponseOutputItemUnion) []responses.ResponseInputItemUnionParam {

731 input := make([]responses.ResponseInputItemUnionParam, 0, len(output))

732 for _, item := range output {

733 var converted responses.ResponseInputItemUnion

734 if err := json.Unmarshal([]byte(item.RawJSON()), &converted); err != nil {

735 panic(err)

736 }

737 input = append(input, converted.ToParam())

738 }

739 return input

740}

741```

742 

558 743 

559## Use `prompt_cache_key`744## Use `prompt_cache_key`

560 745 


629print(response.output_text)814print(response.output_text)

630```815```

631 816 

817```go

818package main

819 

820import (

821 "context"

822 "fmt"

823 "strings"

824 

825 "github.com/openai/openai-go/v3"

826 "github.com/openai/openai-go/v3/responses"

827)

828 

829func main() {

830 client := openai.NewClient()

831 instructions := strings.Join([]string{

832 "You are the support agent for Acme.",

833 "Follow the Acme support policy and escalation rubric.",

834 "Use the same tone, safety rules, and tool plan for each ticket.",

835 }, "\n")

836 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

837 Model: "gpt-5.6",

838 PromptCacheKey: openai.String("tenant-acme-support-agent"),

839 Instructions: openai.String(instructions),

840 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Summarize the current escalation for the on-call lead.")},

841 })

842 if err != nil {

843 panic(err)

844 }

845 fmt.Println(response.OutputText())

846}

847```

848 

632 849 

633## Use `reasoning.encrypted_content`850## Use `reasoning.encrypted_content`

634 851 


728print(second.output_text)945print(second.output_text)

729```946```

730 947 

948```go

949package main

950 

951import (

952 "context"

953 "encoding/json"

954 "fmt"

955 

956 "github.com/openai/openai-go/v3"

957 "github.com/openai/openai-go/v3/responses"

958 "github.com/openai/openai-go/v3/shared"

959)

960 

961func main() {

962 client := openai.NewClient()

963 history := []responses.ResponseInputItemUnionParam{

964 responses.ResponseInputItemParamOfMessage("Investigate why invoice INV-1043 has mismatched tax totals.", responses.EasyInputMessageRoleUser),

965 }

966 first, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

967 Model: "gpt-5.6",

968 Store: openai.Bool(false),

969 Reasoning: shared.ReasoningParam{Effort: shared.ReasoningEffortMedium, Context: shared.ReasoningContextCurrentTurn},

970 Include: []responses.ResponseIncludable{responses.ResponseIncludableReasoningEncryptedContent},

971 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: history},

972 })

973 if err != nil {

974 panic(err)

975 }

976 history = append(history, outputAsInput(first.Output)...)

977 history = append(history, responses.ResponseInputItemParamOfMessage(

978 "Now write the customer-facing explanation in plain English.",

979 responses.EasyInputMessageRoleUser,

980 ))

981 second, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

982 Model: "gpt-5.6",

983 Store: openai.Bool(false),

984 Reasoning: shared.ReasoningParam{Effort: shared.ReasoningEffortMedium, Context: shared.ReasoningContextAllTurns},

985 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: history},

986 })

987 if err != nil {

988 panic(err)

989 }

990 fmt.Println(second.OutputText())

991}

992 

993func outputAsInput(output []responses.ResponseOutputItemUnion) []responses.ResponseInputItemUnionParam {

994 input := make([]responses.ResponseInputItemUnionParam, 0, len(output))

995 for _, item := range output {

996 var converted responses.ResponseInputItemUnion

997 if err := json.Unmarshal([]byte(item.RawJSON()), &converted); err != nil {

998 panic(err)

999 }

1000 input = append(input, converted.ToParam())

1001 }

1002 return input

1003}

1004```

1005 

731 1006 

732## Set image detail intentionally1007## Set image detail intentionally

733 1008 


823print(job.output_text)1098print(job.output_text)

824```1099```

825 1100 

1101```go

1102package main

1103 

1104import (

1105 "context"

1106 "fmt"

1107 "time"

1108 

1109 "github.com/openai/openai-go/v3"

1110 "github.com/openai/openai-go/v3/responses"

1111)

1112 

1113func main() {

1114 client := openai.NewClient()

1115 tool := responses.ToolParamOfCodeInterpreter(responses.ToolCodeInterpreterContainerCodeInterpreterContainerAutoParam{

1116 FileIDs: []string{"file_abc123"},

1117 })

1118 job, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

1119 Model: "gpt-5.6",

1120 Background: openai.Bool(true),

1121 Store: openai.Bool(false),

1122 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Analyze this large log bundle and cluster the primary failure modes.")},

1123 Tools: []responses.ToolUnionParam{tool},

1124 })

1125 if err != nil {

1126 panic(err)

1127 }

1128 for job.Status == responses.ResponseStatusQueued || job.Status == responses.ResponseStatusInProgress {

1129 time.Sleep(2 * time.Second)

1130 job, err = client.Responses.Get(context.Background(), job.ID, responses.ResponseGetParams{})

1131 if err != nil {

1132 panic(err)

1133 }

1134 }

1135 fmt.Println(job.OutputText())

1136}

1137```

1138 

826 1139 

827You can combine it with `stream=True` for progress events, but the first event1140You can combine it with `stream=True` for progress events, but the first event

828may take longer than a normal request.1141may take longer than a normal request.

Details

131)131)

132```132```

133 133 

134```go

135package main

136 

137import (

138 "context"

139 "fmt"

140 

141 "github.com/openai/openai-go/v3"

142)

143 

144func main() {

145 client := openai.NewClient()

146 job, err := client.FineTuning.Jobs.New(context.Background(), openai.FineTuningJobNewParams{

147 TrainingFile: "file-all-about-the-weather",

148 Model: "gpt-4o-2024-08-06",

149 Method: openai.FineTuningJobNewParamsMethod{

150 Type: "dpo",

151 Dpo: openai.DpoMethodParam{Hyperparameters: openai.DpoHyperparameters{

152 Beta: openai.DpoHyperparametersBetaUnion{OfFloat: openai.Float(0.1)},

153 }},

154 },

155 })

156 if err != nil {

157 panic(err)

158 }

159 fmt.Println(job.ID)

160}

161```

162 

134 163 

135## Use SFT and DPO together164## Use SFT and DPO together

136 165 

Details

48print(response.data[0].embedding)48print(response.data[0].embedding)

49```49```

50 50 

51```go

52package main

53 

54import (

55 "context"

56 "fmt"

57 

58 "github.com/openai/openai-go/v3"

59)

60 

61func main() {

62 client := openai.NewClient()

63 

64 embedding, err := client.Embeddings.New(context.Background(), openai.EmbeddingNewParams{

65 Model: openai.EmbeddingModelTextEmbedding3Small,

66 Input: openai.EmbeddingNewParamsInputUnion{

67 OfString: openai.String("Your text string goes here."),

68 },

69 })

70 if err != nil {

71 panic(err)

72 }

73 

74 fmt.Println(len(embedding.Data[0].Embedding))

75}

76```

77 

51```bash78```bash

52curl https://api.openai.com/v1/embeddings \79curl https://api.openai.com/v1/embeddings \

53 -H "Content-Type: application/json" \80 -H "Content-Type: application/json" \

Details

259else:259else:

260 print(response.output_text)260 print(response.output_text)

261```261```

262 

263```go

264package main

265 

266import (

267 "context"

268 "errors"

269 "fmt"

270 

271 "github.com/openai/openai-go/v3"

272 "github.com/openai/openai-go/v3/responses"

273)

274 

275func main() {

276 client := openai.NewClient()

277 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

278 Model: "gpt-5.6",

279 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Hello world")},

280 })

281 if err != nil {

282 var apiError *openai.Error

283 if errors.As(err, &apiError) {

284 fmt.Println("OpenAI API returned an API error:", apiError)

285 return

286 }

287 fmt.Println("Failed to connect to OpenAI API:", err)

288 return

289 }

290 fmt.Println(response.OutputText())

291}

292```

guides/evals.md +57 −0

Details

81print(response.output_text)81print(response.output_text)

82```82```

83 83 

84```go

85package main

86 

87import (

88 "context"

89 "fmt"

90 

91 "github.com/openai/openai-go/v3"

92 "github.com/openai/openai-go/v3/responses"

93)

94 

95func main() {

96 client := openai.NewClient()

97 instructions := "You are an expert in categorizing IT support tickets. Given the support ticket below, categorize the request into one of \"Hardware\", \"Software\", or \"Other\". Respond with only one of those words."

98 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

99 Model: "gpt-5.6",

100 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: responses.ResponseInputParam{

101 responses.ResponseInputItemParamOfMessage(instructions, responses.EasyInputMessageRoleDeveloper),

102 responses.ResponseInputItemParamOfMessage("My monitor won't turn on - help!", responses.EasyInputMessageRoleUser),

103 }},

104 })

105 if err != nil {

106 panic(err)

107 }

108 fmt.Println(response.OutputText())

109}

110```

111 

84```bash112```bash

85curl https://api.openai.com/v1/responses \113curl https://api.openai.com/v1/responses \

86 -H "Authorization: Bearer $OPENAI_API_KEY" \114 -H "Authorization: Bearer $OPENAI_API_KEY" \


322print(file)350print(file)

323```351```

324 352 

353```go

354package main

355 

356import (

357 "context"

358 "fmt"

359 "os"

360 

361 "github.com/openai/openai-go/v3"

362)

363 

364func main() {

365 client := openai.NewClient()

366 file, err := os.Open("tickets.jsonl")

367 if err != nil {

368 panic(err)

369 }

370 defer file.Close()

371 uploaded, err := client.Files.New(context.Background(), openai.FileNewParams{

372 File: file,

373 Purpose: openai.FilePurposeEvals,

374 })

375 if err != nil {

376 panic(err)

377 }

378 fmt.Println(uploaded.ID)

379}

380```

381 

325```bash382```bash

326curl https://api.openai.com/v1/files \383curl https://api.openai.com/v1/files \

327 -H "Authorization: Bearer $OPENAI_API_KEY" \384 -H "Authorization: Bearer $OPENAI_API_KEY" \

Details

44print(response)44print(response)

45```45```

46 46 

47```go

48package main

49 

50import (

51 "context"

52 "fmt"

53 

54 "github.com/openai/openai-go/v3"

55 "github.com/openai/openai-go/v3/responses"

56)

57 

58func main() {

59 client := openai.NewClient()

60 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

61 Model: "gpt-5.6-sol",

62 ServiceTier: "fast",

63 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("What does 'fit check for my napalm era' mean?")},

64 })

65 if err != nil {

66 panic(err)

67 }

68 fmt.Println(response.OutputText())

69}

70```

71 

47```bash72```bash

48curl https://api.openai.com/v1/responses \73curl https://api.openai.com/v1/responses \

49 -H "Authorization: Bearer $OPENAI_API_KEY" \74 -H "Authorization: Bearer $OPENAI_API_KEY" \


82- Cached input discounts still apply to Fast mode requests.107- Cached input discounts still apply to Fast mode requests.

83- Fast mode supports multimodal requests, including image inputs.108- Fast mode supports multimodal requests, including image inputs.

84- To view Fast mode requests in the usage dashboard, select the option to group by service tier. For GPT-5.6 and earlier models, these requests appear as `priority` even when you specify `fast`.109- To view Fast mode requests in the usage dashboard, select the option to group by service tier. For GPT-5.6 and earlier models, these requests appear as `priority` even when you specify `fast`.

85- Long context, fine-tuned models, and embeddings are not supported.110- GPT-5.6 models support long context. Fast mode doesn't support fine-tuned models or embeddings.

86 111 

87## Frequently asked questions112## Frequently asked questions

88 113 


104 129 

105### Which models and modalities support Fast mode?130### Which models and modalities support Fast mode?

106 131 

107Fast mode supports the multimodal capabilities available with Standard processing, including image inputs. Long context, fine-tuned models, and embeddings aren't supported. Future GPT models may support Fast mode, but support isn't guaranteed for every model.132Fast mode supports the multimodal capabilities available with Standard processing, including image inputs. GPT-5.6 models support long context. Fast mode doesn't support fine-tuned models or embeddings. Future GPT models may support Fast mode, but support isn't guaranteed for every model.

108 133 

109### Are ramp rate limits shared across projects or organizations?134### Are ramp rate limits shared across projects or organizations?

110 135 

Details

89)89)

90```90```

91 91 

92```go

93package main

94 

95import (

96 "context"

97 "fmt"

98 

99 "github.com/openai/openai-go/v3"

100)

101 

102func main() {

103 client := openai.NewClient()

104 job, err := client.FineTuning.Jobs.New(context.Background(), openai.FineTuningJobNewParams{

105 TrainingFile: "file-abc123",

106 Model: "gpt-4o-mini-2024-07-18",

107 Method: openai.FineTuningJobNewParamsMethod{

108 Type: "supervised",

109 Supervised: openai.SupervisedMethodParam{Hyperparameters: openai.SupervisedHyperparameters{

110 NEpochs: openai.SupervisedHyperparametersNEpochsUnion{OfInt: openai.Int(2)},

111 }},

112 },

113 })

114 if err != nil {

115 panic(err)

116 }

117 fmt.Println(job.ID)

118}

119```

120 

92 121 

93## Adjust your dataset122## Adjust your dataset

94 123 

Details

54print(response.output_text)54print(response.output_text)

55```55```

56 56 

57```go

58package main

59 

60import (

61 "context"

62 "fmt"

63 "time"

64 

65 "github.com/openai/openai-go/v3"

66 "github.com/openai/openai-go/v3/option"

67 "github.com/openai/openai-go/v3/responses"

68)

69 

70func main() {

71 client := openai.NewClient(option.WithRequestTimeout(15 * time.Minute))

72 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

73 Model: "gpt-5.6",

74 Instructions: openai.String("List and describe all the metaphors used in this book."),

75 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("<very long text of book here>")},

76 ServiceTier: responses.ResponseNewParamsServiceTierFlex,

77 })

78 if err != nil {

79 panic(err)

80 }

81 fmt.Println(response.OutputText())

82}

83```

84 

57```bash85```bash

58curl https://api.openai.com/v1/responses \86curl https://api.openai.com/v1/responses \

59 -H "Authorization: Bearer $OPENAI_API_KEY" \87 -H "Authorization: Bearer $OPENAI_API_KEY" \

Details

227print("\n" + response.output_text)227print("\n" + response.output_text)

228```228```

229 229 

230```go

231package main

232 

233import (

234 "context"

235 "encoding/json"

236 "fmt"

237 

238 "github.com/openai/openai-go/v3"

239 "github.com/openai/openai-go/v3/responses"

240)

241 

242func main() {

243 client := openai.NewClient()

244 tool := horoscopeResponseTool()

245 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

246 Model: "gpt-5.6",

247 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("What is my horoscope? I am an Aquarius.")},

248 Tools: []responses.ToolUnionParam{tool},

249 })

250 if err != nil {

251 panic(err)

252 }

253 

254 var functionOutput responses.ResponseInputItemUnionParam

255 for _, output := range response.Output {

256 if output.Type != "function_call" {

257 continue

258 }

259 call := output.AsFunctionCall()

260 if call.Name != "get_horoscope" {

261 continue

262 }

263 var arguments struct {

264 Sign string `json:"sign"`

265 }

266 if err := json.Unmarshal([]byte(call.Arguments), &arguments); err != nil {

267 panic(err)

268 }

269 functionOutput = responses.ResponseInputItemParamOfFunctionCallOutput(call.CallID, getHoroscope(arguments.Sign))

270 }

271 if functionOutput.OfFunctionCallOutput == nil {

272 panic("the model did not call get_horoscope")

273 }

274 

275 response, err = client.Responses.New(context.Background(), responses.ResponseNewParams{

276 Model: "gpt-5.6",

277 PreviousResponseID: openai.String(response.ID),

278 Instructions: openai.String("Respond only with a horoscope generated by a tool."),

279 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: responses.ResponseInputParam{functionOutput}},

280 Tools: []responses.ToolUnionParam{tool},

281 })

282 if err != nil {

283 panic(err)

284 }

285 fmt.Println(response.OutputText())

286}

287 

288func horoscopeResponseTool() responses.ToolUnionParam {

289 parameters := map[string]any{

290 "type": "object",

291 "properties": map[string]any{

292 "sign": map[string]any{"type": "string", "description": "An astrological sign like Taurus or Aquarius"},

293 },

294 "required": []string{"sign"},

295 "additionalProperties": false,

296 }

297 tool := responses.ToolParamOfFunction("get_horoscope", parameters, true)

298 tool.OfFunction.Description = openai.String("Get today's horoscope for an astrological sign.")

299 return tool

300}

301 

302func getHoroscope(sign string) string {

303 return fmt.Sprintf("%s: Next Tuesday you will befriend a baby otter.", sign)

304}

305```

306 

230 307 

231 308 

232Note that for reasoning models like GPT-5 or o4-mini, any reasoning items309Note that for reasoning models like GPT-5 or o4-mini, any reasoning items


434 )511 )

435```512```

436 513 

514```go

515input = append(input, responseOutputAsInput(response.Output)...)

516 

517for _, output := range response.Output {

518 if output.Type != "function_call" {

519 continue

520 }

521 toolCall := output.AsFunctionCall()

522 var arguments functionArguments

523 if err := json.Unmarshal([]byte(toolCall.Arguments), &arguments); err != nil {

524 panic(err)

525 }

526 result, err := callFunction(toolCall.Name, arguments)

527 if err != nil {

528 panic(err)

529 }

530 input = append(input, responses.ResponseInputItemParamOfFunctionCallOutput(toolCall.CallID, result))

531}

532```

533 

437 534 

438 535 

439In the example above, we have a hypothetical `call_function` to route each call. Here’s a possible implementation:536In the example above, we have a hypothetical `call_function` to route each call. Here’s a possible implementation:


460 raise ValueError(f"Unknown function: {name}")557 raise ValueError(f"Unknown function: {name}")

461```558```

462 559 

560```go

561func callFunction(name string, arguments functionArguments) (string, error) {

562 switch name {

563 case "get_weather":

564 return getWeather(arguments.Location), nil

565 case "send_email":

566 return sendEmail(arguments.To, arguments.Body), nil

567 default:

568 return "", fmt.Errorf("unknown function: %s", name)

569 }

570}

571```

572 

463 573 

464### Formatting results574### Formatting results

465 575 


495print(response.output_text)605print(response.output_text)

496```606```

497 607 

608```go

609response, err = client.Responses.New(context.Background(), responses.ResponseNewParams{

610 Model: "gpt-5.6",

611 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: input},

612 Tools: tools,

613})

614if err != nil {

615 panic(err)

616}

617```

618 

498 619 

499 620 

500Final response621Final response


741 print(event)862 print(event)

742```863```

743 864 

865```go

866package main

867 

868import (

869 "context"

870 "fmt"

871 

872 "github.com/openai/openai-go/v3"

873 "github.com/openai/openai-go/v3/responses"

874)

875 

876func main() {

877 client := openai.NewClient()

878 parameters := map[string]any{

879 "type": "object",

880 "properties": map[string]any{

881 "location": map[string]any{"type": "string", "description": "City and country e.g. Bogotá, Colombia"},

882 },

883 "required": []string{"location"},

884 "additionalProperties": false,

885 }

886 tool := responses.ToolParamOfFunction("get_weather", parameters, true)

887 stream := client.Responses.NewStreaming(context.Background(), responses.ResponseNewParams{

888 Model: "gpt-5.6",

889 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("What's the weather like in Paris today?")},

890 Tools: []responses.ToolUnionParam{tool},

891 })

892 for stream.Next() {

893 fmt.Println(stream.Current().Type)

894 }

895 if err := stream.Err(); err != nil {

896 panic(err)

897 }

898}

899```

900 

744 901 

745Output events902Output events

746 903 


810 final_tool_calls[index].arguments += event.delta967 final_tool_calls[index].arguments += event.delta

811```968```

812 969 

970```go

971package main

972 

973import (

974 "context"

975 "fmt"

976 

977 "github.com/openai/openai-go/v3"

978 "github.com/openai/openai-go/v3/responses"

979)

980 

981func main() {

982 client := openai.NewClient()

983 parameters := map[string]any{

984 "type": "object",

985 "properties": map[string]any{

986 "location": map[string]any{"type": "string"},

987 },

988 "required": []string{"location"},

989 "additionalProperties": false,

990 }

991 tool := responses.ToolParamOfFunction("get_weather", parameters, true)

992 stream := client.Responses.NewStreaming(context.Background(), responses.ResponseNewParams{

993 Model: "gpt-5.6",

994 Input: responses.ResponseNewParamsInputUnion{

995 OfString: openai.String("What's the weather like in Paris today?"),

996 },

997 Tools: []responses.ToolUnionParam{tool},

998 })

999 

1000 finalToolCalls := map[int64]responses.ResponseFunctionToolCall{}

1001 for stream.Next() {

1002 event := stream.Current()

1003 if event.Type == "response.output_item.added" && event.Item.Type == "function_call" {

1004 finalToolCalls[event.OutputIndex] = event.Item.AsFunctionCall()

1005 }

1006 if event.Type == "response.function_call_arguments.delta" {

1007 finalToolCall, ok := finalToolCalls[event.OutputIndex]

1008 if !ok {

1009 continue

1010 }

1011 finalToolCall.Arguments += event.Delta

1012 finalToolCalls[event.OutputIndex] = finalToolCall

1013 }

1014 }

1015 if err := stream.Err(); err != nil {

1016 panic(err)

1017 }

1018 fmt.Println(finalToolCalls)

1019}

1020```

1021 

813 1022 

814Accumulated final_tool_calls[0]1023Accumulated final_tool_calls[0]

815 1024 


880print(response.output)1089print(response.output)

881```1090```

882 1091 

1092```go

1093package main

1094 

1095import (

1096 "context"

1097 "fmt"

1098 

1099 "github.com/openai/openai-go/v3"

1100 "github.com/openai/openai-go/v3/responses"

1101)

1102 

1103func main() {

1104 client := openai.NewClient()

1105 tool := responses.ToolParamOfCustom("code_exec")

1106 tool.OfCustom.Description = openai.String("Executes arbitrary Python code.")

1107 

1108 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

1109 Model: "gpt-5.6",

1110 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Use the code_exec tool to print hello world to the console.")},

1111 Tools: []responses.ToolUnionParam{tool},

1112 })

1113 if err != nil {

1114 panic(err)

1115 }

1116 fmt.Println(response.Output)

1117}

1118```

1119 

883 1120 

884Just as before, the `output` array will contain a tool call generated by the model. Except this time, the tool call input is given as plain text.1121Just as before, the `output` array will contain a tool call generated by the model. Except this time, the tool call input is given as plain text.

885 1122 


986print(response.output)1223print(response.output)

987```1224```

988 1225 

1226```go

1227package main

1228 

1229import (

1230 "context"

1231 "fmt"

1232 

1233 "github.com/openai/openai-go/v3"

1234 "github.com/openai/openai-go/v3/responses"

1235 "github.com/openai/openai-go/v3/shared"

1236)

1237 

1238func main() {

1239 client := openai.NewClient()

1240 grammar := `start: expr

1241expr: term (SP ADD SP term)* -> add

1242| term

1243term: factor (SP MUL SP factor)* -> mul

1244| factor

1245factor: INT

1246SP: " "

1247ADD: "+"

1248MUL: "*"

1249%import common.INT`

1250 tool := responses.ToolParamOfCustom("math_exp")

1251 tool.OfCustom.Description = openai.String("Creates valid mathematical expressions")

1252 tool.OfCustom.Format = shared.CustomToolInputFormatParamOfGrammar(grammar, "lark")

1253 

1254 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

1255 Model: "gpt-5.6",

1256 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Use the math_exp tool to add four plus four.")},

1257 Tools: []responses.ToolUnionParam{tool},

1258 })

1259 if err != nil {

1260 panic(err)

1261 }

1262 fmt.Println(response.Output)

1263}

1264```

1265 

989 1266 

990The output from the tool should then conform to the Lark CFG that you defined:1267The output from the tool should then conform to the Lark CFG that you defined:

991 1268 


1151print(response.output)1428print(response.output)

1152```1429```

1153 1430 

1431```go

1432package main

1433 

1434import (

1435 "context"

1436 "fmt"

1437 

1438 "github.com/openai/openai-go/v3"

1439 "github.com/openai/openai-go/v3/responses"

1440 "github.com/openai/openai-go/v3/shared"

1441)

1442 

1443func main() {

1444 client := openai.NewClient()

1445 grammar := `^(?P<month>January|February|March|April|May|June|July|August|September|October|November|December)\s+(?P<day>\d{1,2})(?:st|nd|rd|th)?\s+(?P<year>\d{4})\s+at\s+(?P<hour>0?[1-9]|1[0-2])(?P<ampm>AM|PM)$`

1446 tool := responses.ToolParamOfCustom("timestamp")

1447 tool.OfCustom.Description = openai.String("Saves a timestamp in date and time format.")

1448 tool.OfCustom.Format = shared.CustomToolInputFormatParamOfGrammar(grammar, "regex")

1449 

1450 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

1451 Model: "gpt-5.6",

1452 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Use the timestamp tool to save a timestamp for August 7th 2025 at 10AM.")},

1453 Tools: []responses.ToolUnionParam{tool},

1454 })

1455 if err != nil {

1456 panic(err)

1457 }

1458 fmt.Println(response.Output)

1459}

1460```

1461 

1154 1462 

1155The output from the tool should then conform to the Regex CFG that you defined:1463The output from the tool should then conform to the Regex CFG that you defined:

1156 1464 

Details

110 f.write(image_bytes)110 f.write(image_bytes)

111```111```

112 112 

113```go

114package main

115 

116import (

117 "context"

118 "encoding/base64"

119 "os"

120 

121 "github.com/openai/openai-go/v3"

122)

123 

124func main() {

125 client := openai.NewClient()

126 result, err := client.Images.Generate(context.Background(), openai.ImageGenerateParams{

127 Model: openai.ImageModel("gpt-image-2"),

128 Prompt: "A children's book drawing of a veterinarian using a stethoscope to " +

129 "listen to the heartbeat of a baby otter.",

130 })

131 if err != nil {

132 panic(err)

133 }

134 image, err := base64.StdEncoding.DecodeString(result.Data[0].B64JSON)

135 if err != nil {

136 panic(err)

137 }

138 if err := os.WriteFile("otter.png", image, 0o600); err != nil {

139 panic(err)

140 }

141}

142```

143 

113```bash144```bash

114curl -X POST "https://api.openai.com/v1/images/generations" \145curl -X POST "https://api.openai.com/v1/images/generations" \

115 -H "Authorization: Bearer $OPENAI_API_KEY" \146 -H "Authorization: Bearer $OPENAI_API_KEY" \


185 f.write(base64.b64decode(image_base64))216 f.write(base64.b64decode(image_base64))

186```217```

187 218 

219```go

220package main

221 

222import (

223 "context"

224 "encoding/base64"

225 "os"

226 

227 "github.com/openai/openai-go/v3"

228 "github.com/openai/openai-go/v3/responses"

229)

230 

231func main() {

232 client := openai.NewClient()

233 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

234 Model: "gpt-5.6",

235 Input: responses.ResponseNewParamsInputUnion{

236 OfString: openai.String("Generate an image of gray tabby cat hugging an otter with an orange scarf"),

237 },

238 Tools: []responses.ToolUnionParam{{OfImageGeneration: &responses.ToolImageGenerationParam{}}},

239 })

240 if err != nil {

241 panic(err)

242 }

243 saveFirstGeneratedImage(response, "otter.png")

244}

245 

246func saveFirstGeneratedImage(response *responses.Response, filename string) {

247 for _, output := range response.Output {

248 if output.Type != "image_generation_call" {

249 continue

250 }

251 image, err := base64.StdEncoding.DecodeString(output.AsImageGenerationCall().Result)

252 if err != nil {

253 panic(err)

254 }

255 if err := os.WriteFile(filename, image, 0o600); err != nil {

256 panic(err)

257 }

258 return

259 }

260 panic("response did not include an image generation call")

261}

262```

263 

188 264 

189 265 

190### Multi-turn image generation266### Multi-turn image generation


244 f.write(base64.b64decode(image_base64))320 f.write(base64.b64decode(image_base64))

245```321```

246 322 

323```go

324package main

325 

326import (

327 "context"

328 "encoding/base64"

329 "os"

330 

331 "github.com/openai/openai-go/v3"

332 "github.com/openai/openai-go/v3/responses"

333)

334 

335func main() {

336 client := openai.NewClient()

337 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

338 Model: "gpt-5.6",

339 Input: responses.ResponseNewParamsInputUnion{

340 OfString: openai.String("Generate an image of gray tabby cat hugging an otter with an orange scarf"),

341 },

342 Tools: []responses.ToolUnionParam{{OfImageGeneration: &responses.ToolImageGenerationParam{Action: "generate"}}},

343 })

344 if err != nil {

345 panic(err)

346 }

347 for _, output := range response.Output {

348 if output.Type != "image_generation_call" {

349 continue

350 }

351 image, err := base64.StdEncoding.DecodeString(output.AsImageGenerationCall().Result)

352 if err != nil {

353 panic(err)

354 }

355 if err := os.WriteFile("otter.png", image, 0o600); err != nil {

356 panic(err)

357 }

358 return

359 }

360 panic("response did not include an image generation call")

361}

362```

363 

247 364 

248If you force `edit` without providing an image in context, the call will return an error. Leave `action` at `auto` to have the model decide when to generate or edit.365If you force `edit` without providing an image in context, the call will return an error. Leave `action` at `auto` to have the model decide when to generate or edit.

249 366 


343 f.write(base64.b64decode(image_base64))460 f.write(base64.b64decode(image_base64))

344```461```

345 462 

463```go

464package main

465 

466import (

467 "context"

468 "encoding/base64"

469 "os"

470 

471 "github.com/openai/openai-go/v3"

472 "github.com/openai/openai-go/v3/responses"

473)

474 

475func main() {

476 client := openai.NewClient()

477 first, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

478 Model: "gpt-5.6",

479 Input: responses.ResponseNewParamsInputUnion{

480 OfString: openai.String("Generate an image of gray tabby cat hugging an otter with an orange scarf"),

481 },

482 Tools: []responses.ToolUnionParam{{OfImageGeneration: &responses.ToolImageGenerationParam{}}},

483 })

484 if err != nil {

485 panic(err)

486 }

487 saveFirstGeneratedImage(first, "cat_and_otter.png")

488 

489 followUp, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

490 Model: "gpt-5.6",

491 PreviousResponseID: openai.String(first.ID),

492 Input: responses.ResponseNewParamsInputUnion{

493 OfString: openai.String("Now make it look realistic"),

494 },

495 Tools: []responses.ToolUnionParam{{OfImageGeneration: &responses.ToolImageGenerationParam{}}},

496 })

497 if err != nil {

498 panic(err)

499 }

500 saveFirstGeneratedImage(followUp, "cat_and_otter_realistic.png")

501}

502 

503func saveFirstGeneratedImage(response *responses.Response, filename string) {

504 for _, output := range response.Output {

505 if output.Type != "image_generation_call" {

506 continue

507 }

508 image, err := base64.StdEncoding.DecodeString(output.AsImageGenerationCall().Result)

509 if err != nil {

510 panic(err)

511 }

512 if err := os.WriteFile(filename, image, 0o600); err != nil {

513 panic(err)

514 }

515 return

516 }

517 panic("response did not include an image generation call")

518}

519```

520 

346 521

347 522 

348 523


458 f.write(base64.b64decode(image_base64))633 f.write(base64.b64decode(image_base64))

459```634```

460 635 

636```go

637package main

638 

639import (

640 "context"

641 "encoding/base64"

642 "encoding/json"

643 "os"

644 

645 "github.com/openai/openai-go/v3"

646 "github.com/openai/openai-go/v3/responses"

647)

648 

649func main() {

650 client := openai.NewClient()

651 first, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

652 Model: "gpt-5.6",

653 Input: responses.ResponseNewParamsInputUnion{

654 OfString: openai.String("Generate an image of gray tabby cat hugging an otter with an orange scarf"),

655 },

656 Tools: []responses.ToolUnionParam{{OfImageGeneration: &responses.ToolImageGenerationParam{}}},

657 })

658 if err != nil {

659 panic(err)

660 }

661 call := firstImageGenerationCall(first)

662 saveImage("cat_and_otter.png", call.Result)

663 input := outputAsInput(first.Output)

664 input = append(input, responses.ResponseInputItemParamOfMessage(

665 responses.ResponseInputMessageContentListParam{responses.ResponseInputContentParamOfInputText("Now make it look realistic")},

666 responses.EasyInputMessageRoleUser,

667 ))

668 

669 followUp, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

670 Model: "gpt-5.6",

671 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: input},

672 Tools: []responses.ToolUnionParam{{OfImageGeneration: &responses.ToolImageGenerationParam{}}},

673 })

674 if err != nil {

675 panic(err)

676 }

677 saveImage("cat_and_otter_realistic.png", firstImageGenerationCall(followUp).Result)

678}

679 

680func firstImageGenerationCall(response *responses.Response) responses.ResponseOutputItemImageGenerationCall {

681 for _, output := range response.Output {

682 if output.Type == "image_generation_call" {

683 return output.AsImageGenerationCall()

684 }

685 }

686 panic("response did not include an image generation call")

687}

688 

689func outputAsInput(output []responses.ResponseOutputItemUnion) []responses.ResponseInputItemUnionParam {

690 input := make([]responses.ResponseInputItemUnionParam, 0, len(output))

691 for _, item := range output {

692 var converted responses.ResponseInputItemUnion

693 if err := json.Unmarshal([]byte(item.RawJSON()), &converted); err != nil {

694 panic(err)

695 }

696 input = append(input, converted.ToParam())

697 }

698 return input

699}

700 

701func saveImage(filename, encoded string) {

702 image, err := base64.StdEncoding.DecodeString(encoded)

703 if err != nil {

704 panic(err)

705 }

706 if err := os.WriteFile(filename, image, 0o600); err != nil {

707 panic(err)

708 }

709}

710```

711 

461 712 

462 713 

463#### Result714#### Result


584 save_base64_image("river-final.png", image_data[0])835 save_base64_image("river-final.png", image_data[0])

585```836```

586 837 

838```go

839package main

840 

841import (

842 "context"

843 "encoding/base64"

844 "fmt"

845 "os"

846 

847 "github.com/openai/openai-go/v3"

848 "github.com/openai/openai-go/v3/responses"

849)

850 

851func main() {

852 client := openai.NewClient()

853 stream := client.Responses.NewStreaming(context.Background(), responses.ResponseNewParams{

854 Model: "gpt-5.6",

855 Input: responses.ResponseNewParamsInputUnion{

856 OfString: openai.String("Draw a gorgeous image of a river made of white owl feathers, snaking its way through a serene winter landscape"),

857 },

858 Tools: []responses.ToolUnionParam{{OfImageGeneration: &responses.ToolImageGenerationParam{PartialImages: openai.Int(2)}}},

859 })

860 for stream.Next() {

861 event := stream.Current()

862 if event.Type == "response.image_generation_call.partial_image" {

863 partial := event.AsResponseImageGenerationCallPartialImage()

864 saveImage(fmt.Sprintf("river-partial-%d.png", partial.PartialImageIndex), partial.PartialImageB64)

865 }

866 if event.Type == "response.completed" {

867 for _, output := range event.AsResponseCompleted().Response.Output {

868 if output.Type == "image_generation_call" {

869 saveImage("river-final.png", output.AsImageGenerationCall().Result)

870 }

871 }

872 }

873 }

874 if err := stream.Err(); err != nil {

875 panic(err)

876 }

877}

878 

879func saveImage(filename, encoded string) {

880 image, err := base64.StdEncoding.DecodeString(encoded)

881 if err != nil {

882 panic(err)

883 }

884 if err := os.WriteFile(filename, image, 0o600); err != nil {

885 panic(err)

886 }

887}

888```

889 

587 890

588 891 

589 892


640 f.write(image_bytes)943 f.write(image_bytes)

641```944```

642 945 

946```go

947package main

948 

949import (

950 "context"

951 "encoding/base64"

952 "fmt"

953 "os"

954 

955 "github.com/openai/openai-go/v3"

956)

957 

958func main() {

959 client := openai.NewClient()

960 stream := client.Images.GenerateStreaming(context.Background(), openai.ImageGenerateParams{

961 Model: openai.ImageModel("gpt-image-2"),

962 Prompt: "Draw a gorgeous image of a river made of white owl feathers, snaking its way through a serene winter landscape",

963 PartialImages: openai.Int(2),

964 })

965 for stream.Next() {

966 event := stream.Current()

967 if event.Type != "image_generation.partial_image" {

968 continue

969 }

970 partial := event.AsImageGenerationPartialImage()

971 saveImage(fmt.Sprintf("river%d.png", partial.PartialImageIndex), partial.B64JSON)

972 }

973 if err := stream.Err(); err != nil {

974 panic(err)

975 }

976}

977 

978func saveImage(filename, encoded string) {

979 image, err := base64.StdEncoding.DecodeString(encoded)

980 if err != nil {

981 panic(err)

982 }

983 if err := os.WriteFile(filename, image, 0o600); err != nil {

984 panic(err)

985 }

986}

987```

988 

643 989 

644 990 

645#### Result991#### Result


739 return result.id1085 return result.id

740```1086```

741 1087 

1088```go

1089package main

1090 

1091import (

1092 "context"

1093 "fmt"

1094 "os"

1095 

1096 "github.com/openai/openai-go/v3"

1097)

1098 

1099func main() {

1100 client := openai.NewClient()

1101 file, err := os.Open("image.png")

1102 if err != nil {

1103 panic(err)

1104 }

1105 defer file.Close()

1106 

1107 uploaded, err := client.Files.New(context.Background(), openai.FileNewParams{

1108 File: file,

1109 Purpose: openai.FilePurposeVision,

1110 })

1111 if err != nil {

1112 panic(err)

1113 }

1114 fmt.Println(uploaded.ID)

1115}

1116```

1117 

742 1118 

743#### Create a base64 encoded image1119#### Create a base64 encoded image

744 1120 


763 return base64_image1139 return base64_image

764```1140```

765 1141 

1142```go

1143package main

1144 

1145import (

1146 "encoding/base64"

1147 "fmt"

1148 "os"

1149)

1150 

1151func main() {

1152 image, err := os.ReadFile("image.png")

1153 if err != nil {

1154 panic(err)

1155 }

1156 fmt.Println(base64.StdEncoding.EncodeToString(image))

1157}

1158```

1159 

766 1160 

767Edit an image1161Edit an image

768 1162 


908 print(response.output_text)1302 print(response.output_text)

909```1303```

910 1304 

1305```go

1306package main

1307 

1308import (

1309 "context"

1310 "encoding/base64"

1311 "os"

1312 

1313 "github.com/openai/openai-go/v3"

1314 "github.com/openai/openai-go/v3/responses"

1315)

1316 

1317func main() {

1318 client := openai.NewClient()

1319 bathBombID := uploadImage(client, "bath-bomb.png")

1320 incenseKitID := uploadImage(client, "incense-kit.png")

1321 

1322 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

1323 Model: "gpt-5.6",

1324 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: responses.ResponseInputParam{

1325 responses.ResponseInputItemParamOfMessage(

1326 responses.ResponseInputMessageContentListParam{

1327 responses.ResponseInputContentParamOfInputText("Generate a photorealistic image of a gift basket on a white background labeled 'Relax & Unwind' with a ribbon and handwriting-like font, containing all the items in the reference pictures."),

1328 {OfInputImage: &responses.ResponseInputImageParam{ImageURL: openai.String(dataURL("body-lotion.png")), Detail: responses.ResponseInputImageDetailAuto}},

1329 {OfInputImage: &responses.ResponseInputImageParam{ImageURL: openai.String(dataURL("soap.png")), Detail: responses.ResponseInputImageDetailAuto}},

1330 {OfInputImage: &responses.ResponseInputImageParam{FileID: openai.String(bathBombID), Detail: responses.ResponseInputImageDetailAuto}},

1331 {OfInputImage: &responses.ResponseInputImageParam{FileID: openai.String(incenseKitID), Detail: responses.ResponseInputImageDetailAuto}},

1332 },

1333 responses.EasyInputMessageRoleUser,

1334 ),

1335 }},

1336 Tools: []responses.ToolUnionParam{{OfImageGeneration: &responses.ToolImageGenerationParam{}}},

1337 })

1338 if err != nil {

1339 panic(err)

1340 }

1341 saveFirstGeneratedImage(response, "gift-basket.png")

1342}

1343 

1344func uploadImage(client openai.Client, filename string) string {

1345 file, err := os.Open(filename)

1346 if err != nil {

1347 panic(err)

1348 }

1349 defer file.Close()

1350 uploaded, err := client.Files.New(context.Background(), openai.FileNewParams{File: file, Purpose: openai.FilePurposeVision})

1351 if err != nil {

1352 panic(err)

1353 }

1354 return uploaded.ID

1355}

1356 

1357func dataURL(filename string) string {

1358 image, err := os.ReadFile(filename)

1359 if err != nil {

1360 panic(err)

1361 }

1362 return "data:image/png;base64," + base64.StdEncoding.EncodeToString(image)

1363}

1364 

1365func saveFirstGeneratedImage(response *responses.Response, filename string) {

1366 for _, output := range response.Output {

1367 if output.Type != "image_generation_call" {

1368 continue

1369 }

1370 image, err := base64.StdEncoding.DecodeString(output.AsImageGenerationCall().Result)

1371 if err != nil {

1372 panic(err)

1373 }

1374 if err := os.WriteFile(filename, image, 0o600); err != nil {

1375 panic(err)

1376 }

1377 return

1378 }

1379 panic("response did not include an image generation call")

1380}

1381```

1382 

911 1383 

912 1384

913 1385 


989 f.write(image_bytes)1461 f.write(image_bytes)

990```1462```

991 1463 

1464```go

1465package main

1466 

1467import (

1468 "context"

1469 "encoding/base64"

1470 "io"

1471 "os"

1472 

1473 "github.com/openai/openai-go/v3"

1474)

1475 

1476func main() {

1477 client := openai.NewClient()

1478 files, closeFiles := openImages(

1479 "bath-bomb.png",

1480 "body-lotion.png",

1481 "incense-kit.png",

1482 "soap.png",

1483 )

1484 defer closeFiles()

1485 

1486 response, err := client.Images.Edit(context.Background(), openai.ImageEditParams{

1487 Model: openai.ImageModel("gpt-image-2"),

1488 Image: openai.ImageEditParamsImageUnion{OfFileArray: files},

1489 Prompt: "Generate a photorealistic image of a gift basket on a white background " +

1490 "labeled 'Relax & Unwind' with a ribbon and handwriting-like font, containing all the items in the reference pictures.",

1491 })

1492 if err != nil {

1493 panic(err)

1494 }

1495 saveImage("basket.png", response.Data[0].B64JSON)

1496}

1497 

1498func openImages(names ...string) ([]io.Reader, func()) {

1499 images := make([]io.Reader, 0, len(names))

1500 files := make([]*os.File, 0, len(names))

1501 for _, name := range names {

1502 file, err := os.Open(name)

1503 if err != nil {

1504 closeFiles(files)

1505 panic(err)

1506 }

1507 images = append(images, openai.File(file, name, "image/png"))

1508 files = append(files, file)

1509 }

1510 return images, func() { closeFiles(files) }

1511}

1512 

1513func closeFiles(files []*os.File) {

1514 for _, file := range files {

1515 if err := file.Close(); err != nil {

1516 panic(err)

1517 }

1518 }

1519}

1520 

1521func saveImage(filename, encoded string) {

1522 image, err := base64.StdEncoding.DecodeString(encoded)

1523 if err != nil {

1524 panic(err)

1525 }

1526 if err := os.WriteFile(filename, image, 0o600); err != nil {

1527 panic(err)

1528 }

1529}

1530```

1531 

992```bash1532```bash

993curl -s -D >(grep -i x-request-id >&2) \1533curl -s -D >(grep -i x-request-id >&2) \

994 -o >(jq -r '.data[0].b64_json' | base64 --decode > gift-basket.png) \1534 -o >(jq -r '.data[0].b64_json' | base64 --decode > gift-basket.png) \


1145 f.write(base64.b64decode(image_base64))1685 f.write(base64.b64decode(image_base64))

1146```1686```

1147 1687 

1688```go

1689package main

1690 

1691import (

1692 "context"

1693 "encoding/base64"

1694 "os"

1695 

1696 "github.com/openai/openai-go/v3"

1697 "github.com/openai/openai-go/v3/responses"

1698)

1699 

1700func main() {

1701 client := openai.NewClient()

1702 imageID := uploadImage(client, "sunlit_lounge.png")

1703 maskID := uploadImage(client, "mask.png")

1704 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

1705 Model: "gpt-5.6",

1706 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: responses.ResponseInputParam{

1707 responses.ResponseInputItemParamOfMessage(

1708 responses.ResponseInputMessageContentListParam{

1709 responses.ResponseInputContentParamOfInputText("Generate an image of the same sunlit indoor lounge area with a pool, but the pool should contain a flamingo."),

1710 {OfInputImage: &responses.ResponseInputImageParam{FileID: openai.String(imageID), Detail: responses.ResponseInputImageDetailAuto}},

1711 },

1712 responses.EasyInputMessageRoleUser,

1713 ),

1714 }},

1715 Tools: []responses.ToolUnionParam{{OfImageGeneration: &responses.ToolImageGenerationParam{

1716 Quality: "high",

1717 InputImageMask: responses.ToolImageGenerationInputImageMaskParam{FileID: openai.String(maskID)},

1718 }}},

1719 })

1720 if err != nil {

1721 panic(err)

1722 }

1723 saveFirstGeneratedImage(response, "lounge.png")

1724}

1725 

1726func uploadImage(client openai.Client, filename string) string {

1727 file, err := os.Open(filename)

1728 if err != nil {

1729 panic(err)

1730 }

1731 defer file.Close()

1732 uploaded, err := client.Files.New(context.Background(), openai.FileNewParams{File: file, Purpose: openai.FilePurposeVision})

1733 if err != nil {

1734 panic(err)

1735 }

1736 return uploaded.ID

1737}

1738 

1739func saveFirstGeneratedImage(response *responses.Response, filename string) {

1740 for _, output := range response.Output {

1741 if output.Type != "image_generation_call" {

1742 continue

1743 }

1744 image, err := base64.StdEncoding.DecodeString(output.AsImageGenerationCall().Result)

1745 if err != nil {

1746 panic(err)

1747 }

1748 if err := os.WriteFile(filename, image, 0o600); err != nil {

1749 panic(err)

1750 }

1751 return

1752 }

1753 panic("response did not include an image generation call")

1754}

1755```

1756 

1148 1757

1149 1758 

1150 1759


1198 f.write(image_bytes)1807 f.write(image_bytes)

1199```1808```

1200 1809 

1810```go

1811package main

1812 

1813import (

1814 "context"

1815 "encoding/base64"

1816 "os"

1817 

1818 "github.com/openai/openai-go/v3"

1819)

1820 

1821func main() {

1822 client := openai.NewClient()

1823 image, err := os.Open("sunlit_lounge.png")

1824 if err != nil {

1825 panic(err)

1826 }

1827 defer image.Close()

1828 mask, err := os.Open("mask.png")

1829 if err != nil {

1830 panic(err)

1831 }

1832 defer mask.Close()

1833 

1834 response, err := client.Images.Edit(context.Background(), openai.ImageEditParams{

1835 Model: openai.ImageModel("gpt-image-2"),

1836 Image: openai.ImageEditParamsImageUnion{OfFile: openai.File(image, "sunlit_lounge.png", "image/png")},

1837 Mask: openai.File(mask, "mask.png", "image/png"),

1838 Prompt: "A sunlit indoor lounge area with a pool containing a flamingo",

1839 })

1840 if err != nil {

1841 panic(err)

1842 }

1843 result, err := base64.StdEncoding.DecodeString(response.Data[0].B64JSON)

1844 if err != nil {

1845 panic(err)

1846 }

1847 if err := os.WriteFile("lounge.png", result, 0o600); err != nil {

1848 panic(err)

1849 }

1850}

1851```

1852 

1201```bash1853```bash

1202curl -s -D >(grep -i x-request-id >&2) \1854curl -s -D >(grep -i x-request-id >&2) \

1203 -o >(jq -r '.data[0].b64_json' | base64 --decode > lounge.png) \1855 -o >(jq -r '.data[0].b64_json' | base64 --decode > lounge.png) \


1271 f.write(mask_bytes)1923 f.write(mask_bytes)

1272```1924```

1273 1925 

1926```go

1927package main

1928 

1929import (

1930 "image"

1931 "image/color"

1932 "image/png"

1933 "os"

1934)

1935 

1936func main() {

1937 file, err := os.Open("mask.png")

1938 if err != nil {

1939 panic(err)

1940 }

1941 defer file.Close()

1942 

1943 mask, _, err := image.Decode(file)

1944 if err != nil {

1945 panic(err)

1946 }

1947 bounds := mask.Bounds()

1948 withAlpha := image.NewNRGBA(bounds)

1949 for y := bounds.Min.Y; y < bounds.Max.Y; y++ {

1950 for x := bounds.Min.X; x < bounds.Max.X; x++ {

1951 gray := color.GrayModel.Convert(mask.At(x, y)).(color.Gray)

1952 withAlpha.SetNRGBA(x, y, color.NRGBA{R: gray.Y, G: gray.Y, B: gray.Y, A: gray.Y})

1953 }

1954 }

1955 

1956 output, err := os.Create("mask_alpha.png")

1957 if err != nil {

1958 panic(err)

1959 }

1960 if err := png.Encode(output, withAlpha); err != nil {

1961 panic(err)

1962 }

1963 if err := output.Close(); err != nil {

1964 panic(err)

1965 }

1966}

1967```

1968 

1274 1969 

1275### Image input fidelity1970### Image input fidelity

1276 1971 


1537 print(hint)2232 print(hint)

1538```2233```

1539 2234 

2235```go

2236package main

2237 

2238import (

2239 "context"

2240 "encoding/json"

2241 "errors"

2242 "fmt"

2243 "slices"

2244 

2245 "github.com/openai/openai-go/v3"

2246)

2247 

2248func main() {

2249 client := openai.NewClient()

2250 _, err := client.Images.Generate(context.Background(), openai.ImageGenerateParams{

2251 Model: openai.ImageModel("gpt-image-2"),

2252 Prompt: "Create a poster humiliating my coworker with insulting captions",

2253 })

2254 if err == nil {

2255 return

2256 }

2257 

2258 var apiError *openai.Error

2259 if !errors.As(err, &apiError) || apiError.Code != "moderation_blocked" {

2260 panic(err)

2261 }

2262 

2263 var body struct {

2264 ModerationDetails struct {

2265 Categories []string `json:"categories"`

2266 ModerationStage string `json:"moderation_stage"`

2267 } `json:"moderation_details"`

2268 }

2269 if err := json.Unmarshal([]byte(apiError.RawJSON()), &body); err != nil {

2270 panic(err)

2271 }

2272 

2273 hint := "This request could not be completed because it did not meet safety requirements."

2274 if slices.Contains(body.ModerationDetails.Categories, "harassment") {

2275 hint = "Try removing abusive or targeting language and focus on neutral visual details instead."

2276 } else if body.ModerationDetails.ModerationStage == "input" {

2277 hint = "Try revising the prompt or input images and submit the request again."

2278 } else if body.ModerationDetails.ModerationStage == "output" {

2279 hint = "The generated result was blocked by a safety check. Try changing the prompt and generating again."

2280 }

2281 

2282 fmt.Printf("Image generation blocked (%s): %s\n", apiError.Code, hint)

2283}

2284```

2285 

1540 2286 

1541### Supported models2287### Supported models

1542 2288 

Details

86 f.write(base64.b64decode(image_base64))86 f.write(base64.b64decode(image_base64))

87```87```

88 88 

89```go

90package main

91 

92import (

93 "context"

94 "encoding/base64"

95 "os"

96 

97 "github.com/openai/openai-go/v3"

98 "github.com/openai/openai-go/v3/responses"

99)

100 

101func main() {

102 client := openai.NewClient()

103 

104 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

105 Model: "gpt-5.6",

106 Input: responses.ResponseNewParamsInputUnion{

107 OfString: openai.String("Generate an image of a gray tabby cat hugging an otter with an orange scarf."),

108 },

109 Tools: []responses.ToolUnionParam{{

110 OfImageGeneration: &responses.ToolImageGenerationParam{},

111 }},

112 })

113 if err != nil {

114 panic(err)

115 }

116 

117 for _, output := range response.Output {

118 if output.Type != "image_generation_call" {

119 continue

120 }

121 image, err := base64.StdEncoding.DecodeString(output.AsImageGenerationCall().Result)

122 if err != nil {

123 panic(err)

124 }

125 if err := os.WriteFile("cat_and_otter.png", image, 0o600); err != nil {

126 panic(err)

127 }

128 return

129 }

130 

131 panic("response did not include an image generation call")

132}

133```

134 

89```bash135```bash

90openai responses create \136openai responses create \

91 --model gpt-5.6 \137 --model gpt-5.6 \


183print(response.output_text)229print(response.output_text)

184```230```

185 231 

232```go

233package main

234 

235import (

236 "context"

237 "fmt"

238 

239 "github.com/openai/openai-go/v3"

240 "github.com/openai/openai-go/v3/responses"

241)

242 

243func main() {

244 client := openai.NewClient()

245 

246 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

247 Model: "gpt-5.6",

248 Input: responses.ResponseNewParamsInputUnion{

249 OfInputItemList: responses.ResponseInputParam{

250 responses.ResponseInputItemParamOfMessage(

251 responses.ResponseInputMessageContentListParam{

252 responses.ResponseInputContentParamOfInputText("What's in this image?"),

253 {OfInputImage: &responses.ResponseInputImageParam{

254 Detail: responses.ResponseInputImageDetailAuto,

255 ImageURL: openai.String("https://api.nga.gov/iiif/a2e6da57-3cd1-4235-b20e-95dcaefed6c8/full/!800,800/0/default.jpg"),

256 }},

257 },

258 responses.EasyInputMessageRoleUser,

259 ),

260 },

261 },

262 })

263 if err != nil {

264 panic(err)

265 }

266 

267 fmt.Println(response.OutputText())

268}

269```

270 

186```csharp271```csharp

187using OpenAI.Responses;272using OpenAI.Responses;

188#pragma warning disable OPENAI001273#pragma warning disable OPENAI001


322print(response.output_text)407print(response.output_text)

323```408```

324 409 

410```go

411package main

412 

413import (

414 "context"

415 "encoding/base64"

416 "fmt"

417 "os"

418 

419 "github.com/openai/openai-go/v3"

420 "github.com/openai/openai-go/v3/responses"

421)

422 

423func main() {

424 client := openai.NewClient()

425 image, err := os.ReadFile("image.png")

426 if err != nil {

427 panic(err)

428 }

429 imageURL := "data:image/png;base64," + base64.StdEncoding.EncodeToString(image)

430 

431 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

432 Model: "gpt-5.6",

433 Input: responses.ResponseNewParamsInputUnion{

434 OfInputItemList: responses.ResponseInputParam{

435 responses.ResponseInputItemParamOfMessage(

436 responses.ResponseInputMessageContentListParam{

437 responses.ResponseInputContentParamOfInputText("What's in this image?"),

438 {OfInputImage: &responses.ResponseInputImageParam{

439 Detail: responses.ResponseInputImageDetailAuto,

440 ImageURL: openai.String(imageURL),

441 }},

442 },

443 responses.EasyInputMessageRoleUser,

444 ),

445 },

446 },

447 })

448 if err != nil {

449 panic(err)

450 }

451 

452 fmt.Println(response.OutputText())

453}

454```

455 

325```csharp456```csharp

326using OpenAI.Responses;457using OpenAI.Responses;

327#pragma warning disable OPENAI001458#pragma warning disable OPENAI001


458print(response.output_text)589print(response.output_text)

459```590```

460 591 

592```go

593package main

594 

595import (

596 "context"

597 "fmt"

598 "os"

599 

600 "github.com/openai/openai-go/v3"

601 "github.com/openai/openai-go/v3/responses"

602)

603 

604func main() {

605 client := openai.NewClient()

606 file, err := os.Open("image.png")

607 if err != nil {

608 panic(err)

609 }

610 defer file.Close()

611 

612 uploaded, err := client.Files.New(context.Background(), openai.FileNewParams{

613 File: file,

614 Purpose: openai.FilePurposeVision,

615 })

616 if err != nil {

617 panic(err)

618 }

619 

620 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

621 Model: "gpt-5.6",

622 Input: responses.ResponseNewParamsInputUnion{

623 OfInputItemList: responses.ResponseInputParam{

624 responses.ResponseInputItemParamOfMessage(

625 responses.ResponseInputMessageContentListParam{

626 responses.ResponseInputContentParamOfInputText("What's in this image?"),

627 {OfInputImage: &responses.ResponseInputImageParam{

628 Detail: responses.ResponseInputImageDetailAuto,

629 FileID: openai.String(uploaded.ID),

630 }},

631 },

632 responses.EasyInputMessageRoleUser,

633 ),

634 },

635 },

636 })

637 if err != nil {

638 panic(err)

639 }

640 

641 fmt.Println(response.OutputText())

642}

643```

644 

461```csharp645```csharp

462using OpenAI.Files;646using OpenAI.Files;

463using OpenAI.Responses;647using OpenAI.Responses;

Details

86print(response)86print(response)

87```87```

88 88 

89```go

90package main

91 

92import (

93 "context"

94 "fmt"

95 

96 "github.com/openai/openai-go/v3"

97 "github.com/openai/openai-go/v3/responses"

98 "github.com/openai/openai-go/v3/shared"

99)

100 

101func main() {

102 client := openai.NewClient()

103 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

104 Model: "gpt-5.2",

105 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Think carefully and outline your steps before answering. How much gold would it take to coat the Statue of Liberty in a 1mm layer?")},

106 Reasoning: shared.ReasoningParam{Effort: shared.ReasoningEffortNone},

107 })

108 if err != nil {

109 panic(err)

110 }

111 fmt.Println(response)

112}

113```

114 

89```bash115```bash

90curl --request POST \116curl --request POST \

91 --url https://api.openai.com/v1/responses \117 --url https://api.openai.com/v1/responses \


144print(response)170print(response)

145```171```

146 172 

173```go

174package main

175 

176import (

177 "context"

178 "fmt"

179 

180 "github.com/openai/openai-go/v3"

181 "github.com/openai/openai-go/v3/responses"

182)

183 

184func main() {

185 client := openai.NewClient()

186 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

187 Model: "gpt-5.2",

188 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("What is the answer to the ultimate question of life, the universe, and everything?")},

189 Text: responses.ResponseTextConfigParam{Verbosity: responses.ResponseTextConfigVerbosityLow},

190 })

191 if err != nil {

192 panic(err)

193 }

194 fmt.Println(response)

195}

196```

197 

147```bash198```bash

148curl --request POST \199curl --request POST \

149 --url https://api.openai.com/v1/responses \200 --url https://api.openai.com/v1/responses \

Details

89print(response)89print(response)

90```90```

91 91 

92```go

93package main

94 

95import (

96 "context"

97 "fmt"

98 

99 "github.com/openai/openai-go/v3"

100 "github.com/openai/openai-go/v3/responses"

101 "github.com/openai/openai-go/v3/shared"

102)

103 

104func main() {

105 client := openai.NewClient()

106 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

107 Model: "gpt-5.4",

108 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Think carefully and outline your steps before answering. How much gold would it take to coat the Statue of Liberty in a 1mm layer?")},

109 Reasoning: shared.ReasoningParam{Effort: shared.ReasoningEffortNone},

110 })

111 if err != nil {

112 panic(err)

113 }

114 fmt.Println(response)

115}

116```

117 

92```bash118```bash

93curl --request POST \119curl --request POST \

94 --url https://api.openai.com/v1/responses \120 --url https://api.openai.com/v1/responses \


147print(response)173print(response)

148```174```

149 175 

176```go

177package main

178 

179import (

180 "context"

181 "fmt"

182 

183 "github.com/openai/openai-go/v3"

184 "github.com/openai/openai-go/v3/responses"

185)

186 

187func main() {

188 client := openai.NewClient()

189 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

190 Model: "gpt-5.4",

191 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("What is the answer to the ultimate question of life, the universe, and everything?")},

192 Text: responses.ResponseTextConfigParam{Verbosity: responses.ResponseTextConfigVerbosityLow},

193 })

194 if err != nil {

195 panic(err)

196 }

197 fmt.Println(response)

198}

199```

200 

150```bash201```bash

151curl --request POST \202curl --request POST \

152 --url https://api.openai.com/v1/responses \203 --url https://api.openai.com/v1/responses \


372print(response.output_text)423print(response.output_text)

373```424```

374 425 

426```go

427package main

428 

429import (

430 "context"

431 "fmt"

432 

433 "github.com/openai/openai-go/v3"

434 "github.com/openai/openai-go/v3/responses"

435)

436 

437func main() {

438 client := openai.NewClient()

439 commentary := responses.ResponseInputItemParamOfMessage(

440 "I’ll inspect the logs and then summarize root cause and remediation.",

441 responses.EasyInputMessageRoleAssistant,

442 )

443 commentary.OfMessage.Phase = responses.EasyInputMessagePhaseCommentary

444 finalAnswer := responses.ResponseInputItemParamOfMessage(

445 "Root cause: cache invalidation race.",

446 responses.EasyInputMessageRoleAssistant,

447 )

448 finalAnswer.OfMessage.Phase = responses.EasyInputMessagePhaseFinalAnswer

449 

450 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

451 Model: "gpt-5.4",

452 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: responses.ResponseInputParam{

453 commentary,

454 finalAnswer,

455 responses.ResponseInputItemParamOfMessage("Great—now give me a rollout-safe fix plan.", responses.EasyInputMessageRoleUser),

456 }},

457 })

458 if err != nil {

459 panic(err)

460 }

461 fmt.Println(response.OutputText())

462}

463```

464 

375 465 

376### GPT-5.4 parameter compatibility466### GPT-5.4 parameter compatibility

377 467 

Details

180response = client.responses.create(model="gpt-5.6", input=context)180response = client.responses.create(model="gpt-5.6", input=context)

181```181```

182 182 

183```go

184package main

185 

186import (

187 "context"

188 "fmt"

189 

190 "github.com/openai/openai-go/v3"

191 "github.com/openai/openai-go/v3/responses"

192)

193 

194func main() {

195 client := openai.NewClient()

196 

197 completion, err := client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{

198 Model: "gpt-5.6",

199 Messages: []openai.ChatCompletionMessageParamUnion{

200 openai.SystemMessage("You are a helpful assistant."),

201 openai.UserMessage("Hello!"),

202 },

203 })

204 if err != nil {

205 panic(err)

206 }

207 fmt.Println(completion.Choices[0].Message.Content)

208 

209 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

210 Model: "gpt-5.6",

211 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: responses.ResponseInputParam{

212 responses.ResponseInputItemParamOfMessage("You are a helpful assistant.", responses.EasyInputMessageRoleSystem),

213 responses.ResponseInputItemParamOfMessage("Hello!", responses.EasyInputMessageRoleUser),

214 }},

215 })

216 if err != nil {

217 panic(err)

218 }

219 fmt.Println(response.OutputText())

220}

221```

222 

183```bash223```bash

184INPUT='[224INPUT='[

185 { "role": "system", "content": "You are a helpful assistant." },225 { "role": "system", "content": "You are a helpful assistant." },


241print(completion.choices[0].message.content)281print(completion.choices[0].message.content)

242```282```

243 283 

284```go

285package main

286 

287import (

288 "context"

289 "fmt"

290 

291 "github.com/openai/openai-go/v3"

292)

293 

294func main() {

295 client := openai.NewClient()

296 

297 completion, err := client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{

298 Model: "gpt-5.6",

299 Messages: []openai.ChatCompletionMessageParamUnion{

300 openai.SystemMessage("You are a helpful assistant."),

301 openai.UserMessage("Hello!"),

302 },

303 })

304 if err != nil {

305 panic(err)

306 }

307 fmt.Println(completion.Choices[0].Message.Content)

308}

309```

310 

244```bash311```bash

245curl https://api.openai.com/v1/chat/completions \312curl https://api.openai.com/v1/chat/completions \

246 -H "Content-Type: application/json" \313 -H "Content-Type: application/json" \


290print(response.output_text)357print(response.output_text)

291```358```

292 359 

360```go

361package main

362 

363import (

364 "context"

365 "fmt"

366 

367 "github.com/openai/openai-go/v3"

368 "github.com/openai/openai-go/v3/responses"

369)

370 

371func main() {

372 client := openai.NewClient()

373 

374 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

375 Model: "gpt-5.6",

376 Instructions: openai.String("You are a helpful assistant."),

377 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Hello!")},

378 })

379 if err != nil {

380 panic(err)

381 }

382 fmt.Println(response.OutputText())

383}

384```

385 

293```bash386```bash

294curl https://api.openai.com/v1/responses \387curl https://api.openai.com/v1/responses \

295 -H "Content-Type: application/json" \388 -H "Content-Type: application/json" \


368res2 = client.chat.completions.create(model="gpt-5.6", messages=messages)461res2 = client.chat.completions.create(model="gpt-5.6", messages=messages)

369```462```

370 463 

464```go

465package main

466 

467import (

468 "context"

469 "fmt"

470 

471 "github.com/openai/openai-go/v3"

472)

473 

474func main() {

475 client := openai.NewClient()

476 messages := []openai.ChatCompletionMessageParamUnion{

477 openai.SystemMessage("You are a helpful assistant."),

478 openai.UserMessage("What is the capital of France?"),

479 }

480 

481 first, err := client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{Model: "gpt-5.6", Messages: messages})

482 if err != nil {

483 panic(err)

484 }

485 messages = append(messages, openai.AssistantMessage(first.Choices[0].Message.Content), openai.UserMessage("And its population?"))

486 

487 second, err := client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{Model: "gpt-5.6", Messages: messages})

488 if err != nil {

489 panic(err)

490 }

491 fmt.Println(second.Choices[0].Message.Content)

492}

493```

494 

371 495 

372 496

373 497 


418 model="gpt-5.6",542 model="gpt-5.6",

419 input=context,543 input=context,

420)544)

545```

546 

547```go

548package main

549 

550import (

551 "context"

552 "encoding/json"

553 "fmt"

554 

555 "github.com/openai/openai-go/v3"

556 "github.com/openai/openai-go/v3/responses"

557)

558 

559func main() {

560 client := openai.NewClient()

561 contextItems := responses.ResponseInputParam{

562 responses.ResponseInputItemParamOfMessage("What is the capital of France?", responses.EasyInputMessageRoleUser),

563 }

564 first, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

565 Model: "gpt-5.6",

566 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: contextItems},

567 })

568 if err != nil {

569 panic(err)

570 }

571 contextItems = append(contextItems, outputAsInput(first.Output)...)

572 contextItems = append(contextItems, responses.ResponseInputItemParamOfMessage("And its population?", responses.EasyInputMessageRoleUser))

573 second, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

574 Model: "gpt-5.6",

575 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: contextItems},

576 })

577 if err != nil {

578 panic(err)

579 }

580 fmt.Println(second.OutputText())

581}

582 

583func outputAsInput(output []responses.ResponseOutputItemUnion) []responses.ResponseInputItemUnionParam {

584 input := make([]responses.ResponseInputItemUnionParam, 0, len(output))

585 for _, item := range output {

586 var converted responses.ResponseInputItemUnion

587 if err := json.Unmarshal([]byte(item.RawJSON()), &converted); err != nil {

588 panic(err)

589 }

590 input = append(input, converted.ToParam())

591 }

592 return input

593}

421```594```

422 595 

423 You can also use `previous_response_id` to reference the previous response596 You can also use `previous_response_id` to reference the previous response


452)625)

453```626```

454 627 

628```go

629package main

630 

631import (

632 "context"

633 "fmt"

634 

635 "github.com/openai/openai-go/v3"

636 "github.com/openai/openai-go/v3/responses"

637)

638 

639func main() {

640 client := openai.NewClient()

641 

642 first, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

643 Model: "gpt-5.6",

644 Store: openai.Bool(true),

645 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("What is the capital of France?")},

646 })

647 if err != nil {

648 panic(err)

649 }

650 

651 second, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

652 Model: "gpt-5.6",

653 Store: openai.Bool(true),

654 PreviousResponseID: openai.String(first.ID),

655 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("And its population?")},

656 })

657 if err != nil {

658 panic(err)

659 }

660 fmt.Println(second.OutputText())

661}

662```

663 

455 664 

456 665 

457Even when using `previous_response_id`, all previous input tokens for responses in the chain are billed as input tokens in the API.666Even when using `previous_response_id`, all previous input tokens for responses in the chain are billed as input tokens in the API.


614)823)

615```824```

616 825 

826```go

827package main

828 

829import (

830 "context"

831 "fmt"

832 

833 "github.com/openai/openai-go/v3"

834 "github.com/openai/openai-go/v3/shared"

835)

836 

837func main() {

838 client := openai.NewClient()

839 schema := map[string]any{

840 "type": "object",

841 "properties": map[string]any{

842 "name": map[string]any{"type": "string", "minLength": 1},

843 "age": map[string]any{"type": "number", "minimum": 0, "maximum": 130},

844 },

845 "required": []string{"name", "age"},

846 "additionalProperties": false,

847 }

848 

849 completion, err := client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{

850 Model: "gpt-5.6",

851 ReasoningEffort: openai.ReasoningEffortMedium,

852 Messages: []openai.ChatCompletionMessageParamUnion{

853 openai.UserMessage("Jane, 54 years old"),

854 },

855 ResponseFormat: openai.ChatCompletionNewParamsResponseFormatUnion{

856 OfJSONSchema: &shared.ResponseFormatJSONSchemaParam{JSONSchema: shared.ResponseFormatJSONSchemaJSONSchemaParam{

857 Name: "person", Strict: openai.Bool(true), Schema: schema,

858 }},

859 },

860 })

861 if err != nil {

862 panic(err)

863 }

864 fmt.Println(completion.Choices[0].Message.Content)

865}

866```

867 

617```bash868```bash

618curl https://api.openai.com/v1/chat/completions \869curl https://api.openai.com/v1/chat/completions \

619 -H "Content-Type: application/json" \870 -H "Content-Type: application/json" \


718)969)

719```970```

720 971 

972```go

973package main

974 

975import (

976 "context"

977 "fmt"

978 

979 "github.com/openai/openai-go/v3"

980 "github.com/openai/openai-go/v3/responses"

981)

982 

983func main() {

984 client := openai.NewClient()

985 schema := map[string]any{

986 "type": "object",

987 "properties": map[string]any{

988 "name": map[string]any{"type": "string", "minLength": 1},

989 "age": map[string]any{"type": "number", "minimum": 0, "maximum": 130},

990 },

991 "required": []string{"name", "age"},

992 "additionalProperties": false,

993 }

994 

995 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

996 Model: "gpt-5.6",

997 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Jane, 54 years old")},

998 Text: responses.ResponseTextConfigParam{Format: responses.ResponseFormatTextConfigUnionParam{

999 OfJSONSchema: &responses.ResponseFormatTextJSONSchemaConfigParam{Name: "person", Schema: schema, Strict: openai.Bool(true)},

1000 }},

1001 })

1002 if err != nil {

1003 panic(err)

1004 }

1005 fmt.Println(response.OutputText())

1006}

1007```

1008 

721```bash1009```bash

722curl https://api.openai.com/v1/responses \1010curl https://api.openai.com/v1/responses \

723 -H "Content-Type: application/json" \1011 -H "Content-Type: application/json" \


837)1125)

838```1126```

839 1127 

1128```go

1129package main

1130 

1131import (

1132 "context"

1133 "fmt"

1134 

1135 "github.com/openai/openai-go/v3"

1136 "github.com/openai/openai-go/v3/shared"

1137)

1138 

1139func main() {

1140 client := openai.NewClient()

1141 completion, err := client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{

1142 Model: "gpt-5.6",

1143 Messages: []openai.ChatCompletionMessageParamUnion{

1144 openai.SystemMessage("You are a helpful assistant."),

1145 openai.UserMessage("Who is the current president of France?"),

1146 },

1147 Functions: []openai.ChatCompletionNewParamsFunction{{

1148 Name: "web_search",

1149 Description: openai.String("Search the web for information"),

1150 Parameters: map[string]any{

1151 "type": "object",

1152 "properties": map[string]any{"query": map[string]any{"type": "string"}},

1153 "required": []string{"query"},

1154 },

1155 }},

1156 ReasoningEffort: shared.ReasoningEffortNone,

1157 })

1158 if err != nil {

1159 panic(err)

1160 }

1161 fmt.Println(completion.Choices[0].Message)

1162}

1163```

1164 

840```bash1165```bash

841curl https://api.example.com/search \1166curl https://api.example.com/search \

842 -G \1167 -G \


874print(answer.output_text)1199print(answer.output_text)

875```1200```

876 1201 

1202```go

1203package main

1204 

1205import (

1206 "context"

1207 "fmt"

1208 

1209 "github.com/openai/openai-go/v3"

1210 "github.com/openai/openai-go/v3/responses"

1211)

1212 

1213func main() {

1214 client := openai.NewClient()

1215 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

1216 Model: "gpt-5.6",

1217 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Who is the current president of France?")},

1218 Tools: []responses.ToolUnionParam{

1219 responses.ToolParamOfWebSearch(responses.WebSearchToolTypeWebSearch),

1220 },

1221 })

1222 if err != nil {

1223 panic(err)

1224 }

1225 fmt.Println(response.OutputText())

1226}

1227```

1228 

877```bash1229```bash

878curl https://api.openai.com/v1/responses \1230curl https://api.openai.com/v1/responses \

879 -H "Content-Type: application/json" \1231 -H "Content-Type: application/json" \

Details

87print(output_moderation.flagged)87print(output_moderation.flagged)

88```88```

89 89 

90```go

91package main

92 

93import (

94 "context"

95 "errors"

96 "fmt"

97 

98 "github.com/openai/openai-go/v3"

99 "github.com/openai/openai-go/v3/responses"

100)

101 

102func main() {

103 client := openai.NewClient()

104 

105 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

106 Model: "gpt-5.6",

107 Input: responses.ResponseNewParamsInputUnion{

108 OfString: openai.String("A user asks for instructions to make a harmful weapon. Draft a brief refusal and offer a safer alternative."),

109 },

110 Moderation: responses.ResponseNewParamsModeration{

111 Model: "omni-moderation-latest",

112 },

113 })

114 if err != nil {

115 panic(err)

116 }

117 

118 switch inputModeration := response.Moderation.Input.AsAny().(type) {

119 case responses.ResponseModerationInputModerationResult:

120 fmt.Println(inputModeration.Flagged)

121 case responses.ResponseModerationInputError:

122 panic(errors.New(inputModeration.Message))

123 default:

124 panic("unexpected input moderation result")

125 }

126 switch outputModeration := response.Moderation.Output.AsAny().(type) {

127 case responses.ResponseModerationOutputModerationResult:

128 fmt.Println(outputModeration.Flagged)

129 case responses.ResponseModerationOutputError:

130 panic(errors.New(outputModeration.Message))

131 default:

132 panic("unexpected output moderation result")

133 }

134}

135```

136 

90 137 

91The Responses API returns an input `moderation_result` object at `response.moderation.input` and an output `moderation_result` object at `response.moderation.output`.138The Responses API returns an input `moderation_result` object at `response.moderation.input` and an output `moderation_result` object at `response.moderation.output`.

92 139 


139print(response)186print(response)

140```187```

141 188 

189```go

190package main

191 

192import (

193 "context"

194 "fmt"

195 

196 "github.com/openai/openai-go/v3"

197)

198 

199func main() {

200 client := openai.NewClient()

201 

202 moderation, err := client.Moderations.New(context.Background(), openai.ModerationNewParams{

203 Model: openai.ModerationModelOmniModerationLatest,

204 Input: openai.ModerationNewParamsInputUnion{

205 OfString: openai.String("Text to classify goes here."),

206 },

207 })

208 if err != nil {

209 panic(err)

210 }

211 

212 fmt.Println(moderation.Results[0].Flagged)

213}

214```

215 

142```bash216```bash

143curl https://api.openai.com/v1/moderations \217curl https://api.openai.com/v1/moderations \

144 -X POST \218 -X POST \


207print(response)281print(response)

208```282```

209 283 

284```go

285package main

286 

287import (

288 "context"

289 "fmt"

290 

291 "github.com/openai/openai-go/v3"

292)

293 

294func main() {

295 client := openai.NewClient()

296 

297 moderation, err := client.Moderations.New(context.Background(), openai.ModerationNewParams{

298 Model: openai.ModerationModelOmniModerationLatest,

299 Input: openai.ModerationNewParamsInputUnion{

300 OfModerationMultiModalArray: []openai.ModerationMultiModalInputUnionParam{

301 openai.ModerationMultiModalInputParamOfText("Text to classify goes here."),

302 openai.ModerationMultiModalInputParamOfImageURL(openai.ModerationImageURLInputImageURLParam{

303 URL: "https://api.nga.gov/iiif/a2e6da57-3cd1-4235-b20e-95dcaefed6c8/full/!800,800/0/default.jpg",

304 }),

305 },

306 },

307 })

308 if err != nil {

309 panic(err)

310 }

311 

312 fmt.Println(moderation.Results[0].Flagged)

313}

314```

315 

210```bash316```bash

211curl https://api.openai.com/v1/moderations \317curl https://api.openai.com/v1/moderations \

212 -X POST \318 -X POST \

Details

104print(completion.choices[0].message.content)104print(completion.choices[0].message.content)

105```105```

106 106 

107```go

108package main

109 

110import (

111 "context"

112 "fmt"

113 "strings"

114 

115 "github.com/openai/openai-go/v3"

116 "github.com/openai/openai-go/v3/shared"

117)

118 

119func main() {

120 client := openai.NewClient()

121 code := strings.TrimSpace(`

122class User {

123 firstName: string = "";

124 lastName: string = "";

125 username: string = "";

126}

127 

128export default User;

129`)

130 refactorPrompt := strings.TrimSpace(`

131Replace the "username" property with an "email" property. Respond only

132with code, and with no markdown formatting.

133`)

134 completion, err := client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{

135 Model: shared.ChatModelGPT4_1,

136 Messages: []openai.ChatCompletionMessageParamUnion{

137 openai.UserMessage(refactorPrompt),

138 openai.UserMessage(code),

139 },

140 Store: openai.Bool(true),

141 Prediction: openai.ChatCompletionPredictionContentParam{

142 Content: openai.ChatCompletionPredictionContentContentUnionParam{OfString: openai.String(code)},

143 },

144 })

145 if err != nil {

146 panic(err)

147 }

148 fmt.Println(completion.Choices[0].Message.Content)

149}

150```

151 

107```bash152```bash

108curl https://api.openai.com/v1/chat/completions \153curl https://api.openai.com/v1/chat/completions \

109 -H "Content-Type: application/json" \154 -H "Content-Type: application/json" \


245 print(chunk.choices[0].delta.content, end="")290 print(chunk.choices[0].delta.content, end="")

246```291```

247 292 

293```go

294package main

295 

296import (

297 "context"

298 "fmt"

299 "strings"

300 

301 "github.com/openai/openai-go/v3"

302 "github.com/openai/openai-go/v3/shared"

303)

304 

305func main() {

306 client := openai.NewClient()

307 code := strings.TrimSpace(`

308class User {

309 firstName: string = "";

310 lastName: string = "";

311 username: string = "";

312}

313 

314export default User;

315`)

316 refactorPrompt := strings.TrimSpace(`

317Replace the "username" property with an "email" property. Respond only

318with code, and with no markdown formatting.

319`)

320 stream := client.Chat.Completions.NewStreaming(context.Background(), openai.ChatCompletionNewParams{

321 Model: shared.ChatModelGPT4_1,

322 Messages: []openai.ChatCompletionMessageParamUnion{

323 openai.UserMessage(refactorPrompt),

324 openai.UserMessage(code),

325 },

326 Store: openai.Bool(true),

327 Prediction: openai.ChatCompletionPredictionContentParam{

328 Content: openai.ChatCompletionPredictionContentContentUnionParam{OfString: openai.String(code)},

329 },

330 })

331 for stream.Next() {

332 if len(stream.Current().Choices) > 0 {

333 fmt.Print(stream.Current().Choices[0].Delta.Content)

334 }

335 }

336 if err := stream.Err(); err != nil {

337 panic(err)

338 }

339}

340```

341 

248 342 

249## Position of predicted text in response343## Position of predicted text in response

250 344 

Details

43 "fmt"43 "fmt"

44 44 

45 "github.com/openai/openai-go/v3"45 "github.com/openai/openai-go/v3"

46 "github.com/openai/openai-go/v3/option"

47 "github.com/openai/openai-go/v3/responses"46 "github.com/openai/openai-go/v3/responses"

48)47)

49 48 

50func main() {49func main() {

51 client := openai.NewClient(50 client := openai.NewClient()

52 option.WithAPIKey("My API Key"), // or set OPENAI_API_KEY in your env

53 )

54 51 

55 resp, err := client.Responses.New(context.TODO(), responses.ResponseNewParams{52 resp, err := client.Responses.New(context.TODO(), responses.ResponseNewParams{

56 Model: "gpt-5.6",53 Model: "gpt-5.6",

Details

51)51)

52```52```

53 53 

54```go

55package main

56 

57import (

58 "context"

59 "fmt"

60 

61 "github.com/openai/openai-go/v3"

62 "github.com/openai/openai-go/v3/responses"

63)

64 

65func main() {

66 client := openai.NewClient()

67 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

68 Prompt: responses.ResponsePromptParam{

69 ID: "pmpt_123",

70 Version: openai.String("1"),

71 Variables: map[string]responses.ResponsePromptVariableUnionParam{

72 "customer_name": {OfString: openai.String("Acme")},

73 "issue": {OfString: openai.String("billing question")},

74 },

75 },

76 })

77 if err != nil {

78 panic(err)

79 }

80 fmt.Println(response.OutputText())

81}

82```

83 

54```bash84```bash

55curl https://api.openai.com/v1/responses \85curl https://api.openai.com/v1/responses \

56 -H "Content-Type: application/json" \86 -H "Content-Type: application/json" \


118print(response.output_text)148print(response.output_text)

119```149```

120 150 

151```go

152package main

153 

154import (

155 "context"

156 "fmt"

157 

158 "github.com/openai/openai-go/v3"

159 "github.com/openai/openai-go/v3/responses"

160)

161 

162func main() {

163 client := openai.NewClient()

164 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

165 Model: "gpt-5.6",

166 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: responses.ResponseInputParam{

167 responses.ResponseInputItemParamOfMessage("You are a helpful support assistant. Be concise, accurate, and friendly.", responses.EasyInputMessageRoleSystem),

168 responses.ResponseInputItemParamOfMessage("Customer name: Acme. Issue: billing question. Write a response to the customer.", responses.EasyInputMessageRoleUser),

169 }},

170 })

171 if err != nil {

172 panic(err)

173 }

174 fmt.Println(response.OutputText())

175}

176```

177 

121```bash178```bash

122curl https://api.openai.com/v1/responses \179curl https://api.openai.com/v1/responses \

123 -H "Content-Type: application/json" \180 -H "Content-Type: application/json" \


217)274)

218```275```

219 276 

277```go

278package main

279 

280import (

281 "context"

282 "fmt"

283 

284 "github.com/openai/openai-go/v3"

285 "github.com/openai/openai-go/v3/responses"

286)

287 

288func main() {

289 client := openai.NewClient()

290 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

291 Model: "gpt-5.6",

292 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: buildSupportPrompt("Acme", "billing question")},

293 })

294 if err != nil {

295 panic(err)

296 }

297 fmt.Println(response.OutputText())

298}

299 

300func buildSupportPrompt(customerName string, issue string) responses.ResponseInputParam {

301 return responses.ResponseInputParam{

302 responses.ResponseInputItemParamOfMessage("You are a helpful support assistant. Be concise, accurate, and friendly. Do not invent policy details.", responses.EasyInputMessageRoleSystem),

303 responses.ResponseInputItemParamOfMessage(fmt.Sprintf("Customer name: %s. Issue: %s. Write a response to the customer.", customerName, issue), responses.EasyInputMessageRoleUser),

304 }

305}

306```

307 

220 308 

221## What you gain309## What you gain

222 310 

Details

60print(response.output_text)60print(response.output_text)

61```61```

62 62 

63```go

64package main

65 

66import (

67 "context"

68 "fmt"

69 

70 "github.com/openai/openai-go/v3"

71 "github.com/openai/openai-go/v3/responses"

72)

73 

74func main() {

75 client := openai.NewClient()

76 prompt := `Write a bash script that takes a matrix represented as a string with

77format '[1,2],[3,4],[5,6]' and prints the transpose in the same format.`

78 

79 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

80 Model: "gpt-5.6",

81 Reasoning: responses.ReasoningParam{

82 Effort: responses.ReasoningEffortLow,

83 },

84 Input: responses.ResponseNewParamsInputUnion{

85 OfString: openai.String(prompt),

86 },

87 })

88 if err != nil {

89 panic(err)

90 }

91 

92 fmt.Println(response.OutputText())

93}

94```

95 

63```bash96```bash

64curl https://api.openai.com/v1/responses \97curl https://api.openai.com/v1/responses \

65 -H "Content-Type: application/json" \98 -H "Content-Type: application/json" \


236 print("Ran out of tokens during reasoning")269 print("Ran out of tokens during reasoning")

237```270```

238 271 

272```go

273package main

274 

275import (

276 "context"

277 "fmt"

278 

279 "github.com/openai/openai-go/v3"

280 "github.com/openai/openai-go/v3/responses"

281)

282 

283func main() {

284 client := openai.NewClient()

285 prompt := `Write a bash script that takes a matrix represented as a string with

286format '[1,2],[3,4],[5,6]' and prints the transpose in the same format.`

287 

288 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

289 Model: "gpt-5.6",

290 MaxOutputTokens: openai.Int(300),

291 Reasoning: responses.ReasoningParam{

292 Effort: responses.ReasoningEffortMedium,

293 },

294 Input: responses.ResponseNewParamsInputUnion{

295 OfString: openai.String(prompt),

296 },

297 })

298 if err != nil {

299 panic(err)

300 }

301 

302 if response.Status == responses.ResponseStatusIncomplete {

303 fmt.Println("Ran out of tokens")

304 if text := response.OutputText(); text != "" {

305 fmt.Println("Partial output:", text)

306 }

307 }

308}

309```

310 

239 311 

240### Keeping reasoning items in context312### Keeping reasoning items in context

241 313 


317print(second.output_text)389print(second.output_text)

318```390```

319 391 

392```go

393package main

394 

395import (

396 "context"

397 "fmt"

398 

399 "github.com/openai/openai-go/v3"

400 "github.com/openai/openai-go/v3/responses"

401)

402 

403func main() {

404 client := openai.NewClient()

405 model := "gpt-5.6"

406 

407 first, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

408 Model: model,

409 Input: responses.ResponseNewParamsInputUnion{

410 OfString: openai.String("Inspect this repository and identify the likely bug."),

411 },

412 Reasoning: responses.ReasoningParam{

413 Context: responses.ReasoningContextCurrentTurn,

414 },

415 })

416 if err != nil {

417 panic(err)

418 }

419 

420 second, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

421 Model: model,

422 PreviousResponseID: openai.String(first.ID),

423 Input: responses.ResponseNewParamsInputUnion{

424 OfString: openai.String("Now patch the bug and explain the change."),

425 },

426 Reasoning: responses.ReasoningParam{

427 Context: responses.ReasoningContextAllTurns,

428 },

429 })

430 if err != nil {

431 panic(err)

432 }

433 

434 fmt.Println(second.OutputText())

435}

436```

437 

320 438 

321Use `current_turn` when replaying older response items that the model no longer needs. Those reasoning items can remain in the API payload for continuity, but the service does not render them into the new sample. This can reduce the rendered context for long-running workflows.439Use `current_turn` when replaying older response items that the model no longer needs. Those reasoning items can remain in the API payload for continuity, but the service does not render them into the new sample. This can reduce the rendered context for long-running workflows.

322 440 


422print(second.output_text)540print(second.output_text)

423```541```

424 542 

543```go

544package main

545 

546import (

547 "context"

548 "encoding/json"

549 "fmt"

550 

551 "github.com/openai/openai-go/v3"

552 "github.com/openai/openai-go/v3/responses"

553 "github.com/openai/openai-go/v3/shared"

554)

555 

556func main() {

557 client := openai.NewClient()

558 history := []responses.ResponseInputItemUnionParam{

559 responses.ResponseInputItemParamOfMessage("Inspect this repository and identify the likely bug.", responses.EasyInputMessageRoleUser),

560 }

561 first, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

562 Model: "gpt-5.6",

563 Store: openai.Bool(false),

564 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: history},

565 Reasoning: shared.ReasoningParam{Context: shared.ReasoningContextCurrentTurn},

566 })

567 if err != nil {

568 panic(err)

569 }

570 history = append(history, outputAsInput(first.Output)...)

571 history = append(history, responses.ResponseInputItemParamOfMessage(

572 "Now patch the bug and explain the change.",

573 responses.EasyInputMessageRoleUser,

574 ))

575 second, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

576 Model: "gpt-5.6",

577 Store: openai.Bool(false),

578 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: history},

579 Reasoning: shared.ReasoningParam{Context: shared.ReasoningContextAllTurns},

580 })

581 if err != nil {

582 panic(err)

583 }

584 fmt.Println(second.OutputText())

585}

586 

587func outputAsInput(output []responses.ResponseOutputItemUnion) []responses.ResponseInputItemUnionParam {

588 input := make([]responses.ResponseInputItemUnionParam, 0, len(output))

589 for _, item := range output {

590 var converted responses.ResponseInputItemUnion

591 if err := json.Unmarshal([]byte(item.RawJSON()), &converted); err != nil {

592 panic(err)

593 }

594 input = append(input, converted.ToParam())

595 }

596 return input

597}

598```

599 

425 600 

426## Reasoning summaries601## Reasoning summaries

427 602 


465print(response.output)640print(response.output)

466```641```

467 642 

643```go

644package main

645 

646import (

647 "context"

648 "fmt"

649 

650 "github.com/openai/openai-go/v3"

651 "github.com/openai/openai-go/v3/responses"

652)

653 

654func main() {

655 client := openai.NewClient()

656 

657 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

658 Model: "gpt-5.6",

659 Input: responses.ResponseNewParamsInputUnion{

660 OfString: openai.String("What is the capital of France?"),

661 },

662 Reasoning: responses.ReasoningParam{

663 Effort: responses.ReasoningEffortLow,

664 Summary: responses.ReasoningSummaryAuto,

665 },

666 })

667 if err != nil {

668 panic(err)

669 }

670 

671 fmt.Println(response.Output)

672}

673```

674 

468```bash675```bash

469curl https://api.openai.com/v1/responses \676curl https://api.openai.com/v1/responses \

470 -H "Content-Type: application/json" \677 -H "Content-Type: application/json" \


584print(response.output_text)791print(response.output_text)

585```792```

586 793 

794```go

795package main

796 

797import (

798 "context"

799 "fmt"

800 

801 "github.com/openai/openai-go/v3"

802 "github.com/openai/openai-go/v3/responses"

803)

804 

805func main() {

806 client := openai.NewClient()

807 commentary := responses.ResponseInputItemParamOfMessage(

808 "I’ll inspect the logs and then summarize root cause and remediation.",

809 responses.EasyInputMessageRoleAssistant,

810 )

811 commentary.OfMessage.Phase = responses.EasyInputMessagePhaseCommentary

812 finalAnswer := responses.ResponseInputItemParamOfMessage(

813 "Root cause: cache invalidation race.",

814 responses.EasyInputMessageRoleAssistant,

815 )

816 finalAnswer.OfMessage.Phase = responses.EasyInputMessagePhaseFinalAnswer

817 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

818 Model: "gpt-5.6",

819 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: responses.ResponseInputParam{

820 commentary,

821 finalAnswer,

822 responses.ResponseInputItemParamOfMessage("Great—now give me a rollout-safe fix plan.", responses.EasyInputMessageRoleUser),

823 }},

824 })

825 if err != nil {

826 panic(err)

827 }

828 fmt.Println(response.OutputText())

829}

830```

831 

587 832 

588## Advice on prompting833## Advice on prompting

589 834 


702print(response.output_text)947print(response.output_text)

703```948```

704 949 

950```go

951package main

952 

953import (

954 "context"

955 "fmt"

956 

957 "github.com/openai/openai-go/v3"

958 "github.com/openai/openai-go/v3/responses"

959)

960 

961func main() {

962 client := openai.NewClient()

963 prompt := `Instructions:

964- Given the React component below, change it so that nonfiction books have red text.

965- Return only the code in your reply.

966- Do not include any additional formatting, such as markdown code blocks.

967 

968const books = [

969 { title: 'Dune', category: 'fiction', id: 1 },

970 { title: 'Frankenstein', category: 'fiction', id: 2 },

971 { title: 'Moneyball', category: 'nonfiction', id: 3 },

972];`

973 

974 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

975 Model: "gpt-5.6",

976 Input: responses.ResponseNewParamsInputUnion{

977 OfString: openai.String(prompt),

978 },

979 })

980 if err != nil {

981 panic(err)

982 }

983 

984 fmt.Println(response.OutputText())

985}

986```

987 

705 988 

706 989

707 990 


775print(response.output_text)1058print(response.output_text)

776```1059```

777 1060 

1061```go

1062package main

1063 

1064import (

1065 "context"

1066 "fmt"

1067 

1068 "github.com/openai/openai-go/v3"

1069 "github.com/openai/openai-go/v3/responses"

1070)

1071 

1072func main() {

1073 client := openai.NewClient()

1074 prompt := `I want to build a Python app that takes user questions and looks them up

1075in a database where they are mapped to answers. If there is a close match, it

1076retrieves the matched answer. If there is not, it asks the user to provide an

1077answer and stores the question/answer pair in the database. Make a plan for the

1078directory structure you will need, then return each file in full.`

1079 

1080 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

1081 Model: "gpt-5.6",

1082 Input: responses.ResponseNewParamsInputUnion{

1083 OfString: openai.String(prompt),

1084 },

1085 })

1086 if err != nil {

1087 panic(err)

1088 }

1089 

1090 fmt.Println(response.OutputText())

1091}

1092```

1093 

778 1094 

779 1095

780 1096 


834print(response.output_text)1150print(response.output_text)

835```1151```

836 1152 

1153```go

1154package main

1155 

1156import (

1157 "context"

1158 "fmt"

1159 

1160 "github.com/openai/openai-go/v3"

1161 "github.com/openai/openai-go/v3/responses"

1162)

1163 

1164func main() {

1165 client := openai.NewClient()

1166 prompt := `What are three compounds we should consider investigating to advance

1167research into new antibiotics? Why should we consider them?`

1168 

1169 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

1170 Model: "gpt-5.6",

1171 Input: responses.ResponseNewParamsInputUnion{

1172 OfString: openai.String(prompt),

1173 },

1174 })

1175 if err != nil {

1176 panic(err)

1177 }

1178 

1179 fmt.Println(response.OutputText())

1180}

1181```

1182 

837 1183 

838 1184 

839## Use case examples1185## Use case examples

Details

47)47)

48```48```

49 49 

50```go

51package main

52 

53import (

54 "context"

55 "fmt"

56 "os"

57 

58 "github.com/openai/openai-go/v3"

59)

60 

61func main() {

62 client := openai.NewClient()

63 vectorStore, err := client.VectorStores.New(context.Background(), openai.VectorStoreNewParams{Name: openai.String("Support FAQ")})

64 if err != nil {

65 panic(err)

66 }

67 file, err := os.Open("customer_policies.txt")

68 if err != nil {

69 panic(err)

70 }

71 defer file.Close()

72 _, err = client.VectorStores.Files.UploadAndPoll(context.Background(), vectorStore.ID, openai.FileNewParams{

73 File: openai.File(file, "customer_policies.txt", "text/plain"),

74 Purpose: openai.FilePurposeAssistants,

75 }, 1000)

76 if err != nil {

77 panic(err)

78 }

79 fmt.Println(vectorStore.ID)

80}

81```

82 

50 83 

51<li className={s.StandaloneLi} data-number={2}>84<li className={s.StandaloneLi} data-number={2}>

52 **Send search query** to get relevant results.85 **Send search query** to get relevant results.


71)104)

72```105```

73 106 

107```go

108package main

109 

110import (

111 "context"

112 "fmt"

113 

114 "github.com/openai/openai-go/v3"

115)

116 

117func main() {

118 client := openai.NewClient()

119 results, err := client.VectorStores.Search(context.Background(), "vs_123", openai.VectorStoreSearchParams{

120 Query: openai.VectorStoreSearchParamsQueryUnion{OfString: openai.String("What is the return policy?")},

121 })

122 if err != nil {

123 panic(err)

124 }

125 fmt.Println(results.Data)

126}

127```

128 

74 129 

75To learn how to use the results with our models, check out the [synthesizing130To learn how to use the results with our models, check out the [synthesizing

76 responses](#synthesizing-responses) section.131 responses](#synthesizing-responses) section.


112)167)

113```168```

114 169 

170```go

171package main

172 

173import (

174 "context"

175 "fmt"

176 

177 "github.com/openai/openai-go/v3"

178)

179 

180func main() {

181 client := openai.NewClient()

182 results, err := client.VectorStores.Search(context.Background(), "vs_123", openai.VectorStoreSearchParams{

183 Query: openai.VectorStoreSearchParamsQueryUnion{OfString: openai.String("How many woodchucks are allowed per passenger?")},

184 })

185 if err != nil {

186 panic(err)

187 }

188 fmt.Println(results.Data)

189}

190```

191 

115 192 

116Results193Results

117 194 


377)454)

378```455```

379 456 

457```go

458package main

459 

460import (

461 "context"

462 "fmt"

463 

464 "github.com/openai/openai-go/v3"

465)

466 

467func main() {

468 client := openai.NewClient()

469 vectorStore, err := client.VectorStores.New(context.Background(), openai.VectorStoreNewParams{

470 Name: openai.String("Support FAQ"),

471 FileIDs: []string{"file_123"},

472 })

473 if err != nil {

474 panic(err)

475 }

476 fmt.Println(vectorStore.ID)

477}

478```

479 

380 480

381 481 

382 482


396)496)

397```497```

398 498 

499```go

500package main

501 

502import (

503 "context"

504 "fmt"

505 

506 "github.com/openai/openai-go/v3"

507)

508 

509func main() {

510 client := openai.NewClient()

511 vectorStore, err := client.VectorStores.Get(context.Background(), "vs_123")

512 if err != nil {

513 panic(err)

514 }

515 fmt.Println(vectorStore.ID)

516}

517```

518 

399 519

400 520 

401 521


418)538)

419```539```

420 540 

541```go

542package main

543 

544import (

545 "context"

546 "fmt"

547 

548 "github.com/openai/openai-go/v3"

549)

550 

551func main() {

552 client := openai.NewClient()

553 vectorStore, err := client.VectorStores.Update(context.Background(), "vs_123", openai.VectorStoreUpdateParams{

554 Name: openai.String("Support FAQ Updated"),

555 })

556 if err != nil {

557 panic(err)

558 }

559 fmt.Println(vectorStore.Name)

560}

561```

562 

421 563

422 564 

423 565


437)579)

438```580```

439 581 

582```go

583package main

584 

585import (

586 "context"

587 "fmt"

588 

589 "github.com/openai/openai-go/v3"

590)

591 

592func main() {

593 client := openai.NewClient()

594 deleted, err := client.VectorStores.Delete(context.Background(), "vs_123")

595 if err != nil {

596 panic(err)

597 }

598 fmt.Println(deleted.Deleted)

599}

600```

601 

440 602

441 603 

442 604


454client.vector_stores.list()616client.vector_stores.list()

455```617```

456 618 

619```go

620package main

621 

622import (

623 "context"

624 "fmt"

625 

626 "github.com/openai/openai-go/v3"

627)

628 

629func main() {

630 client := openai.NewClient()

631 vectorStores, err := client.VectorStores.List(context.Background(), openai.VectorStoreListParams{})

632 if err != nil {

633 panic(err)

634 }

635 fmt.Println(vectorStores.Data)

636}

637```

638 

457 639 

458 640 

459### Vector store file operations641### Vector store file operations


481)663)

482```664```

483 665 

666```go

667package main

668 

669import (

670 "context"

671 "fmt"

672 

673 "github.com/openai/openai-go/v3"

674)

675 

676func main() {

677 client := openai.NewClient()

678 file, err := client.VectorStores.Files.NewAndPoll(context.Background(), "vs_123", openai.VectorStoreFileNewParams{

679 FileID: "file_123",

680 }, 1000)

681 if err != nil {

682 panic(err)

683 }

684 fmt.Println(file.ID)

685}

686```

687 

484 688

485 689 

486 690


504)708)

505```709```

506 710 

711```go

712package main

713 

714import (

715 "context"

716 "fmt"

717 "os"

718 

719 "github.com/openai/openai-go/v3"

720)

721 

722func main() {

723 client := openai.NewClient()

724 file, err := os.Open("customer_policies.txt")

725 if err != nil {

726 panic(err)

727 }

728 defer file.Close()

729 result, err := client.VectorStores.Files.UploadAndPoll(context.Background(), "vs_123", openai.FileNewParams{

730 File: openai.File(file, "customer_policies.txt", "text/plain"),

731 Purpose: openai.FilePurposeAssistants,

732 }, 1000)

733 if err != nil {

734 panic(err)

735 }

736 fmt.Println(result.ID)

737}

738```

739 

507 740

508 741 

509 742


526)759)

527```760```

528 761 

762```go

763package main

764 

765import (

766 "context"

767 "fmt"

768 

769 "github.com/openai/openai-go/v3"

770)

771 

772func main() {

773 client := openai.NewClient()

774 file, err := client.VectorStores.Files.Get(context.Background(), "vs_123", "file_123")

775 if err != nil {

776 panic(err)

777 }

778 fmt.Println(file.ID)

779}

780```

781 

529 782

530 783 

531 784


550)803)

551```804```

552 805 

806```go

807package main

808 

809import (

810 "context"

811 "fmt"

812 

813 "github.com/openai/openai-go/v3"

814)

815 

816func main() {

817 client := openai.NewClient()

818 file, err := client.VectorStores.Files.Update(context.Background(), "vs_123", "file_123", openai.VectorStoreFileUpdateParams{

819 Attributes: map[string]openai.VectorStoreFileUpdateParamsAttributeUnion{

820 "key": {OfString: openai.String("value")},

821 },

822 })

823 if err != nil {

824 panic(err)

825 }

826 fmt.Println(file.ID)

827}

828```

829 

553 830

554 831 

555 832


572)849)

573```850```

574 851 

852```go

853package main

854 

855import (

856 "context"

857 "fmt"

858 

859 "github.com/openai/openai-go/v3"

860)

861 

862func main() {

863 client := openai.NewClient()

864 deleted, err := client.VectorStores.Files.Delete(context.Background(), "vs_123", "file_123")

865 if err != nil {

866 panic(err)

867 }

868 fmt.Println(deleted.Deleted)

869}

870```

871 

575 872

576 873 

577 874


591)888)

592```889```

593 890 

891```go

892package main

893 

894import (

895 "context"

896 "fmt"

897 

898 "github.com/openai/openai-go/v3"

899)

900 

901func main() {

902 client := openai.NewClient()

903 files, err := client.VectorStores.Files.List(context.Background(), "vs_123", openai.VectorStoreFileListParams{})

904 if err != nil {

905 panic(err)

906 }

907 fmt.Println(files.Data)

908}

909```

910 

594 911 

595 912 

596### Batch operations913### Batch operations


642)959)

643```960```

644 961 

962```go

963package main

964 

965import (

966 "context"

967 "fmt"

968 

969 "github.com/openai/openai-go/v3"

970)

971 

972func main() {

973 client := openai.NewClient()

974 batch, err := client.VectorStores.FileBatches.NewAndPoll(context.Background(), "vs_123", openai.VectorStoreFileBatchNewParams{

975 Files: []openai.VectorStoreFileBatchNewParamsFile{

976 {

977 FileID: "file_123",

978 Attributes: map[string]openai.VectorStoreFileBatchNewParamsFileAttributeUnion{

979 "department": {OfString: openai.String("finance")},

980 },

981 },

982 {

983 FileID: "file_456",

984 ChunkingStrategy: openai.FileChunkingStrategyParamUnion{OfStatic: &openai.StaticFileChunkingStrategyObjectParam{

985 Static: openai.StaticFileChunkingStrategyParam{MaxChunkSizeTokens: 1200, ChunkOverlapTokens: 200},

986 }},

987 },

988 },

989 }, 1000)

990 if err != nil {

991 panic(err)

992 }

993 fmt.Println(batch.ID)

994}

995```

996 

645 997

646 998 

647 999


664)1016)

665```1017```

666 1018 

1019```go

1020package main

1021 

1022import (

1023 "context"

1024 "fmt"

1025 

1026 "github.com/openai/openai-go/v3"

1027)

1028 

1029func main() {

1030 client := openai.NewClient()

1031 batch, err := client.VectorStores.FileBatches.Get(context.Background(), "vs_123", "vsfb_123")

1032 if err != nil {

1033 panic(err)

1034 }

1035 fmt.Println(batch.ID)

1036}

1037```

1038 

667 1039

668 1040 

669 1041


686)1058)

687```1059```

688 1060 

1061```go

1062package main

1063 

1064import (

1065 "context"

1066 "fmt"

1067 

1068 "github.com/openai/openai-go/v3"

1069)

1070 

1071func main() {

1072 client := openai.NewClient()

1073 batch, err := client.VectorStores.FileBatches.Cancel(context.Background(), "vs_123", "vsfb_123")

1074 if err != nil {

1075 panic(err)

1076 }

1077 fmt.Println(batch.Status)

1078}

1079```

1080 

689 1081

690 1082 

691 1083


708)1100)

709```1101```

710 1102 

1103```go

1104package main

1105 

1106import (

1107 "context"

1108 "fmt"

1109 

1110 "github.com/openai/openai-go/v3"

1111)

1112 

1113func main() {

1114 client := openai.NewClient()

1115 files, err := client.VectorStores.FileBatches.ListFiles(context.Background(), "vs_123", "vsfb_123", openai.VectorStoreFileBatchListFilesParams{})

1116 if err != nil {

1117 panic(err)

1118 }

1119 fmt.Println(files.Data)

1120}

1121```

1122 

711 1123 

712 1124 

713When creating a batch you can either provide `file_ids` with optional `attributes` and/or `chunking_strategy`, or use the `files` array to pass objects that include a `file_id` plus optional `attributes` and `chunking_strategy` for each file. The two options are mutually exclusive so that you can cleanly control whether every file shares the same settings or you need per-file overrides.1125When creating a batch you can either provide `file_ids` with optional `attributes` and/or `chunking_strategy`, or use the `files` array to pass objects that include a `file_id` plus optional `attributes` and `chunking_strategy` for each file. The two options are mutually exclusive so that you can cleanly control whether every file shares the same settings or you need per-file overrides.


743)1155)

744```1156```

745 1157 

1158```go

1159package main

1160 

1161import (

1162 "context"

1163 "fmt"

1164 

1165 "github.com/openai/openai-go/v3"

1166)

1167 

1168func main() {

1169 client := openai.NewClient()

1170 file, err := client.VectorStores.Files.New(context.Background(), "<vector_store_id>", openai.VectorStoreFileNewParams{

1171 FileID: "file_123",

1172 Attributes: map[string]openai.VectorStoreFileNewParamsAttributeUnion{

1173 "region": {OfString: openai.String("US")},

1174 "category": {OfString: openai.String("Marketing")},

1175 "date": {OfFloat: openai.Float(1672531200)},

1176 },

1177 })

1178 if err != nil {

1179 panic(err)

1180 }

1181 fmt.Println(file.ID)

1182}

1183```

1184 

746 1185 

747### Expiration policies1186### Expiration policies

748 1187 


769)1208)

770```1209```

771 1210 

1211```go

1212package main

1213 

1214import (

1215 "context"

1216 "fmt"

1217 

1218 "github.com/openai/openai-go/v3"

1219)

1220 

1221func main() {

1222 client := openai.NewClient()

1223 vectorStore, err := client.VectorStores.Update(context.Background(), "vs_123", openai.VectorStoreUpdateParams{

1224 ExpiresAfter: openai.VectorStoreUpdateParamsExpiresAfter{Days: 7},

1225 })

1226 if err != nil {

1227 panic(err)

1228 }

1229 fmt.Println(vectorStore.ExpiresAfter)

1230}

1231```

1232 

772 1233 

773### Limits1234### Limits

774 1235 


845)1306)

846```1307```

847 1308 

1309```go

1310package main

1311 

1312import (

1313 "context"

1314 "fmt"

1315 

1316 "github.com/openai/openai-go/v3"

1317)

1318 

1319func main() {

1320 client := openai.NewClient()

1321 results, err := client.VectorStores.Search(context.Background(), "vs_123", openai.VectorStoreSearchParams{

1322 Query: openai.VectorStoreSearchParamsQueryUnion{OfString: openai.String("What is the return policy?")},

1323 })

1324 if err != nil {

1325 panic(err)

1326 }

1327 fmt.Println(results.Data)

1328}

1329```

1330 

848 1331 

849Synthesize a response based on results1332Synthesize a response based on results

850 1333 


895print(completion.choices[0].message.content)1378print(completion.choices[0].message.content)

896```1379```

897 1380 

1381```go

1382package main

1383 

1384import (

1385 "context"

1386 "fmt"

1387 "strings"

1388 

1389 "github.com/openai/openai-go/v3"

1390)

1391 

1392func main() {

1393 client := openai.NewClient()

1394 userQuery := "What is the return policy?"

1395 results, err := client.VectorStores.Search(context.Background(), "vs_123", openai.VectorStoreSearchParams{

1396 Query: openai.VectorStoreSearchParamsQueryUnion{OfString: openai.String(userQuery)},

1397 })

1398 if err != nil {

1399 panic(err)

1400 }

1401 

1402 completion, err := client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{

1403 Model: "gpt-5.6",

1404 Messages: []openai.ChatCompletionMessageParamUnion{

1405 openai.DeveloperMessage("Produce a concise answer to the query based on the provided sources."),

1406 openai.UserMessage(fmt.Sprintf("Sources: %s\n\nQuery: %q", formatResults(results.Data), userQuery)),

1407 },

1408 })

1409 if err != nil {

1410 panic(err)

1411 }

1412 fmt.Println(completion.Choices[0].Message.Content)

1413}

1414 

1415func formatResults(results []openai.VectorStoreSearchResponse) string {

1416 var sources strings.Builder

1417 sources.WriteString("<sources>")

1418 for _, result := range results {

1419 fmt.Fprintf(&sources, "<result file_id=%q file_name=%q>", result.FileID, result.Filename)

1420 for _, content := range result.Content {

1421 fmt.Fprintf(&sources, "<content>%s</content>", content.Text)

1422 }

1423 sources.WriteString("</result>")

1424 }

1425 sources.WriteString("</sources>")

1426 return sources.String()

1427}

1428```

1429 

898 1430 

899```json1431```json

900"Our return policy allows returns within 30 days of purchase."1432"Our return policy allows returns within 30 days of purchase."


931 formatted_results += formatted_result + "</result>"1463 formatted_results += formatted_result + "</result>"

932 return f"<sources>{formatted_results}</sources>"1464 return f"<sources>{formatted_results}</sources>"

933```1465```

1466 

1467```go

1468package main

1469 

1470import (

1471 "fmt"

1472 "strings"

1473 

1474 "github.com/openai/openai-go/v3"

1475)

1476 

1477func main() {

1478 results := []openai.VectorStoreSearchResponse{{

1479 FileID: "file-12345",

1480 Filename: "woodchuck_policy.txt",

1481 Content: []openai.VectorStoreSearchResponseContent{{Text: "Each passenger may carry up to two woodchucks."}},

1482 }}

1483 fmt.Println(formatResults(results))

1484}

1485 

1486func formatResults(results []openai.VectorStoreSearchResponse) string {

1487 var sources strings.Builder

1488 sources.WriteString("<sources>")

1489 for _, result := range results {

1490 fmt.Fprintf(&sources, "<result file_id=%q file_name=%q>", result.FileID, result.Filename)

1491 for _, content := range result.Content {

1492 fmt.Fprintf(&sources, "<content>%s</content>", content.Text)

1493 }

1494 sources.WriteString("</result>")

1495 }

1496 sources.WriteString("</sources>")

1497 return sources.String()

1498}

1499```

Details

75)75)

76```76```

77 77 

78```go

79package main

80 

81import (

82 "context"

83 "fmt"

84 

85 "github.com/openai/openai-go/v3"

86)

87 

88func main() {

89 client := openai.NewClient()

90 response, err := client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{

91 Model: "gpt-5.6",

92 Messages: []openai.ChatCompletionMessageParamUnion{openai.UserMessage("This is a test")},

93 MaxCompletionTokens: openai.Int(5),

94 SafetyIdentifier: openai.String("user_123456"),

95 })

96 if err != nil {

97 panic(err)

98 }

99 fmt.Println(response.Choices[0].Message.Content)

100}

101```

102 

78```bash103```bash

79curl https://api.openai.com/v1/chat/completions \104curl https://api.openai.com/v1/chat/completions \

80-H "Content-Type: application/json" \105-H "Content-Type: application/json" \

Details

45)45)

46```46```

47 47 

48```go

49package main

50 

51import (

52 "context"

53 "fmt"

54 

55 "github.com/openai/openai-go/v3"

56 "github.com/openai/openai-go/v3/responses"

57)

58 

59func main() {

60 client := openai.NewClient()

61 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

62 Model: "gpt-5.6-terra",

63 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("This is a test")},

64 SafetyIdentifier: openai.String("user_123456"),

65 })

66 if err != nil {

67 panic(err)

68 }

69 fmt.Println(response.OutputText())

70}

71```

72 

48```bash73```bash

49curl https://api.openai.com/v1/responses \74curl https://api.openai.com/v1/responses \

50-H "Content-Type: application/json" \75-H "Content-Type: application/json" \


77)102)

78```103```

79 104 

105```go

106package main

107 

108import (

109 "context"

110 "fmt"

111 

112 "github.com/openai/openai-go/v3"

113)

114 

115func main() {

116 client := openai.NewClient()

117 response, err := client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{

118 Model: "gpt-5.6-terra",

119 Messages: []openai.ChatCompletionMessageParamUnion{openai.UserMessage("This is a test")},

120 SafetyIdentifier: openai.String("user_123456"),

121 })

122 if err != nil {

123 panic(err)

124 }

125 fmt.Println(response.Choices[0].Message.Content)

126}

127```

128 

80```bash129```bash

81curl https://api.openai.com/v1/chat/completions \130curl https://api.openai.com/v1/chat/completions \

82-H "Content-Type: application/json" \131-H "Content-Type: application/json" \

Details

46print(transcription.text)46print(transcription.text)

47```47```

48 48 

49```go

50package main

51 

52import (

53 "context"

54 "fmt"

55 "os"

56 

57 "github.com/openai/openai-go/v3"

58)

59 

60func main() {

61 file, err := os.Open("fixtures/audio.wav")

62 if err != nil {

63 panic(err)

64 }

65 defer file.Close()

66 

67 client := openai.NewClient()

68 transcription, err := client.Audio.Transcriptions.New(context.Background(), openai.AudioTranscriptionNewParams{

69 File: file,

70 Model: "gpt-transcribe",

71 })

72 if err != nil {

73 panic(err)

74 }

75 fmt.Println(transcription.Text)

76}

77```

78 

49```bash79```bash

50openai audio:transcriptions create \80openai audio:transcriptions create \

51 --model gpt-transcribe \81 --model gpt-transcribe \


123print(transcription.text)153print(transcription.text)

124```154```

125 155 

156```go

157package main

158 

159import (

160 "context"

161 "fmt"

162 "os"

163 

164 "github.com/openai/openai-go/v3"

165)

166 

167func main() {

168 file, err := os.Open("fixtures/audio.wav")

169 if err != nil {

170 panic(err)

171 }

172 defer file.Close()

173 

174 parameters := openai.AudioTranscriptionNewParams{

175 File: file,

176 Model: "gpt-transcribe",

177 Prompt: openai.String("A customer support call about a premium plan and account AC-42."),

178 }

179 parameters.SetExtraFields(map[string]any{

180 "keywords": []string{"premium plan", "AC-42", "billing"},

181 "languages": []string{"en", "fr"},

182 })

183 client := openai.NewClient()

184 transcription, err := client.Audio.Transcriptions.New(context.Background(), parameters)

185 if err != nil {

186 panic(err)

187 }

188 fmt.Println(transcription.Text)

189}

190```

191 

126```bash192```bash

127curl https://api.openai.com/v1/audio/transcriptions \193curl https://api.openai.com/v1/audio/transcriptions \

128 -H "Authorization: Bearer $OPENAI_API_KEY" \194 -H "Authorization: Bearer $OPENAI_API_KEY" \


214 print(segment.speaker, segment.text, segment.start, segment.end)280 print(segment.speaker, segment.text, segment.start, segment.end)

215```281```

216 282 

283```go

284package main

285 

286import (

287 "context"

288 "encoding/base64"

289 "encoding/json"

290 "fmt"

291 "os"

292 

293 "github.com/openai/openai-go/v3"

294 "github.com/openai/openai-go/v3/shared/constant"

295)

296 

297type diarizedTranscript struct {

298 Segments []struct {

299 Speaker string `json:"speaker"`

300 Text string `json:"text"`

301 Start float64 `json:"start"`

302 End float64 `json:"end"`

303 } `json:"segments"`

304}

305 

306func main() {

307 agentAudio, err := os.ReadFile("fixtures/agent.wav")

308 if err != nil {

309 panic(err)

310 }

311 meeting, err := os.Open("fixtures/meeting.wav")

312 if err != nil {

313 panic(err)

314 }

315 defer meeting.Close()

316 

317 client := openai.NewClient()

318 transcription, err := client.Audio.Transcriptions.New(context.Background(), openai.AudioTranscriptionNewParams{

319 File: meeting,

320 Model: "gpt-4o-transcribe-diarize",

321 ResponseFormat: openai.AudioResponseFormatDiarizedJSON,

322 ChunkingStrategy: openai.AudioTranscriptionNewParamsChunkingStrategyUnion{

323 OfAuto: constant.ValueOf[constant.Auto](),

324 },

325 KnownSpeakerNames: []string{"agent"},

326 KnownSpeakerReferences: []string{"data:audio/wav;base64," + base64.StdEncoding.EncodeToString(agentAudio)},

327 })

328 if err != nil {

329 panic(err)

330 }

331 var result diarizedTranscript

332 if err := json.Unmarshal([]byte(transcription.RawJSON()), &result); err != nil {

333 panic(err)

334 }

335 for _, segment := range result.Segments {

336 fmt.Println(segment.Speaker+":", segment.Text, segment.Start, segment.End)

337 }

338}

339```

340 

217```bash341```bash

218curl --request POST \342curl --request POST \

219 --url https://api.openai.com/v1/audio/transcriptions \343 --url https://api.openai.com/v1/audio/transcriptions \


267print(translation.text)391print(translation.text)

268```392```

269 393 

394```go

395package main

396 

397import (

398 "context"

399 "fmt"

400 "os"

401 

402 "github.com/openai/openai-go/v3"

403)

404 

405func main() {

406 file, err := os.Open("fixtures/german.wav")

407 if err != nil {

408 panic(err)

409 }

410 defer file.Close()

411 

412 client := openai.NewClient()

413 translation, err := client.Audio.Translations.New(context.Background(), openai.AudioTranslationNewParams{

414 File: file,

415 Model: openai.AudioModelWhisper1,

416 })

417 if err != nil {

418 panic(err)

419 }

420 fmt.Println(translation.Text)

421}

422```

423 

270```bash424```bash

271curl --request POST \425curl --request POST \

272 --url https://api.openai.com/v1/audio/translations \426 --url https://api.openai.com/v1/audio/translations \


335print(transcription.words)489print(transcription.words)

336```490```

337 491 

492```go

493package main

494 

495import (

496 "context"

497 "fmt"

498 "os"

499 

500 "github.com/openai/openai-go/v3"

501)

502 

503func main() {

504 file, err := os.Open("fixtures/audio.wav")

505 if err != nil {

506 panic(err)

507 }

508 defer file.Close()

509 

510 client := openai.NewClient()

511 transcription, err := client.Audio.Transcriptions.New(context.Background(), openai.AudioTranscriptionNewParams{

512 File: file,

513 Model: openai.AudioModelWhisper1,

514 ResponseFormat: openai.AudioResponseFormatVerboseJSON,

515 TimestampGranularities: []string{"word"},

516 })

517 if err != nil {

518 panic(err)

519 }

520 fmt.Println(transcription.Words)

521}

522```

523 

338```bash524```bash

339curl https://api.openai.com/v1/audio/transcriptions \525curl https://api.openai.com/v1/audio/transcriptions \

340 -H "Authorization: Bearer $OPENAI_API_KEY" \526 -H "Authorization: Bearer $OPENAI_API_KEY" \


440# highlight-end626# highlight-end

441```627```

442 628 

629```go

630package main

631 

632import (

633 "context"

634 "fmt"

635 "os"

636 

637 "github.com/openai/openai-go/v3"

638)

639 

640func main() {

641 file, err := os.Open("fixtures/speech.wav")

642 if err != nil {

643 panic(err)

644 }

645 defer file.Close()

646 

647 client := openai.NewClient()

648 stream := client.Audio.Transcriptions.NewStreaming(context.Background(), openai.AudioTranscriptionNewParams{

649 File: file,

650 Model: "gpt-transcribe",

651 })

652 for stream.Next() {

653 fmt.Println(stream.Current().Type)

654 }

655 if err := stream.Err(); err != nil {

656 panic(err)

657 }

658}

659```

660 

443```bash661```bash

444curl --request POST \662curl --request POST \

445 --url https://api.openai.com/v1/audio/transcriptions \663 --url https://api.openai.com/v1/audio/transcriptions \


517print(transcription.text)735print(transcription.text)

518```736```

519 737 

738```go

739package main

740 

741import (

742 "context"

743 "fmt"

744 "os"

745 

746 "github.com/openai/openai-go/v3"

747)

748 

749func main() {

750 file, err := os.Open("fixtures/speech.wav")

751 if err != nil {

752 panic(err)

753 }

754 defer file.Close()

755 

756 client := openai.NewClient()

757 var transcription []byte

758 err = client.Post(context.Background(), "audio/transcriptions", openai.AudioTranscriptionNewParams{

759 File: file,

760 Model: openai.AudioModelWhisper1,

761 ResponseFormat: openai.AudioResponseFormatText,

762 Prompt: openai.String("ZyntriQix, Digique Plus, CynapseFive, VortiQore V8, EchoNix Array, OrbitalLink Seven, DigiFractal Matrix, PULSE, RAPT, B.R.I.C.K., Q.U.A.R.T.Z., F.L.I.N.T."),

763 }, &transcription)

764 if err != nil {

765 panic(err)

766 }

767 fmt.Println(string(transcription))

768}

769```

770 

520```bash771```bash

521curl --request POST \772curl --request POST \

522 --url https://api.openai.com/v1/audio/transcriptions \773 --url https://api.openai.com/v1/audio/transcriptions \


596corrected_text = generate_corrected_transcript(0, system_prompt, fake_company_filepath)847corrected_text = generate_corrected_transcript(0, system_prompt, fake_company_filepath)

597```848```

598 849 

850```go

851package main

852 

853import (

854 "context"

855 "fmt"

856 "os"

857 

858 "github.com/openai/openai-go/v3"

859)

860 

861const systemPrompt = `

862You are a helpful assistant for the company ZyntriQix. Your task is

863to correct any spelling discrepancies in the transcribed text. Make

864sure that the names of the following products are spelled correctly:

865ZyntriQix, Digique Plus, CynapseFive, VortiQore V8, EchoNix Array,

866OrbitalLink Seven, DigiFractal Matrix, PULSE, RAPT, B.R.I.C.K.,

867Q.U.A.R.T.Z., F.L.I.N.T. Only add necessary punctuation such as

868periods, commas, and capitalization, and use only the context provided.

869`

870 

871func main() {

872 file, err := os.Open("fixtures/speech.wav")

873 if err != nil {

874 panic(err)

875 }

876 defer file.Close()

877 

878 client := openai.NewClient()

879 transcription, err := client.Audio.Transcriptions.New(context.Background(), openai.AudioTranscriptionNewParams{

880 File: file,

881 Model: openai.AudioModelGPT4oTranscribe,

882 })

883 if err != nil {

884 panic(err)

885 }

886 completion, err := client.Chat.Completions.New(context.Background(), openai.ChatCompletionNewParams{

887 Model: "gpt-4.1",

888 Temperature: openai.Float(0),

889 Messages: []openai.ChatCompletionMessageParamUnion{

890 openai.SystemMessage(systemPrompt),

891 openai.UserMessage(transcription.Text),

892 },

893 Store: openai.Bool(true),

894 })

895 if err != nil {

896 panic(err)

897 }

898 fmt.Println(completion.Choices[0].Message.Content)

899}

900```

901 

599 902 

600A text model can correct misspellings and handle longer terminology lists than Whisper's 224-token prompt window. Evaluate corrections against the original audio to avoid changing what the speaker said.903A text model can correct misspellings and handle longer terminology lists than Whisper's 224-token prompt window. Evaluate corrections against the original audio to avoid changing what the speaker said.

Details

51 print(event)51 print(event)

52```52```

53 53 

54```go

55package main

56 

57import (

58 "context"

59 "fmt"

60 

61 "github.com/openai/openai-go/v3"

62 "github.com/openai/openai-go/v3/responses"

63)

64 

65func main() {

66 client := openai.NewClient()

67 stream := client.Responses.NewStreaming(context.Background(), responses.ResponseNewParams{

68 Model: "gpt-5.6",

69 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Say 'double bubble bath' ten times fast.")},

70 })

71 for stream.Next() {

72 fmt.Println(stream.Current().Type)

73 }

74 if err := stream.Err(); err != nil {

75 panic(err)

76 }

77}

78```

79 

54```csharp80```csharp

55using OpenAI.Responses;81using OpenAI.Responses;

56#pragma warning disable OPENAI00182#pragma warning disable OPENAI001


126)152)

127```153```

128 154 

155```go

156type StreamingEvent = responses.ResponseStreamEventUnion

157```

158 

129 159 

130 160 

131 161 

Details

76event = response.output_parsed76event = response.output_parsed

77```77```

78 78 

79```go

80package main

81 

82import (

83 "context"

84 "fmt"

85 

86 "github.com/openai/openai-go/v3"

87 "github.com/openai/openai-go/v3/responses"

88)

89 

90func main() {

91 client := openai.NewClient()

92 schema := map[string]any{

93 "type": "object",

94 "properties": map[string]any{

95 "name": map[string]any{"type": "string"},

96 "date": map[string]any{"type": "string"},

97 "participants": map[string]any{"type": "array", "items": map[string]any{"type": "string"}},

98 },

99 "required": []string{"name", "date", "participants"},

100 "additionalProperties": false,

101 }

102 

103 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

104 Model: "gpt-5.6",

105 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: responses.ResponseInputParam{

106 responses.ResponseInputItemParamOfMessage(

107 responses.ResponseInputMessageContentListParam{responses.ResponseInputContentParamOfInputText("Extract the event information.")},

108 responses.EasyInputMessageRoleSystem,

109 ),

110 responses.ResponseInputItemParamOfMessage(

111 responses.ResponseInputMessageContentListParam{responses.ResponseInputContentParamOfInputText("Alice and Bob are going to a science fair on Friday.")},

112 responses.EasyInputMessageRoleUser,

113 ),

114 }},

115 Text: responses.ResponseTextConfigParam{Format: responses.ResponseFormatTextConfigUnionParam{

116 OfJSONSchema: &responses.ResponseFormatTextJSONSchemaConfigParam{Name: "event", Schema: schema, Strict: openai.Bool(true)},

117 }},

118 })

119 if err != nil {

120 panic(err)

121 }

122 

123 fmt.Println(response.OutputText())

124}

125```

126 

79 127 

80 128 

81### Supported models129### Supported models


231math_reasoning = response.output_parsed279math_reasoning = response.output_parsed

232```280```

233 281 

282```go

283package main

284 

285import (

286 "context"

287 "fmt"

288 

289 "github.com/openai/openai-go/v3"

290 "github.com/openai/openai-go/v3/responses"

291)

292 

293func main() {

294 client := openai.NewClient()

295 step := map[string]any{

296 "type": "object",

297 "properties": map[string]any{

298 "explanation": map[string]any{"type": "string"},

299 "output": map[string]any{"type": "string"},

300 },

301 "required": []string{"explanation", "output"},

302 "additionalProperties": false,

303 }

304 schema := map[string]any{

305 "type": "object",

306 "properties": map[string]any{

307 "steps": map[string]any{"type": "array", "items": step},

308 "final_answer": map[string]any{"type": "string"},

309 },

310 "required": []string{"steps", "final_answer"},

311 "additionalProperties": false,

312 }

313 

314 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

315 Model: "gpt-5.6",

316 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: responses.ResponseInputParam{

317 responses.ResponseInputItemParamOfMessage(

318 responses.ResponseInputMessageContentListParam{responses.ResponseInputContentParamOfInputText("You are a helpful math tutor. Guide the user through the solution step by step.")},

319 responses.EasyInputMessageRoleSystem,

320 ),

321 responses.ResponseInputItemParamOfMessage(

322 responses.ResponseInputMessageContentListParam{responses.ResponseInputContentParamOfInputText("how can I solve 8x + 7 = -23")},

323 responses.EasyInputMessageRoleUser,

324 ),

325 }},

326 Text: responses.ResponseTextConfigParam{Format: responses.ResponseFormatTextConfigUnionParam{

327 OfJSONSchema: &responses.ResponseFormatTextJSONSchemaConfigParam{Name: "math_reasoning", Schema: schema, Strict: openai.Bool(true)},

328 }},

329 })

330 if err != nil {

331 panic(err)

332 }

333 

334 fmt.Println(response.OutputText())

335}

336```

337 

234```bash338```bash

235curl https://api.openai.com/v1/responses \339curl https://api.openai.com/v1/responses \

236 -H "Authorization: Bearer $OPENAI_API_KEY" \340 -H "Authorization: Bearer $OPENAI_API_KEY" \


398research_paper = response.output_parsed502research_paper = response.output_parsed

399```503```

400 504 

505```go

506package main

507 

508import (

509 "context"

510 "fmt"

511 

512 "github.com/openai/openai-go/v3"

513 "github.com/openai/openai-go/v3/responses"

514)

515 

516const researchPaperText = "Attention Is All You Need by Ashish Vaswani, Noam Shazeer, " +

517 "Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, " +

518 "Łukasz Kaiser, and Illia Polosukhin. We propose the Transformer, " +

519 "a sequence transduction architecture based entirely on attention. " +

520 "Keywords: transformers, attention, sequence transduction."

521 

522func main() {

523 client := openai.NewClient()

524 schema := map[string]any{

525 "type": "object",

526 "properties": map[string]any{

527 "title": map[string]any{"type": "string"},

528 "authors": map[string]any{"type": "array", "items": map[string]any{"type": "string"}},

529 "abstract": map[string]any{"type": "string"},

530 "keywords": map[string]any{"type": "array", "items": map[string]any{"type": "string"}},

531 },

532 "required": []string{"title", "authors", "abstract", "keywords"},

533 "additionalProperties": false,

534 }

535 

536 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

537 Model: "gpt-5.6",

538 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: responses.ResponseInputParam{

539 responses.ResponseInputItemParamOfMessage(

540 responses.ResponseInputMessageContentListParam{responses.ResponseInputContentParamOfInputText("You are an expert at structured data extraction. You will be given unstructured text from a research paper and should convert it into the given structure.")},

541 responses.EasyInputMessageRoleSystem,

542 ),

543 responses.ResponseInputItemParamOfMessage(

544 responses.ResponseInputMessageContentListParam{responses.ResponseInputContentParamOfInputText(researchPaperText)},

545 responses.EasyInputMessageRoleUser,

546 ),

547 }},

548 Text: responses.ResponseTextConfigParam{Format: responses.ResponseFormatTextConfigUnionParam{

549 OfJSONSchema: &responses.ResponseFormatTextJSONSchemaConfigParam{Name: "research_paper_extraction", Schema: schema, Strict: openai.Bool(true)},

550 }},

551 })

552 if err != nil {

553 panic(err)

554 }

555 

556 fmt.Println(response.OutputText())

557}

558```

559 

401```bash560```bash

402curl https://api.openai.com/v1/responses \561curl https://api.openai.com/v1/responses \

403 -H "Authorization: Bearer $OPENAI_API_KEY" \562 -H "Authorization: Bearer $OPENAI_API_KEY" \


574ui = response.output_parsed733ui = response.output_parsed

575```734```

576 735 

736```go

737package main

738 

739import (

740 "context"

741 "fmt"

742 

743 "github.com/openai/openai-go/v3"

744 "github.com/openai/openai-go/v3/responses"

745)

746 

747func main() {

748 client := openai.NewClient()

749 schema := map[string]any{

750 "type": "object",

751 "properties": map[string]any{

752 "type": map[string]any{"type": "string", "enum": []string{"div", "button", "header", "section", "field", "form"}},

753 "label": map[string]any{"type": "string"},

754 "children": map[string]any{"type": "array", "items": map[string]any{"$ref": "#"}},

755 "attributes": map[string]any{"type": "array", "items": map[string]any{"type": "object", "properties": map[string]any{"name": map[string]any{"type": "string"}, "value": map[string]any{"type": "string"}}, "required": []string{"name", "value"}, "additionalProperties": false}},

756 },

757 "required": []string{"type", "label", "children", "attributes"},

758 "additionalProperties": false,

759 }

760 

761 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

762 Model: "gpt-5.6",

763 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: responses.ResponseInputParam{

764 responses.ResponseInputItemParamOfMessage(

765 responses.ResponseInputMessageContentListParam{responses.ResponseInputContentParamOfInputText("You are a UI generator AI. Convert the user input into a UI.")},

766 responses.EasyInputMessageRoleSystem,

767 ),

768 responses.ResponseInputItemParamOfMessage(

769 responses.ResponseInputMessageContentListParam{responses.ResponseInputContentParamOfInputText("Make a User Profile Form")},

770 responses.EasyInputMessageRoleUser,

771 ),

772 }},

773 Text: responses.ResponseTextConfigParam{Format: responses.ResponseFormatTextConfigUnionParam{

774 OfJSONSchema: &responses.ResponseFormatTextJSONSchemaConfigParam{Name: "ui", Description: openai.String("Dynamically generated UI"), Schema: schema, Strict: openai.Bool(true)},

775 }},

776 })

777 if err != nil {

778 panic(err)

779 }

780 

781 fmt.Println(response.OutputText())

782}

783```

784 

577```bash785```bash

578curl https://api.openai.com/v1/responses \786curl https://api.openai.com/v1/responses \

579 -H "Authorization: Bearer $OPENAI_API_KEY" \787 -H "Authorization: Bearer $OPENAI_API_KEY" \


810compliance = response.output_parsed1018compliance = response.output_parsed

811```1019```

812 1020 

1021```go

1022package main

1023 

1024import (

1025 "context"

1026 "fmt"

1027 

1028 "github.com/openai/openai-go/v3"

1029 "github.com/openai/openai-go/v3/responses"

1030)

1031 

1032func main() {

1033 client := openai.NewClient()

1034 schema := contentComplianceSchema()

1035 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

1036 Model: "gpt-5.6",

1037 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: responses.ResponseInputParam{

1038 responses.ResponseInputItemParamOfMessage("Determine if the user input violates specific guidelines and explain if they do.", responses.EasyInputMessageRoleSystem),

1039 responses.ResponseInputItemParamOfMessage("How do I prepare for a job interview?", responses.EasyInputMessageRoleUser),

1040 }},

1041 Text: responses.ResponseTextConfigParam{Format: responses.ResponseFormatTextConfigUnionParam{

1042 OfJSONSchema: &responses.ResponseFormatTextJSONSchemaConfigParam{

1043 Name: "content_compliance", Description: openai.String("Determines if content is violating specific moderation rules"), Schema: schema, Strict: openai.Bool(true),

1044 },

1045 }},

1046 })

1047 if err != nil {

1048 panic(err)

1049 }

1050 fmt.Println(response.OutputText())

1051}

1052 

1053func contentComplianceSchema() map[string]any {

1054 return map[string]any{

1055 "type": "object",

1056 "properties": map[string]any{

1057 "is_violating": map[string]any{"type": "boolean", "description": "Indicates if the content is violating guidelines"},

1058 "category": map[string]any{"type": []string{"string", "null"}, "description": "Type of violation, if the content is violating guidelines. Null otherwise.", "enum": []any{"violence", "sexual", "self_harm", nil}},

1059 "explanation_if_violating": map[string]any{"type": []string{"string", "null"}, "description": "Explanation of why the content is violating"},

1060 },

1061 "required": []string{"is_violating", "category", "explanation_if_violating"},

1062 "additionalProperties": false,

1063 }

1064}

1065```

1066 

813```bash1067```bash

814curl https://api.openai.com/v1/responses \1068curl https://api.openai.com/v1/responses \

815 -H "Authorization: Bearer $OPENAI_API_KEY" \1069 -H "Authorization: Bearer $OPENAI_API_KEY" \


998print(response.output_text)1252print(response.output_text)

999```1253```

1000 1254 

1255```go

1256package main

1257 

1258import (

1259 "context"

1260 "fmt"

1261 

1262 "github.com/openai/openai-go/v3"

1263 "github.com/openai/openai-go/v3/responses"

1264)

1265 

1266func main() {

1267 client := openai.NewClient()

1268 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

1269 Model: "gpt-5.6",

1270 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: responses.ResponseInputParam{

1271 responses.ResponseInputItemParamOfMessage(

1272 responses.ResponseInputMessageContentListParam{responses.ResponseInputContentParamOfInputText("You are a helpful math tutor. Guide the user through the solution step by step.")},

1273 responses.EasyInputMessageRoleSystem,

1274 ),

1275 responses.ResponseInputItemParamOfMessage(

1276 responses.ResponseInputMessageContentListParam{responses.ResponseInputContentParamOfInputText("how can I solve 8x + 7 = -23")},

1277 responses.EasyInputMessageRoleUser,

1278 ),

1279 }},

1280 Text: responses.ResponseTextConfigParam{Format: responses.ResponseFormatTextConfigUnionParam{

1281 OfJSONSchema: &responses.ResponseFormatTextJSONSchemaConfigParam{Name: "math_response", Schema: mathSchema(), Strict: openai.Bool(true)},

1282 }},

1283 })

1284 if err != nil {

1285 panic(err)

1286 }

1287 fmt.Println(response.OutputText())

1288}

1289 

1290func mathSchema() map[string]any {

1291 return map[string]any{

1292 "type": "object",

1293 "properties": map[string]any{

1294 "steps": map[string]any{"type": "array", "items": map[string]any{"type": "object", "properties": map[string]any{"explanation": map[string]any{"type": "string"}, "output": map[string]any{"type": "string"}}, "required": []string{"explanation", "output"}, "additionalProperties": false}},

1295 "final_answer": map[string]any{"type": "string"},

1296 },

1297 "required": []string{"steps", "final_answer"},

1298 "additionalProperties": false,

1299 }

1300}

1301```

1302 

1001```bash1303```bash

1002curl https://api.openai.com/v1/responses \1304curl https://api.openai.com/v1/responses \

1003 -H "Authorization: Bearer $OPENAI_API_KEY" \1305 -H "Authorization: Bearer $OPENAI_API_KEY" \


1201 print(e)1503 print(e)

1202```1504```

1203 1505 

1506```go

1507package main

1508 

1509import (

1510 "context"

1511 "errors"

1512 "fmt"

1513 

1514 "github.com/openai/openai-go/v3"

1515 "github.com/openai/openai-go/v3/responses"

1516)

1517 

1518func main() {

1519 client := openai.NewClient()

1520 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

1521 Model: "gpt-5.6",

1522 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: responses.ResponseInputParam{

1523 responses.ResponseInputItemParamOfMessage(

1524 responses.ResponseInputMessageContentListParam{responses.ResponseInputContentParamOfInputText("You are a helpful math tutor. Guide the user through the solution step by step.")},

1525 responses.EasyInputMessageRoleSystem,

1526 ),

1527 responses.ResponseInputItemParamOfMessage(

1528 responses.ResponseInputMessageContentListParam{responses.ResponseInputContentParamOfInputText("how can I solve 8x + 7 = -23")},

1529 responses.EasyInputMessageRoleUser,

1530 ),

1531 }},

1532 MaxOutputTokens: openai.Int(1024),

1533 Text: responses.ResponseTextConfigParam{Format: responses.ResponseFormatTextConfigUnionParam{

1534 OfJSONSchema: &responses.ResponseFormatTextJSONSchemaConfigParam{Name: "math_response", Schema: mathSchema(), Strict: openai.Bool(true)},

1535 }},

1536 })

1537 if err != nil {

1538 panic(err)

1539 }

1540 if response.Status == "incomplete" {

1541 panic(errors.New("incomplete response"))

1542 }

1543 

1544 for _, output := range response.Output {

1545 if output.Type != "message" {

1546 continue

1547 }

1548 for _, content := range output.AsMessage().Content {

1549 if content.Type == "refusal" {

1550 fmt.Println(content.AsRefusal().Refusal)

1551 return

1552 }

1553 if content.Type == "output_text" {

1554 fmt.Println(content.AsOutputText().Text)

1555 return

1556 }

1557 }

1558 }

1559 panic(errors.New("no response content"))

1560}

1561 

1562func mathSchema() map[string]any {

1563 return map[string]any{

1564 "type": "object",

1565 "properties": map[string]any{

1566 "steps": map[string]any{"type": "array", "items": map[string]any{"type": "object", "properties": map[string]any{"explanation": map[string]any{"type": "string"}, "output": map[string]any{"type": "string"}}, "required": []string{"explanation", "output"}, "additionalProperties": false}},

1567 "final_answer": map[string]any{"type": "string"},

1568 },

1569 "required": []string{"steps", "final_answer"},

1570 "additionalProperties": false,

1571 }

1572}

1573```

1574 

1204 1575 

1205 1576 

1206 1577 


1304 print(item.parsed)1675 print(item.parsed)

1305```1676```

1306 1677 

1678```go

1679package main

1680 

1681import (

1682 "context"

1683 "fmt"

1684 

1685 "github.com/openai/openai-go/v3"

1686 "github.com/openai/openai-go/v3/responses"

1687)

1688 

1689func main() {

1690 client := openai.NewClient()

1691 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

1692 Model: "gpt-5.6",

1693 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: responses.ResponseInputParam{

1694 responses.ResponseInputItemParamOfMessage(

1695 responses.ResponseInputMessageContentListParam{responses.ResponseInputContentParamOfInputText("You are a helpful math tutor. Guide the user through the solution step by step.")},

1696 responses.EasyInputMessageRoleSystem,

1697 ),

1698 responses.ResponseInputItemParamOfMessage(

1699 responses.ResponseInputMessageContentListParam{responses.ResponseInputContentParamOfInputText("how can I solve 8x + 7 = -23")},

1700 responses.EasyInputMessageRoleUser,

1701 ),

1702 }},

1703 Text: responses.ResponseTextConfigParam{Format: responses.ResponseFormatTextConfigUnionParam{

1704 OfJSONSchema: &responses.ResponseFormatTextJSONSchemaConfigParam{Name: "math_response", Schema: mathSchema(), Strict: openai.Bool(true)},

1705 }},

1706 })

1707 if err != nil {

1708 panic(err)

1709 }

1710 

1711 for _, output := range response.Output {

1712 if output.Type != "message" {

1713 continue

1714 }

1715 for _, content := range output.AsMessage().Content {

1716 if content.Type == "refusal" {

1717 fmt.Println(content.AsRefusal().Refusal)

1718 continue

1719 }

1720 fmt.Println(content.AsOutputText().Text)

1721 }

1722 }

1723}

1724 

1725func mathSchema() map[string]any {

1726 return map[string]any{

1727 "type": "object",

1728 "properties": map[string]any{

1729 "steps": map[string]any{"type": "array", "items": map[string]any{"type": "object", "properties": map[string]any{"explanation": map[string]any{"type": "string"}, "output": map[string]any{"type": "string"}}, "required": []string{"explanation", "output"}, "additionalProperties": false}},

1730 "final_answer": map[string]any{"type": "string"},

1731 },

1732 "required": []string{"steps", "final_answer"},

1733 "additionalProperties": false,

1734 }

1735}

1736```

1737 

1307 1738 

1308 1739 

1309The API response from a refusal will look something like this:1740The API response from a refusal will look something like this:


2105 print(e)2536 print(e)

2106```2537```

2107 2538 

2539```go

2540package main

2541 

2542import (

2543 "context"

2544 "encoding/json"

2545 "fmt"

2546 

2547 "github.com/openai/openai-go/v3"

2548 "github.com/openai/openai-go/v3/responses"

2549 "github.com/openai/openai-go/v3/shared"

2550)

2551 

2552func main() {

2553 client := openai.NewClient()

2554 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

2555 Model: "gpt-5.6",

2556 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: responses.ResponseInputParam{

2557 responses.ResponseInputItemParamOfMessage(

2558 responses.ResponseInputMessageContentListParam{responses.ResponseInputContentParamOfInputText("You are a helpful assistant designed to output JSON.")},

2559 responses.EasyInputMessageRoleSystem,

2560 ),

2561 responses.ResponseInputItemParamOfMessage(

2562 responses.ResponseInputMessageContentListParam{responses.ResponseInputContentParamOfInputText("Who won the world series in 2020? Please respond in the format {winner: ...}")},

2563 responses.EasyInputMessageRoleUser,

2564 ),

2565 }},

2566 Text: responses.ResponseTextConfigParam{Format: responses.ResponseFormatTextConfigUnionParam{

2567 OfJSONObject: &shared.ResponseFormatJSONObjectParam{},

2568 }},

2569 })

2570 if err != nil {

2571 panic(err)

2572 }

2573 

2574 if response.Status == "incomplete" {

2575 fmt.Println("The JSON response is incomplete.")

2576 return

2577 }

2578 for _, output := range response.Output {

2579 if output.Type != "message" {

2580 continue

2581 }

2582 for _, content := range output.AsMessage().Content {

2583 if content.Type == "refusal" {

2584 fmt.Println(content.AsRefusal().Refusal)

2585 return

2586 }

2587 }

2588 }

2589 if response.Status == "completed" {

2590 var value map[string]any

2591 if err := json.Unmarshal([]byte(response.OutputText()), &value); err != nil {

2592 panic(err)

2593 }

2594 fmt.Println(value)

2595 }

2596}

2597```

2598 

2108## Resources2599## Resources

2109 2600 

2110To learn more about Structured Outputs, we recommend browsing the following resources:2601To learn more about Structured Outputs, we recommend browsing the following resources:

guides/text.md +1 −4

Details

41 "fmt"41 "fmt"

42 42 

43 "github.com/openai/openai-go/v3"43 "github.com/openai/openai-go/v3"

44 "github.com/openai/openai-go/v3/option"

45 "github.com/openai/openai-go/v3/responses"44 "github.com/openai/openai-go/v3/responses"

46)45)

47 46 

48func main() {47func main() {

49 client := openai.NewClient(48 client := openai.NewClient()

50 option.WithAPIKey("My API Key"), // or set OPENAI_API_KEY in your env

51 )

52 49 

53 resp, err := client.Responses.New(context.TODO(), responses.ResponseNewParams{50 resp, err := client.Responses.New(context.TODO(), responses.ResponseNewParams{

54 Model: "gpt-5.6",51 Model: "gpt-5.6",

Details

61 response.stream_to_file(speech_file_path)61 response.stream_to_file(speech_file_path)

62```62```

63 63 

64```go

65package main

66 

67import (

68 "context"

69 "io"

70 "os"

71 

72 "github.com/openai/openai-go/v3"

73)

74 

75func main() {

76 client := openai.NewClient()

77 response, err := client.Audio.Speech.New(context.Background(), openai.AudioSpeechNewParams{

78 Model: openai.SpeechModelGPT4oMiniTTS,

79 Voice: openai.AudioSpeechNewParamsVoiceUnion{OfAudioSpeechNewsVoiceString2: openai.String("coral")},

80 Input: "Today is a wonderful day to build something people love!",

81 Instructions: openai.String("Speak in a cheerful and positive tone."),

82 })

83 if err != nil {

84 panic(err)

85 }

86 defer response.Body.Close()

87 

88 file, err := os.Create("speech.mp3")

89 if err != nil {

90 panic(err)

91 }

92 if _, err := io.Copy(file, response.Body); err != nil {

93 panic(err)

94 }

95 if err := file.Close(); err != nil {

96 panic(err)

97 }

98}

99```

100 

64```bash101```bash

65curl https://api.openai.com/v1/audio/speech \102curl https://api.openai.com/v1/audio/speech \

66 -H "Authorization: Bearer $OPENAI_API_KEY" \103 -H "Authorization: Bearer $OPENAI_API_KEY" \


171 asyncio.run(main())208 asyncio.run(main())

172```209```

173 210 

211```go

212package main

213 

214import (

215 "context"

216 "io"

217 "os"

218 

219 "github.com/openai/openai-go/v3"

220)

221 

222func main() {

223 client := openai.NewClient()

224 response, err := client.Audio.Speech.New(context.Background(), openai.AudioSpeechNewParams{

225 Model: openai.SpeechModelGPT4oMiniTTS,

226 Voice: openai.AudioSpeechNewParamsVoiceUnion{OfAudioSpeechNewsVoiceString2: openai.String("coral")},

227 Input: "Today is a wonderful day to build something people love!",

228 Instructions: openai.String("Speak in a cheerful and positive tone."),

229 ResponseFormat: openai.AudioSpeechNewParamsResponseFormatWAV,

230 })

231 if err != nil {

232 panic(err)

233 }

234 defer response.Body.Close()

235 if _, err := io.Copy(os.Stdout, response.Body); err != nil {

236 panic(err)

237 }

238}

239```

240 

174```bash241```bash

175curl https://api.openai.com/v1/audio/speech \242curl https://api.openai.com/v1/audio/speech \

176 -H "Authorization: Bearer $OPENAI_API_KEY" \243 -H "Authorization: Bearer $OPENAI_API_KEY" \

Details

51print(response.input_tokens)51print(response.input_tokens)

52```52```

53 53 

54```go

55package main

56 

57import (

58 "context"

59 "fmt"

60 

61 "github.com/openai/openai-go/v3"

62 "github.com/openai/openai-go/v3/responses"

63)

64 

65func main() {

66 client := openai.NewClient()

67 count, err := client.Responses.InputTokens.Count(context.Background(), responses.InputTokenCountParams{

68 Model: openai.String("gpt-5.6"),

69 Input: responses.InputTokenCountParamsInputUnion{OfString: openai.String("Tell me a joke.")},

70 })

71 if err != nil {

72 panic(err)

73 }

74 fmt.Println(count.InputTokens)

75}

76```

77 

54```bash78```bash

55curl https://api.openai.com/v1/responses/input_tokens \79curl https://api.openai.com/v1/responses/input_tokens \

56 -H "Authorization: Bearer $OPENAI_API_KEY" \80 -H "Authorization: Bearer $OPENAI_API_KEY" \


107print(response.input_tokens)131print(response.input_tokens)

108```132```

109 133 

134```go

135package main

136 

137import (

138 "context"

139 "fmt"

140 

141 "github.com/openai/openai-go/v3"

142 "github.com/openai/openai-go/v3/responses"

143)

144 

145func main() {

146 client := openai.NewClient()

147 input := []responses.ResponseInputItemUnionParam{

148 responses.ResponseInputItemParamOfMessage("What is 2 + 2?", responses.EasyInputMessageRoleUser),

149 responses.ResponseInputItemParamOfMessage("2 + 2 equals 4.", responses.EasyInputMessageRoleAssistant),

150 responses.ResponseInputItemParamOfMessage("What about 3 + 3?", responses.EasyInputMessageRoleUser),

151 }

152 count, err := client.Responses.InputTokens.Count(context.Background(), responses.InputTokenCountParams{

153 Model: openai.String("gpt-5.6"),

154 Input: responses.InputTokenCountParamsInputUnion{OfResponseInputItemArray: input},

155 })

156 if err != nil {

157 panic(err)

158 }

159 fmt.Println(count.InputTokens)

160}

161```

162 

110```bash163```bash

111curl https://api.openai.com/v1/responses/input_tokens \164curl https://api.openai.com/v1/responses/input_tokens \

112 -H "Authorization: Bearer $OPENAI_API_KEY" \165 -H "Authorization: Bearer $OPENAI_API_KEY" \


168print(response.input_tokens)221print(response.input_tokens)

169```222```

170 223 

224```go

225package main

226 

227import (

228 "context"

229 "fmt"

230 

231 "github.com/openai/openai-go/v3"

232 "github.com/openai/openai-go/v3/responses"

233)

234 

235func main() {

236 client := openai.NewClient()

237 count, err := client.Responses.InputTokens.Count(context.Background(), responses.InputTokenCountParams{

238 Model: openai.String("gpt-5.6"),

239 Instructions: openai.String("You are a helpful assistant that explains concepts simply."),

240 Input: responses.InputTokenCountParamsInputUnion{OfString: openai.String("Explain quantum computing in one sentence.")},

241 })

242 if err != nil {

243 panic(err)

244 }

245 fmt.Println(count.InputTokens)

246}

247```

248 

171```bash249```bash

172curl https://api.openai.com/v1/responses/input_tokens \250curl https://api.openai.com/v1/responses/input_tokens \

173 -H "Authorization: Bearer $OPENAI_API_KEY" \251 -H "Authorization: Bearer $OPENAI_API_KEY" \


245print(response.input_tokens)323print(response.input_tokens)

246```324```

247 325 

326```go

327package main

328 

329import (

330 "context"

331 "fmt"

332 

333 "github.com/openai/openai-go/v3"

334 "github.com/openai/openai-go/v3/responses"

335)

336 

337func main() {

338 client := openai.NewClient()

339 input := []responses.ResponseInputItemUnionParam{

340 responses.ResponseInputItemParamOfMessage(

341 responses.ResponseInputMessageContentListParam{

342 {OfInputImage: &responses.ResponseInputImageParam{ImageURL: openai.String("https://example.com/chart.png"), Detail: responses.ResponseInputImageDetailAuto}},

343 {OfInputText: &responses.ResponseInputTextParam{Text: "Summarize this chart."}},

344 },

345 responses.EasyInputMessageRoleUser,

346 ),

347 }

348 count, err := client.Responses.InputTokens.Count(context.Background(), responses.InputTokenCountParams{

349 Model: openai.String("gpt-5.6"),

350 Input: responses.InputTokenCountParamsInputUnion{OfResponseInputItemArray: input},

351 })

352 if err != nil {

353 panic(err)

354 }

355 fmt.Println(count.InputTokens)

356}

357```

358 

248```bash359```bash

249curl https://api.openai.com/v1/responses/input_tokens \360curl https://api.openai.com/v1/responses/input_tokens \

250 -H "Authorization: Bearer $OPENAI_API_KEY" \361 -H "Authorization: Bearer $OPENAI_API_KEY" \


336print(response.input_tokens)447print(response.input_tokens)

337```448```

338 449 

450```go

451package main

452 

453import (

454 "context"

455 "fmt"

456 

457 "github.com/openai/openai-go/v3"

458 "github.com/openai/openai-go/v3/responses"

459)

460 

461func main() {

462 client := openai.NewClient()

463 parameters := map[string]any{

464 "type": "object",

465 "properties": map[string]any{

466 "location": map[string]any{"type": "string"},

467 },

468 "required": []string{"location"},

469 "additionalProperties": false,

470 }

471 tool := responses.ToolParamOfFunction("get_weather", parameters, true)

472 tool.OfFunction.Description = openai.String("Get the current weather in a location")

473 count, err := client.Responses.InputTokens.Count(context.Background(), responses.InputTokenCountParams{

474 Model: openai.String("gpt-5.6"),

475 Input: responses.InputTokenCountParamsInputUnion{OfString: openai.String("What is the weather in San Francisco?")},

476 Tools: []responses.ToolUnionParam{tool},

477 })

478 if err != nil {

479 panic(err)

480 }

481 fmt.Println(count.InputTokens)

482}

483```

484 

339```bash485```bash

340curl https://api.openai.com/v1/responses/input_tokens \486curl https://api.openai.com/v1/responses/input_tokens \

341 -H "Authorization: Bearer $OPENAI_API_KEY" \487 -H "Authorization: Bearer $OPENAI_API_KEY" \

guides/tools.md +167 −0

Details

37print(response.output_text)37print(response.output_text)

38```38```

39 39 

40```go

41package main

42 

43import (

44 "context"

45 "fmt"

46 

47 "github.com/openai/openai-go/v3"

48 "github.com/openai/openai-go/v3/responses"

49)

50 

51func main() {

52 client := openai.NewClient()

53 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

54 Model: "gpt-5.6",

55 Tools: []responses.ToolUnionParam{

56 responses.ToolParamOfWebSearch(responses.WebSearchToolTypeWebSearch),

57 },

58 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("What was a positive news story from today?")},

59 })

60 if err != nil {

61 panic(err)

62 }

63 fmt.Println(response.OutputText())

64}

65```

66 

40```csharp67```csharp

41using OpenAI.Responses;68using OpenAI.Responses;

42#pragma warning disable OPENAI00169#pragma warning disable OPENAI001


130print(response)157print(response)

131```158```

132 159 

160```go

161package main

162 

163import (

164 "context"

165 "fmt"

166 

167 "github.com/openai/openai-go/v3"

168 "github.com/openai/openai-go/v3/responses"

169)

170 

171func main() {

172 client := openai.NewClient()

173 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

174 Model: "gpt-5.6",

175 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("What is deep research by OpenAI?")},

176 Tools: []responses.ToolUnionParam{responses.ToolParamOfFileSearch([]string{"<vector_store_id>"})},

177 })

178 if err != nil {

179 panic(err)

180 }

181 fmt.Println(response)

182}

183```

184 

133```csharp185```csharp

134using OpenAI.Responses;186using OpenAI.Responses;

135#pragma warning disable OPENAI001187#pragma warning disable OPENAI001


290print(response.output)342print(response.output)

291```343```

292 344 

345```go

346package main

347 

348import (

349 "context"

350 "fmt"

351 

352 "github.com/openai/openai-go/v3"

353 "github.com/openai/openai-go/v3/responses"

354)

355 

356func main() {

357 client := openai.NewClient()

358 parameters := map[string]any{

359 "type": "object",

360 "properties": map[string]any{"customer_id": map[string]any{"type": "string"}},

361 "required": []string{"customer_id"},

362 "additionalProperties": false,

363 }

364 namespace := responses.ToolParamOfNamespace(

365 "CRM tools for customer lookup and order management.",

366 "crm",

367 []responses.NamespaceToolToolUnionParam{

368 {OfFunction: &responses.NamespaceToolToolFunctionParam{

369 Name: "get_customer_profile", Description: openai.String("Fetch a customer profile by customer ID."), Parameters: parameters,

370 }},

371 {OfFunction: &responses.NamespaceToolToolFunctionParam{

372 Name: "list_open_orders", Description: openai.String("List open orders for a customer ID."), DeferLoading: openai.Bool(true), Parameters: parameters,

373 }},

374 },

375 )

376 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

377 Model: "gpt-5.6",

378 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("List open orders for customer CUST-12345.")},

379 Tools: []responses.ToolUnionParam{namespace, {OfToolSearch: &responses.ToolSearchToolParam{}}},

380 ParallelToolCalls: openai.Bool(false),

381 })

382 if err != nil {

383 panic(err)

384 }

385 fmt.Println(response.Output)

386}

387```

388 

293 389

294 390 

295 391


371print(response.output[0].to_json())467print(response.output[0].to_json())

372```468```

373 469 

470```go

471package main

472 

473import (

474 "context"

475 "fmt"

476 

477 "github.com/openai/openai-go/v3"

478 "github.com/openai/openai-go/v3/responses"

479)

480 

481func main() {

482 client := openai.NewClient()

483 parameters := map[string]any{

484 "type": "object",

485 "properties": map[string]any{

486 "location": map[string]any{

487 "type": "string",

488 "description": "City and country e.g. Bogotá, Colombia",

489 },

490 },

491 "required": []string{"location"},

492 "additionalProperties": false,

493 }

494 tool := responses.ToolParamOfFunction("get_weather", parameters, true)

495 tool.OfFunction.Description = openai.String("Get current temperature for a given location.")

496 

497 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

498 Model: "gpt-5.6",

499 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: responses.ResponseInputParam{

500 responses.ResponseInputItemParamOfMessage("What is the weather like in Paris today?", responses.EasyInputMessageRoleUser),

501 }},

502 Tools: []responses.ToolUnionParam{tool},

503 })

504 if err != nil {

505 panic(err)

506 }

507 fmt.Println(response.Output)

508}

509```

510 

374```csharp511```csharp

375using System.Text.Json;512using System.Text.Json;

376using System.Text.Json.Serialization.Metadata;513using System.Text.Json.Serialization.Metadata;


559print(resp.output_text)696print(resp.output_text)

560```697```

561 698 

699```go

700package main

701 

702import (

703 "context"

704 "fmt"

705 

706 "github.com/openai/openai-go/v3"

707 "github.com/openai/openai-go/v3/responses"

708)

709 

710func main() {

711 client := openai.NewClient()

712 tool := responses.ToolParamOfMcp("dmcp")

713 tool.OfMcp.ServerDescription = openai.String("A Dungeons and Dragons MCP server to assist with dice rolling.")

714 tool.OfMcp.ServerURL = openai.String("https://dmcp-server.deno.dev/mcp")

715 tool.OfMcp.RequireApproval = responses.ToolMcpRequireApprovalUnionParam{OfMcpToolApprovalSetting: openai.String("never")}

716 

717 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

718 Model: "gpt-5.6",

719 Tools: []responses.ToolUnionParam{tool},

720 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Roll 2d4+1")},

721 })

722 if err != nil {

723 panic(err)

724 }

725 fmt.Println(response.OutputText())

726}

727```

728 

562```csharp729```csharp

563using OpenAI.Responses;730using OpenAI.Responses;

564#pragma warning disable OPENAI001731#pragma warning disable OPENAI001

Details

89]89]

90```90```

91 91 

92```go

93response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

94 Model: "gpt-5.6",

95 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String(responseInput)},

96 Tools: []responses.ToolUnionParam{{OfApplyPatch: &responses.ApplyPatchToolParam{}}},

97})

98if err != nil {

99 panic(err)

100}

101patchCalls := make([]responses.ResponseOutputItemUnion, 0)

102for _, item := range response.Output {

103 if item.Type == "apply_patch_call" {

104 patchCalls = append(patchCalls, item)

105 }

106}

107```

108 

92 109 

93**Example `apply_patch_call` object**110**Example `apply_patch_call` object**

94 111 


145)162)

146```163```

147 164 

165```go

166results := make(responses.ResponseInputParam, 0, len(patchCalls))

167for _, call := range patchCalls {

168 success, logOutput := applyOperation(call.Operation)

169 status := "completed"

170 if !success {

171 status = "failed"

172 }

173 result := responses.ResponseInputItemParamOfApplyPatchCallOutput(call.CallID, status)

174 result.OfApplyPatchCallOutput.Output = openai.String(logOutput)

175 results = append(results, result)

176}

177_, err = client.Responses.New(context.Background(), responses.ResponseNewParams{

178 Model: "gpt-5.6",

179 PreviousResponseID: openai.String(response.ID),

180 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: results},

181 Tools: []responses.ToolUnionParam{{OfApplyPatch: &responses.ApplyPatchToolParam{}}},

182})

183if err != nil {

184 panic(err)

185}

186```

187 

148 188 

149If a patch fails (for example, file not found), set `status: "failed"` and include a helpful `output` string so the model can recover:189If a patch fails (for example, file not found), set `status: "failed"` and include a helpful `output` string so the model can recover:

150 190 

Details

77print(resp.output)77print(resp.output)

78```78```

79 79 

80```go

81package main

82 

83import (

84 "context"

85 "fmt"

86 

87 "github.com/openai/openai-go/v3"

88 "github.com/openai/openai-go/v3/responses"

89)

90 

91func main() {

92 client := openai.NewClient()

93 tool := responses.ToolParamOfCodeInterpreter(responses.ToolCodeInterpreterContainerCodeInterpreterContainerAutoParam{MemoryLimit: "4g"})

94 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

95 Model: "gpt-5.6",

96 Tools: []responses.ToolUnionParam{tool},

97 Instructions: openai.String("You are a personal math tutor. When asked a math question, write and run code using the python tool to answer the question."),

98 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("I need to solve the equation 3x + 11 = 14. Can you help me?")},

99 })

100 if err != nil {

101 panic(err)

102 }

103 fmt.Println(response.Output)

104}

105```

106 

80 107 

81While we call this tool Code Interpreter, the model knows it as the "python108While we call this tool Code Interpreter, the model knows it as the "python

82 tool". Models usually understand prompts that refer to the code interpreter109 tool". Models usually understand prompts that refer to the code interpreter


160print(response.output_text)187print(response.output_text)

161```188```

162 189 

190```go

191package main

192 

193import (

194 "context"

195 "fmt"

196 

197 "github.com/openai/openai-go/v3"

198 "github.com/openai/openai-go/v3/responses"

199)

200 

201func main() {

202 client := openai.NewClient()

203 container, err := client.Containers.New(context.Background(), openai.ContainerNewParams{

204 Name: "test-container",

205 MemoryLimit: openai.ContainerNewParamsMemoryLimit4g,

206 })

207 if err != nil {

208 panic(err)

209 }

210 defer func() {

211 if err := client.Containers.Delete(context.Background(), container.ID); err != nil {

212 panic(err)

213 }

214 }()

215 

216 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

217 Model: "gpt-5.6",

218 Tools: []responses.ToolUnionParam{responses.ToolParamOfCodeInterpreter(container.ID)},

219 ToolChoice: responses.ResponseNewParamsToolChoiceUnion{OfToolChoiceMode: openai.Opt(responses.ToolChoiceOptionsRequired)},

220 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("use the python tool to calculate what is 4 * 3.82. and then find its square root and then find the square root of that result")},

221 })

222 if err != nil {

223 panic(err)

224 }

225 fmt.Println(response.OutputText())

226}

227```

228 

163 229 

164You can choose from `1g` (default), `4g`, `16g`, or `64g`. Higher tiers offer more RAM for the session and are billed at the [built-in tools rates](https://developers.openai.com/api/docs/pricing#built-in-tools) for Code Interpreter. The selected `memory_limit` applies for the entire life of that container, whether it was created automatically or via the containers API.230You can choose from `1g` (default), `4g`, `16g`, or `64g`. Higher tiers offer more RAM for the session and are billed at the [built-in tools rates](https://developers.openai.com/api/docs/pricing#built-in-tools) for Code Interpreter. The selected `memory_limit` applies for the entire life of that container, whether it was created automatically or via the containers API.

165 231 

Details

250print(response.output)250print(response.output)

251```251```

252 252 

253```go

254package main

255 

256import (

257 "context"

258 "fmt"

259 

260 "github.com/openai/openai-go/v3"

261 "github.com/openai/openai-go/v3/responses"

262)

263 

264func main() {

265 client := openai.NewClient()

266 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

267 Model: "gpt-5.6",

268 Tools: []responses.ToolUnionParam{{OfComputer: &responses.ComputerToolParam{}}},

269 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Check whether the Filters panel is open. If it is not open, click Show filters. Then type penguin in the search box. Use the computer tool for UI interaction.")},

270 })

271 if err != nil {

272 panic(err)

273 }

274 fmt.Println(response.Output)

275}

276```

277 

253 278 

254The first turn often asks for a screenshot before the model commits to UI actions. That's normal.279The first turn often asks for a screenshot before the model commits to UI actions. That's normal.

255 280 


1637 )1662 )

1638```1663```

1639 1664 

1665```go

1666package main

1667 

1668import (

1669 "context"

1670 "fmt"

1671 

1672 "github.com/openai/openai-go/v3"

1673 "github.com/openai/openai-go/v3/responses"

1674)

1675 

1676func main() {

1677 client := openai.NewClient()

1678 response, err := sendComputerScreenshot(client, "resp_abc123", "call_abc123", "<base64 bytes here>")

1679 if err != nil {

1680 panic(err)

1681 }

1682 fmt.Println(response.Output)

1683}

1684 

1685func sendComputerScreenshot(client openai.Client, responseID string, callID string, screenshotBase64 string) (*responses.Response, error) {

1686 screenshot := responses.ResponseComputerToolCallOutputScreenshotParam{

1687 ImageURL: openai.String("data:image/png;base64," + screenshotBase64),

1688 }

1689 screenshot.SetExtraFields(map[string]any{"detail": "original"})

1690 return client.Responses.New(context.Background(), responses.ResponseNewParams{

1691 Model: "gpt-5.6",

1692 Tools: []responses.ToolUnionParam{{OfComputer: &responses.ComputerToolParam{}}},

1693 PreviousResponseID: openai.String(responseID),

1694 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: responses.ResponseInputParam{

1695 responses.ResponseInputItemParamOfComputerCallOutput(callID, screenshot),

1696 }},

1697 })

1698}

1699```

1700 

1640 1701 

1641### 5. Repeat until the tool stops calling1702### 5. Repeat until the tool stops calling

1642 1703 


2521)2582)

2522```2583```

2523 2584 

2585```go

2586package main

2587 

2588import (

2589 "context"

2590 "fmt"

2591 

2592 "github.com/openai/openai-go/v3"

2593 "github.com/openai/openai-go/v3/responses"

2594)

2595 

2596func main() {

2597 client := openai.NewClient()

2598 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

2599 Model: "computer-use-preview",

2600 Tools: []responses.ToolUnionParam{responses.ToolParamOfComputerUsePreview(768, 1024, responses.ComputerUsePreviewToolEnvironmentBrowser)},

2601 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Check whether the Filters panel is open.")},

2602 Truncation: responses.ResponseNewParamsTruncationAuto,

2603 })

2604 if err != nil {

2605 panic(err)

2606 }

2607 fmt.Println(response.Output)

2608}

2609```

2610 

2524 2611 

2525Keep the preview path only to maintain older integrations. For new implementations, use the GA flow described above.2612Keep the preview path only to maintain older integrations. For new implementations, use the GA flow described above.

2526 2613 

Details

94print(resp.output_text)94print(resp.output_text)

95```95```

96 96 

97```go

98package main

99 

100import (

101 "context"

102 "fmt"

103 

104 "github.com/openai/openai-go/v3"

105 "github.com/openai/openai-go/v3/responses"

106)

107 

108func main() {

109 client := openai.NewClient()

110 tool := responses.ToolParamOfMcp("dmcp")

111 tool.OfMcp.ServerDescription = openai.String("A Dungeons and Dragons MCP server to assist with dice rolling.")

112 tool.OfMcp.ServerURL = openai.String("https://dmcp-server.deno.dev/mcp")

113 tool.OfMcp.RequireApproval = responses.ToolMcpRequireApprovalUnionParam{OfMcpToolApprovalSetting: openai.String("never")}

114 

115 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

116 Model: "gpt-5.6",

117 Tools: []responses.ToolUnionParam{tool},

118 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Roll 2d4+1")},

119 })

120 if err != nil {

121 panic(err)

122 }

123 fmt.Println(response.OutputText())

124}

125```

126 

97```csharp127```csharp

98using OpenAI.Responses;128using OpenAI.Responses;

99#pragma warning disable OPENAI001129#pragma warning disable OPENAI001


225print(resp.output_text)255print(resp.output_text)

226```256```

227 257 

258```go

259package main

260 

261import (

262 "context"

263 "fmt"

264 

265 "github.com/openai/openai-go/v3"

266 "github.com/openai/openai-go/v3/responses"

267)

268 

269func main() {

270 client := openai.NewClient()

271 tool := responses.ToolParamOfMcp("Dropbox")

272 tool.OfMcp.ConnectorID = "connector_dropbox"

273 tool.OfMcp.Authorization = openai.String("<oauth access token>")

274 tool.OfMcp.RequireApproval = responses.ToolMcpRequireApprovalUnionParam{OfMcpToolApprovalSetting: openai.String("never")}

275 

276 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

277 Model: "gpt-5.6",

278 Tools: []responses.ToolUnionParam{tool},

279 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Summarize the Q2 earnings report.")},

280 })

281 if err != nil {

282 panic(err)

283 }

284 fmt.Println(response.OutputText())

285}

286```

287 

228```csharp288```csharp

229using OpenAI.Responses;289using OpenAI.Responses;

230#pragma warning disable OPENAI001290#pragma warning disable OPENAI001


415print(resp.output_text)475print(resp.output_text)

416```476```

417 477 

478```go

479package main

480 

481import (

482 "context"

483 "fmt"

484 

485 "github.com/openai/openai-go/v3"

486 "github.com/openai/openai-go/v3/responses"

487)

488 

489func main() {

490 client := openai.NewClient()

491 tool := responses.ToolParamOfMcp("dmcp")

492 tool.OfMcp.ServerDescription = openai.String("A Dungeons and Dragons MCP server to assist with dice rolling.")

493 tool.OfMcp.ServerURL = openai.String("https://dmcp-server.deno.dev/mcp")

494 tool.OfMcp.RequireApproval = responses.ToolMcpRequireApprovalUnionParam{OfMcpToolApprovalSetting: openai.String("never")}

495 tool.OfMcp.AllowedTools = responses.ToolMcpAllowedToolsUnionParam{OfMcpAllowedTools: []string{"roll"}}

496 

497 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

498 Model: "gpt-5.6",

499 Tools: []responses.ToolUnionParam{tool},

500 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Roll 2d4+1")},

501 })

502 if err != nil {

503 panic(err)

504 }

505 fmt.Println(response.OutputText())

506}

507```

508 

418```csharp509```csharp

419using OpenAI.Responses;510using OpenAI.Responses;

420#pragma warning disable OPENAI001511#pragma warning disable OPENAI001


561print(resp.output_text)652print(resp.output_text)

562```653```

563 654 

655```go

656package main

657 

658import (

659 "context"

660 "fmt"

661 

662 "github.com/openai/openai-go/v3"

663 "github.com/openai/openai-go/v3/responses"

664)

665 

666func main() {

667 client := openai.NewClient()

668 tool := responses.ToolParamOfMcp("dmcp")

669 tool.OfMcp.ServerDescription = openai.String("A Dungeons and Dragons MCP server to assist with dice rolling.")

670 tool.OfMcp.ServerURL = openai.String("https://dmcp-server.deno.dev/mcp")

671 tool.OfMcp.RequireApproval = responses.ToolMcpRequireApprovalUnionParam{OfMcpToolApprovalSetting: openai.String("always")}

672 

673 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

674 Model: "gpt-5.6",

675 PreviousResponseID: openai.String("resp_682d498bdefc81918b4a6aa477bfafd904ad1e533afccbfa"),

676 Tools: []responses.ToolUnionParam{tool},

677 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: responses.ResponseInputParam{

678 responses.ResponseInputItemParamOfMcpApprovalResponse("mcpr_682d498e3bd4819196a0ce1664f8e77b04ad1e533afccbfa", true),

679 }},

680 })

681 if err != nil {

682 panic(err)

683 }

684 fmt.Println(response.OutputText())

685}

686```

687 

564```csharp688```csharp

565using OpenAI.Responses;689using OpenAI.Responses;

566#pragma warning disable OPENAI001690#pragma warning disable OPENAI001


672print(resp.output_text)796print(resp.output_text)

673```797```

674 798 

799```go

800package main

801 

802import (

803 "context"

804 "fmt"

805 

806 "github.com/openai/openai-go/v3"

807 "github.com/openai/openai-go/v3/responses"

808)

809 

810func main() {

811 client := openai.NewClient()

812 tool := responses.ToolParamOfMcp("deepwiki")

813 tool.OfMcp.ServerURL = openai.String("https://mcp.deepwiki.com/mcp")

814 tool.OfMcp.RequireApproval = responses.ToolMcpRequireApprovalUnionParam{

815 OfMcpToolApprovalFilter: &responses.ToolMcpRequireApprovalMcpToolApprovalFilterParam{

816 Never: responses.ToolMcpRequireApprovalMcpToolApprovalFilterNeverParam{

817 ToolNames: []string{"ask_question", "read_wiki_structure"},

818 },

819 },

820 }

821 

822 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

823 Model: "gpt-5.6",

824 Tools: []responses.ToolUnionParam{tool},

825 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("What transport protocols does the 2025-03-26 version of the MCP spec (modelcontextprotocol/modelcontextprotocol) support?")},

826 })

827 if err != nil {

828 panic(err)

829 }

830 fmt.Println(response.OutputText())

831}

832```

833 

675```csharp834```csharp

676using OpenAI.Responses;835using OpenAI.Responses;

677#pragma warning disable OPENAI001836#pragma warning disable OPENAI001


772print(resp.output_text)931print(resp.output_text)

773```932```

774 933 

934```go

935package main

936 

937import (

938 "context"

939 "fmt"

940 "os"

941 

942 "github.com/openai/openai-go/v3"

943 "github.com/openai/openai-go/v3/responses"

944)

945 

946func main() {

947 authorization := os.Getenv("STRIPE_OAUTH_ACCESS_TOKEN")

948 if authorization == "" {

949 panic("STRIPE_OAUTH_ACCESS_TOKEN is required")

950 }

951 client := openai.NewClient()

952 tool := responses.ToolParamOfMcp("stripe")

953 tool.OfMcp.ServerURL = openai.String("https://mcp.stripe.com")

954 tool.OfMcp.Authorization = openai.String(authorization)

955 

956 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

957 Model: "gpt-5.6",

958 Tools: []responses.ToolUnionParam{tool},

959 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Create a payment link for $20")},

960 })

961 if err != nil {

962 panic(err)

963 }

964 fmt.Println(response.OutputText())

965}

966```

967 

775```csharp968```csharp

776using OpenAI.Responses;969using OpenAI.Responses;

777#pragma warning disable OPENAI001970#pragma warning disable OPENAI001


902print(resp.output_text)1095print(resp.output_text)

903```1096```

904 1097 

1098```go

1099package main

1100 

1101import (

1102 "context"

1103 "fmt"

1104 

1105 "github.com/openai/openai-go/v3"

1106 "github.com/openai/openai-go/v3/responses"

1107)

1108 

1109func main() {

1110 client := openai.NewClient()

1111 tool := responses.ToolParamOfMcp("google_calendar")

1112 tool.OfMcp.ConnectorID = "connector_googlecalendar"

1113 tool.OfMcp.Authorization = openai.String("<oauth access token>")

1114 tool.OfMcp.RequireApproval = responses.ToolMcpRequireApprovalUnionParam{OfMcpToolApprovalSetting: openai.String("never")}

1115 

1116 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

1117 Model: "gpt-5.6",

1118 Tools: []responses.ToolUnionParam{tool},

1119 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("What's on my Google Calendar for today?")},

1120 })

1121 if err != nil {

1122 panic(err)

1123 }

1124 fmt.Println(response.OutputText())

1125}

1126```

1127 

905```csharp1128```csharp

906using OpenAI.Responses;1129using OpenAI.Responses;

907#pragma warning disable OPENAI0011130#pragma warning disable OPENAI001

Details

63 f.write(base64.b64decode(image_base64))63 f.write(base64.b64decode(image_base64))

64```64```

65 65 

66```go

67package main

68 

69import (

70 "context"

71 "encoding/base64"

72 "os"

73 

74 "github.com/openai/openai-go/v3"

75 "github.com/openai/openai-go/v3/responses"

76)

77 

78func main() {

79 client := openai.NewClient()

80 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

81 Model: "gpt-5.6",

82 Input: responses.ResponseNewParamsInputUnion{

83 OfString: openai.String("Generate an image of gray tabby cat hugging an otter with an orange scarf"),

84 },

85 Tools: []responses.ToolUnionParam{{OfImageGeneration: &responses.ToolImageGenerationParam{}}},

86 })

87 if err != nil {

88 panic(err)

89 }

90 saveFirstGeneratedImage(response, "otter.png")

91}

92 

93func saveFirstGeneratedImage(response *responses.Response, filename string) {

94 for _, output := range response.Output {

95 if output.Type != "image_generation_call" {

96 continue

97 }

98 image, err := base64.StdEncoding.DecodeString(output.AsImageGenerationCall().Result)

99 if err != nil {

100 panic(err)

101 }

102 if err := os.WriteFile(filename, image, 0o600); err != nil {

103 panic(err)

104 }

105 return

106 }

107 panic("response did not include an image generation call")

108}

109```

110 

66 111 

67You can [provide input images](https://developers.openai.com/api/docs/guides/image-generation?image-generation-model=gpt-image#edit-images) using file IDs or base64 data.112You can [provide input images](https://developers.openai.com/api/docs/guides/image-generation?image-generation-model=gpt-image#edit-images) using file IDs or base64 data.

68 113 


209 f.write(base64.b64decode(image_base64))254 f.write(base64.b64decode(image_base64))

210```255```

211 256 

257```go

258package main

259 

260import (

261 "context"

262 "encoding/base64"

263 "os"

264 

265 "github.com/openai/openai-go/v3"

266 "github.com/openai/openai-go/v3/responses"

267)

268 

269func main() {

270 client := openai.NewClient()

271 first, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

272 Model: "gpt-5.6",

273 Input: responses.ResponseNewParamsInputUnion{

274 OfString: openai.String("Generate an image of gray tabby cat hugging an otter with an orange scarf"),

275 },

276 Tools: []responses.ToolUnionParam{{OfImageGeneration: &responses.ToolImageGenerationParam{}}},

277 })

278 if err != nil {

279 panic(err)

280 }

281 saveFirstGeneratedImage(first, "cat_and_otter.png")

282 

283 followUp, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

284 Model: "gpt-5.6",

285 PreviousResponseID: openai.String(first.ID),

286 Input: responses.ResponseNewParamsInputUnion{

287 OfString: openai.String("Now make it look realistic"),

288 },

289 Tools: []responses.ToolUnionParam{{OfImageGeneration: &responses.ToolImageGenerationParam{}}},

290 })

291 if err != nil {

292 panic(err)

293 }

294 saveFirstGeneratedImage(followUp, "cat_and_otter_realistic.png")

295}

296 

297func saveFirstGeneratedImage(response *responses.Response, filename string) {

298 for _, output := range response.Output {

299 if output.Type != "image_generation_call" {

300 continue

301 }

302 image, err := base64.StdEncoding.DecodeString(output.AsImageGenerationCall().Result)

303 if err != nil {

304 panic(err)

305 }

306 if err := os.WriteFile(filename, image, 0o600); err != nil {

307 panic(err)

308 }

309 return

310 }

311 panic("response did not include an image generation call")

312}

313```

314 

212 315

213 316 

214 317


324 f.write(base64.b64decode(image_base64))427 f.write(base64.b64decode(image_base64))

325```428```

326 429 

430```go

431package main

432 

433import (

434 "context"

435 "encoding/base64"

436 "encoding/json"

437 "os"

438 

439 "github.com/openai/openai-go/v3"

440 "github.com/openai/openai-go/v3/responses"

441)

442 

443func main() {

444 client := openai.NewClient()

445 first, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

446 Model: "gpt-5.6",

447 Input: responses.ResponseNewParamsInputUnion{

448 OfString: openai.String("Generate an image of gray tabby cat hugging an otter with an orange scarf"),

449 },

450 Tools: []responses.ToolUnionParam{{OfImageGeneration: &responses.ToolImageGenerationParam{}}},

451 })

452 if err != nil {

453 panic(err)

454 }

455 call := firstImageGenerationCall(first)

456 saveImage("cat_and_otter.png", call.Result)

457 input := outputAsInput(first.Output)

458 input = append(input, responses.ResponseInputItemParamOfMessage(

459 responses.ResponseInputMessageContentListParam{responses.ResponseInputContentParamOfInputText("Now make it look realistic")},

460 responses.EasyInputMessageRoleUser,

461 ))

462 

463 followUp, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

464 Model: "gpt-5.6",

465 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: input},

466 Tools: []responses.ToolUnionParam{{OfImageGeneration: &responses.ToolImageGenerationParam{}}},

467 })

468 if err != nil {

469 panic(err)

470 }

471 saveImage("cat_and_otter_realistic.png", firstImageGenerationCall(followUp).Result)

472}

473 

474func firstImageGenerationCall(response *responses.Response) responses.ResponseOutputItemImageGenerationCall {

475 for _, output := range response.Output {

476 if output.Type == "image_generation_call" {

477 return output.AsImageGenerationCall()

478 }

479 }

480 panic("response did not include an image generation call")

481}

482 

483func outputAsInput(output []responses.ResponseOutputItemUnion) []responses.ResponseInputItemUnionParam {

484 input := make([]responses.ResponseInputItemUnionParam, 0, len(output))

485 for _, item := range output {

486 var converted responses.ResponseInputItemUnion

487 if err := json.Unmarshal([]byte(item.RawJSON()), &converted); err != nil {

488 panic(err)

489 }

490 input = append(input, converted.ToParam())

491 }

492 return input

493}

494 

495func saveImage(filename, encoded string) {

496 image, err := base64.StdEncoding.DecodeString(encoded)

497 if err != nil {

498 panic(err)

499 }

500 if err := os.WriteFile(filename, image, 0o600); err != nil {

501 panic(err)

502 }

503}

504```

505 

327 506 

328 507 

329## Streaming508## Streaming


403 save_base64_image("river-final.png", image_data[0])582 save_base64_image("river-final.png", image_data[0])

404```583```

405 584 

585```go

586package main

587 

588import (

589 "context"

590 "encoding/base64"

591 "fmt"

592 "os"

593 

594 "github.com/openai/openai-go/v3"

595 "github.com/openai/openai-go/v3/responses"

596)

597 

598func main() {

599 client := openai.NewClient()

600 stream := client.Responses.NewStreaming(context.Background(), responses.ResponseNewParams{

601 Model: "gpt-5.6",

602 Input: responses.ResponseNewParamsInputUnion{

603 OfString: openai.String("Draw a gorgeous image of a river made of white owl feathers, snaking its way through a serene winter landscape"),

604 },

605 Tools: []responses.ToolUnionParam{{OfImageGeneration: &responses.ToolImageGenerationParam{PartialImages: openai.Int(2)}}},

606 })

607 for stream.Next() {

608 event := stream.Current()

609 if event.Type == "response.image_generation_call.partial_image" {

610 partial := event.AsResponseImageGenerationCallPartialImage()

611 saveImage(fmt.Sprintf("river-partial-%d.png", partial.PartialImageIndex), partial.PartialImageB64)

612 }

613 if event.Type == "response.completed" {

614 for _, output := range event.AsResponseCompleted().Response.Output {

615 if output.Type == "image_generation_call" {

616 saveImage("river-final.png", output.AsImageGenerationCall().Result)

617 }

618 }

619 }

620 }

621 if err := stream.Err(); err != nil {

622 panic(err)

623 }

624}

625 

626func saveImage(filename, encoded string) {

627 image, err := base64.StdEncoding.DecodeString(encoded)

628 if err != nil {

629 panic(err)

630 }

631 if err := os.WriteFile(filename, image, 0o600); err != nil {

632 panic(err)

633 }

634}

635```

636 

406 637 

407## Supported models638## Supported models

408 639 

Details

97print(response.output_text)97print(response.output_text)

98```98```

99 99 

100```go

101package main

102 

103import (

104 "context"

105 "fmt"

106 

107 "github.com/openai/openai-go/v3"

108 "github.com/openai/openai-go/v3/responses"

109)

110 

111func main() {

112 client := openai.NewClient()

113 tool := responses.ToolUnionParam{OfShell: &responses.FunctionShellToolParam{

114 Environment: responses.FunctionShellToolEnvironmentUnionParam{OfContainerAuto: &responses.ContainerAutoParam{}},

115 }}

116 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

117 Model: "gpt-5.6",

118 Tools: []responses.ToolUnionParam{tool},

119 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Execute: ls -lah /mnt/data && python --version && node --version")},

120 })

121 if err != nil {

122 panic(err)

123 }

124 fmt.Println(response.OutputText())

125}

126```

127 

100 128 

101## Hosted runtime details129## Hosted runtime details

102 130 


163print(container.id)191print(container.id)

164```192```

165 193 

194```go

195package main

196 

197import (

198 "context"

199 "fmt"

200 

201 "github.com/openai/openai-go/v3"

202)

203 

204func main() {

205 client := openai.NewClient()

206 container, err := client.Containers.New(context.Background(), openai.ContainerNewParams{

207 Name: "analysis-container",

208 MemoryLimit: openai.ContainerNewParamsMemoryLimit1g,

209 ExpiresAfter: openai.ContainerNewParamsExpiresAfter{

210 Anchor: "last_active_at",

211 Minutes: 20,

212 },

213 })

214 if err != nil {

215 panic(err)

216 }

217 fmt.Println(container.ID)

218}

219```

220 

166 221 

167### 2. Reference the container in Responses222### 2. Reference the container in Responses

168 223 


227print(response.output_text)282print(response.output_text)

228```283```

229 284 

285```go

286package main

287 

288import (

289 "context"

290 "fmt"

291 

292 "github.com/openai/openai-go/v3"

293 "github.com/openai/openai-go/v3/responses"

294)

295 

296func main() {

297 client := openai.NewClient()

298 tool := responses.ToolUnionParam{OfShell: &responses.FunctionShellToolParam{

299 Environment: responses.FunctionShellToolEnvironmentUnionParam{OfContainerReference: &responses.ContainerReferenceParam{ContainerID: "cntr_08f3d96c87a585390069118b594f7481a088b16cda7d9415fe"}},

300 }}

301 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

302 Model: "gpt-5.6",

303 Tools: []responses.ToolUnionParam{tool},

304 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("List files in the container and show disk usage.")},

305 })

306 if err != nil {

307 panic(err)

308 }

309 fmt.Println(response.OutputText())

310}

311```

312 

230 313 

231## Attach skills314## Attach skills

232 315 


297print(container.id)380print(container.id)

298```381```

299 382 

383```go

384package main

385 

386import (

387 "context"

388 "fmt"

389 

390 "github.com/openai/openai-go/v3"

391 "github.com/openai/openai-go/v3/responses"

392)

393 

394func main() {

395 client := openai.NewClient()

396 container, err := client.Containers.New(context.Background(), openai.ContainerNewParams{

397 Name: "skill-container",

398 Skills: []openai.ContainerNewParamsSkillUnion{

399 {OfSkillReference: &responses.SkillReferenceParam{SkillID: "skill_4db6f1a2c9e73508b41f9da06e2c7b5f"}},

400 {OfSkillReference: &responses.SkillReferenceParam{SkillID: "openai-spreadsheets", Version: openai.String("latest")}},

401 },

402 })

403 if err != nil {

404 panic(err)

405 }

406 fmt.Println(container.ID)

407}

408```

409 

300 410 

301## Network access411## Network access

302 412 


404print(response.output_text)514print(response.output_text)

405```515```

406 516 

517```go

518package main

519 

520import (

521 "context"

522 "fmt"

523 

524 "github.com/openai/openai-go/v3"

525 "github.com/openai/openai-go/v3/responses"

526)

527 

528func main() {

529 client := openai.NewClient()

530 tool := responses.ToolUnionParam{OfShell: &responses.FunctionShellToolParam{

531 Environment: responses.FunctionShellToolEnvironmentUnionParam{OfContainerAuto: &responses.ContainerAutoParam{

532 NetworkPolicy: responses.ContainerAutoNetworkPolicyUnionParam{OfAllowlist: &responses.ContainerNetworkPolicyAllowlistParam{

533 AllowedDomains: []string{"pypi.org", "files.pythonhosted.org", "github.com"},

534 }},

535 }},

536 }}

537 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

538 Model: "gpt-5.6",

539 ToolChoice: responses.ResponseNewParamsToolChoiceUnion{OfToolChoiceMode: openai.Opt(responses.ToolChoiceOptionsRequired)},

540 Tools: []responses.ToolUnionParam{tool},

541 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("In the container, pip install httpx beautifulsoup4, fetch release pages, and write /mnt/data/release_digest.md.")},

542 })

543 if err != nil {

544 panic(err)

545 }

546 fmt.Println(response.OutputText())

547}

548```

549 

407 550 

408Allowlisting domains introduces security risks such as prompt551Allowlisting domains introduces security risks such as prompt

409 injection-driven data exfiltration. Only allowlist domains you trust and that552 injection-driven data exfiltration. Only allowlist domains you trust and that


647print(deleted)790print(deleted)

648```791```

649 792 

793```go

794package main

795 

796import (

797 "context"

798 "fmt"

799 

800 "github.com/openai/openai-go/v3"

801)

802 

803func main() {

804 client := openai.NewClient()

805 if err := client.Containers.Delete(context.Background(), "container_id"); err != nil {

806 panic(err)

807 }

808 fmt.Println("Container deleted")

809}

810```

811 

650 812 

651## Domain secrets813## Domain secrets

652 814 


780print(response.output_text)942print(response.output_text)

781```943```

782 944 

945```go

946package main

947 

948import (

949 "context"

950 "fmt"

951 

952 "github.com/openai/openai-go/v3"

953 "github.com/openai/openai-go/v3/responses"

954)

955 

956func main() {

957 client := openai.NewClient()

958 tool := responses.ToolUnionParam{OfShell: &responses.FunctionShellToolParam{

959 Environment: responses.FunctionShellToolEnvironmentUnionParam{OfContainerAuto: &responses.ContainerAutoParam{

960 NetworkPolicy: responses.ContainerAutoNetworkPolicyUnionParam{OfAllowlist: &responses.ContainerNetworkPolicyAllowlistParam{

961 AllowedDomains: []string{"httpbin.org"},

962 DomainSecrets: []responses.ContainerNetworkPolicyDomainSecretParam{{

963 Domain: "httpbin.org",

964 Name: "API_KEY",

965 Value: "debug-secret-123",

966 }},

967 }},

968 }},

969 }}

970 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

971 Model: "gpt-5.6",

972 ToolChoice: responses.ResponseNewParamsToolChoiceUnion{OfToolChoiceMode: openai.Opt(responses.ToolChoiceOptionsRequired)},

973 Tools: []responses.ToolUnionParam{tool},

974 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Use curl to call https://httpbin.org/headers with header Authorization: Bearer $API_KEY. Tell me what you see in the final text response.")},

975 })

976 if err != nil {

977 panic(err)

978 }

979 fmt.Println(response.OutputText())

980}

981```

982 

783 983 

784## Multi-turn workflows984## Multi-turn workflows

785 985 


854print(response.output_text)1054print(response.output_text)

855```1055```

856 1056 

1057```go

1058package main

1059 

1060import (

1061 "context"

1062 "fmt"

1063 

1064 "github.com/openai/openai-go/v3"

1065 "github.com/openai/openai-go/v3/responses"

1066)

1067 

1068func main() {

1069 client := openai.NewClient()

1070 tool := responses.ToolUnionParam{OfShell: &responses.FunctionShellToolParam{

1071 Environment: responses.FunctionShellToolEnvironmentUnionParam{OfContainerReference: &responses.ContainerReferenceParam{ContainerID: "cntr_f19c2b51e4a06793d82d54a7be0fc9154d3361ab28ce7f6041"}},

1072 }}

1073 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

1074 Model: "gpt-5.6",

1075 PreviousResponseID: openai.String("resp_2a8e5c9174d63b0f18a4c572de9f64a1b3c76d508e12f9ab47"),

1076 Tools: []responses.ToolUnionParam{tool},

1077 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Read /mnt/data/top5.csv and report the top candidate.")},

1078 })

1079 if err != nil {

1080 panic(err)

1081 }

1082 fmt.Println(response.OutputText())

1083}

1084```

1085 

857 1086 

858## Shell output in Responses1087## Shell output in Responses

859 1088 


928print(response)1157print(response)

929```1158```

930 1159 

1160```go

1161package main

1162 

1163import (

1164 "context"

1165 "fmt"

1166 

1167 "github.com/openai/openai-go/v3"

1168 "github.com/openai/openai-go/v3/responses"

1169)

1170 

1171func main() {

1172 client := openai.NewClient()

1173 tool := responses.ToolUnionParam{OfShell: &responses.FunctionShellToolParam{

1174 Environment: responses.FunctionShellToolEnvironmentUnionParam{OfLocal: &responses.LocalEnvironmentParam{}},

1175 }}

1176 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

1177 Model: "gpt-5.6",

1178 Instructions: openai.String("The local bash shell environment is on Mac."),

1179 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("find me the largest pdf file in ~/Documents")},

1180 Tools: []responses.ToolUnionParam{tool},

1181 })

1182 if err != nil {

1183 panic(err)

1184 }

1185 fmt.Println(response.Output)

1186}

1187```

1188 

931 1189 

932When you receive `shell_call` output items:1190When you receive `shell_call` output items:

933 1191 


999 return CmdResult(out, err, p.returncode, True)1257 return CmdResult(out, err, p.returncode, True)

1000```1258```

1001 1259 

1260```go

1261package main

1262 

1263import (

1264 "bytes"

1265 "context"

1266 "fmt"

1267 "os/exec"

1268 "time"

1269)

1270 

1271type shellResult struct {

1272 Stdout string

1273 Stderr string

1274 ExitCode int

1275 TimedOut bool

1276}

1277 

1278type shellExecutor struct {

1279 DefaultTimeout time.Duration

1280}

1281 

1282func (e shellExecutor) run(command string, timeout time.Duration) shellResult {

1283 if timeout == 0 {

1284 timeout = e.DefaultTimeout

1285 }

1286 ctx, cancel := context.WithTimeout(context.Background(), timeout)

1287 defer cancel()

1288 cmd := exec.CommandContext(ctx, "sh", "-c", command)

1289 var stdout, stderr bytes.Buffer

1290 cmd.Stdout = &stdout

1291 cmd.Stderr = &stderr

1292 err := cmd.Run()

1293 result := shellResult{Stdout: stdout.String(), Stderr: stderr.String()}

1294 if ctx.Err() == context.DeadlineExceeded {

1295 result.TimedOut = true

1296 result.ExitCode = -1

1297 return result

1298 }

1299 if err != nil {

1300 if exitError, ok := err.(*exec.ExitError); ok {

1301 result.ExitCode = exitError.ExitCode()

1302 return result

1303 }

1304 if result.Stderr == "" {

1305 result.Stderr = err.Error()

1306 }

1307 result.ExitCode = -1

1308 }

1309 return result

1310}

1311 

1312func main() {

1313 executor := shellExecutor{DefaultTimeout: time.Minute}

1314 fmt.Println(executor.run("printf shell-executor-ready", 0))

1315}

1316```

1317 

1002 1318 

1003Example shell_call_output payload1319Example shell_call_output payload

1004 1320 

Details

136print(response.output_text)136print(response.output_text)

137```137```

138 138 

139```go

140package main

141 

142import (

143 "context"

144 "fmt"

145 

146 "github.com/openai/openai-go/v3"

147 "github.com/openai/openai-go/v3/responses"

148)

149 

150func main() {

151 client := openai.NewClient()

152 tool := responses.ToolUnionParam{OfShell: &responses.FunctionShellToolParam{

153 Environment: responses.FunctionShellToolEnvironmentUnionParam{OfContainerAuto: &responses.ContainerAutoParam{

154 Skills: []responses.ContainerAutoSkillUnionParam{

155 {OfSkillReference: &responses.SkillReferenceParam{SkillID: "<skill_id>"}},

156 {OfSkillReference: &responses.SkillReferenceParam{SkillID: "<skill_id>", Version: openai.String("2")}},

157 },

158 }},

159 }}

160 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

161 Model: "gpt-5.6",

162 Tools: []responses.ToolUnionParam{tool},

163 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Use the skills to add 144 and 377, then compute triangle area with base 9 height 13.")},

164 })

165 if err != nil {

166 panic(err)

167 }

168 fmt.Println(response.OutputText())

169}

170```

171 

139 172 

140### Prompting behavior173### Prompting behavior

141 174 


230print(response.output_text)263print(response.output_text)

231```264```

232 265 

266```go

267package main

268 

269import (

270 "context"

271 "fmt"

272 

273 "github.com/openai/openai-go/v3"

274 "github.com/openai/openai-go/v3/responses"

275)

276 

277func main() {

278 client := openai.NewClient()

279 tool := responses.ToolUnionParam{OfShell: &responses.FunctionShellToolParam{

280 Environment: responses.FunctionShellToolEnvironmentUnionParam{OfLocal: &responses.LocalEnvironmentParam{

281 Skills: []responses.LocalSkillParam{{

282 Name: "csv-insights",

283 Description: "Summarize CSV files and produce a markdown report.",

284 Path: "<path-to-skill-folder>",

285 }},

286 }},

287 }}

288 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

289 Model: "gpt-5.6",

290 Tools: []responses.ToolUnionParam{tool},

291 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Use the csv-insights skill and run locally to summarize today's CSV reports in this repo.")},

292 })

293 if err != nil {

294 panic(err)

295 }

296 fmt.Println(response.OutputText())

297}

298```

299 

233 300 

234## Skills in the user prompt301## Skills in the user prompt

235 302 

Details

80print("Video generation started:", video)80print("Video generation started:", video)

81```81```

82 82 

83```go

84package main

85 

86import (

87 "context"

88 "fmt"

89 

90 "github.com/openai/openai-go/v3"

91)

92 

93func main() {

94 client := openai.NewClient()

95 video, err := client.Videos.New(context.Background(), openai.VideoNewParams{

96 Model: openai.VideoModelSora2,

97 Prompt: "A video of the words 'Thank you' in sparkling letters",

98 })

99 if err != nil {

100 panic(err)

101 }

102 fmt.Println("Video generation started:", video)

103}

104```

105 

83```bash106```bash

84curl -X POST "https://api.openai.com/v1/videos" \107curl -X POST "https://api.openai.com/v1/videos" \

85 -H "Authorization: Bearer $OPENAI_API_KEY" \108 -H "Authorization: Bearer $OPENAI_API_KEY" \


201asyncio.run(main())224asyncio.run(main())

202```225```

203 226 

227```go

228package main

229 

230import (

231 "context"

232 "fmt"

233 

234 "github.com/openai/openai-go/v3"

235)

236 

237func main() {

238 client := openai.NewClient()

239 video, err := client.Videos.NewAndPoll(context.Background(), openai.VideoNewParams{

240 Model: openai.VideoModelSora2,

241 Prompt: "A video of the words 'Thank you' in sparkling letters",

242 }, 2000)

243 if err != nil {

244 panic(err)

245 }

246 if video.Status == openai.VideoStatusCompleted {

247 fmt.Println("Video successfully completed:", video)

248 return

249 }

250 fmt.Println("Video creation failed. Status:", video.Status)

251}

252```

253 

204 254 

205Response example:255Response example:

206 256 


346print("Wrote video.mp4")396print("Wrote video.mp4")

347```397```

348 398 

399```go

400package main

401 

402import (

403 "context"

404 "fmt"

405 "io"

406 "os"

407 

408 "github.com/openai/openai-go/v3"

409)

410 

411func main() {

412 client := openai.NewClient()

413 video, err := client.Videos.NewAndPoll(context.Background(), openai.VideoNewParams{

414 Model: openai.VideoModelSora2,

415 Prompt: "A video of the words 'Thank you' in sparkling letters",

416 }, 2000)

417 if err != nil {

418 panic(err)

419 }

420 if video.Status != openai.VideoStatusCompleted {

421 panic(fmt.Errorf("video generation failed with status %s", video.Status))

422 }

423 

424 response, err := client.Videos.DownloadContent(context.Background(), video.ID, openai.VideoDownloadContentParams{})

425 if err != nil {

426 panic(err)

427 }

428 defer response.Body.Close()

429 file, err := os.Create("video.mp4")

430 if err != nil {

431 panic(err)

432 }

433 if _, err := io.Copy(file, response.Body); err != nil {

434 panic(err)

435 }

436 if err := file.Close(); err != nil {

437 panic(err)

438 }

439 fmt.Println("Wrote video.mp4")

440}

441```

442 

349```bash443```bash

350curl -L "https://api.openai.com/v1/videos/video_abc123/content" \444curl -L "https://api.openai.com/v1/videos/video_abc123/content" \

351 -H "Authorization: Bearer $OPENAI_API_KEY" \445 -H "Authorization: Bearer $OPENAI_API_KEY" \

Details

131print(resp.status)131print(resp.status)

132```132```

133 133 

134```go

135package main

136 

137import (

138 "context"

139 "fmt"

140 

141 "github.com/openai/openai-go/v3"

142 "github.com/openai/openai-go/v3/responses"

143)

144 

145func main() {

146 client := openai.NewClient()

147 

148 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

149 Model: "gpt-5.6",

150 Background: openai.Bool(true),

151 Input: responses.ResponseNewParamsInputUnion{

152 OfString: openai.String("Write a very long novel about otters in space."),

153 },

154 })

155 if err != nil {

156 panic(err)

157 }

158 

159 fmt.Println(response.Status)

160}

161```

162 

134 163 

135In this guide, you will learn how to create webook endpoints in the dashboard, set up server-side code to handle them, and verify that inbound requests originated from OpenAI.164In this guide, you will learn how to create webook endpoints in the dashboard, set up server-side code to handle them, and verify that inbound requests originated from OpenAI.

136 165 

libraries.md +1 −4

Details

244 "fmt"244 "fmt"

245 245 

246 "github.com/openai/openai-go/v3"246 "github.com/openai/openai-go/v3"

247 "github.com/openai/openai-go/v3/option"

248 "github.com/openai/openai-go/v3/responses"247 "github.com/openai/openai-go/v3/responses"

249)248)

250 249 

251func main() {250func main() {

252 client := openai.NewClient(251 client := openai.NewClient()

253 option.WithAPIKey("My API Key"), // or set OPENAI_API_KEY in your env

254 )

255 252 

256 resp, err := client.Responses.New(context.TODO(), responses.ResponseNewParams{253 resp, err := client.Responses.New(context.TODO(), responses.ResponseNewParams{

257 Model: "gpt-5.6",254 Model: "gpt-5.6",

mcp.md +6 −3

Details

26 26 

27Note that there are a number of other MCP server frameworks you can use in a variety of programming languages. Whichever framework you use though, the tool definitions in your server will need to conform to the shape described here.27Note that there are a number of other MCP server frameworks you can use in a variety of programming languages. Whichever framework you use though, the tool definitions in your server will need to conform to the shape described here.

28 28 

29To work with ChatGPT deep research and company knowledge (and deep research via API), your MCP server should implement two read-only tools: `search` and `fetch`, using the compatibility schema in [Company knowledge compatibility](https://developers.openai.com/plugins/build/mcp-server#company-knowledge-compatibility).29To work with ChatGPT deep research and company knowledge, your MCP server

30should implement two read-only tools: `search` and `fetch`, using the

31compatibility schema in [Company knowledge compatibility](https://developers.openai.com/plugins/build/mcp-server#company-knowledge-compatibility).

32The same interface is useful for research workflows via API.

30 33 

31Declare an output schema for each tool so clients can validate the result shape.34Declare an output schema for each tool so clients can validate the result shape.

32In FastMCP, typed return models can generate this schema automatically; the35In FastMCP, typed return models can generate this schema automatically; the


397 400 

398## Test and connect your MCP server401## Test and connect your MCP server

399 402 

400You can test your MCP server with a deep research model [in the prompts dashboard](https://platform.openai.com/chat). Create a new prompt, or edit an existing one, and add a new MCP tool to the prompt configuration. Remember that MCP servers used via API for deep research have to be configured with no approval required.403You can test your MCP server with a deep research model [in the prompts dashboard](https://platform.openai.com/chat). Create a new prompt, or edit an existing one, and add a new MCP tool to the prompt configuration. This compatibility example exposes only read-only `search` and `fetch` tools, so its API request skips approval for those tools. Keep approval enabled for tools that can modify data or take other consequential actions.

401 404 

402If you are testing this server as part of a plugin, follow [Connect and test your plugin](https://developers.openai.com/plugins/deploy/connect-chatgpt).405If you are testing this server as part of a plugin, follow [Connect and test your plugin](https://developers.openai.com/plugins/deploy/connect-chatgpt).

403 406 


414 -H "Content-Type: application/json" \417 -H "Content-Type: application/json" \

415 -H "Authorization: Bearer $OPENAI_API_KEY" \418 -H "Authorization: Bearer $OPENAI_API_KEY" \

416 -d '{419 -d '{

417 "model": "o4-mini-deep-research",420 "model": "gpt-5.6-sol",

418 "input": [421 "input": [

419 {422 {

420 "role": "developer",423 "role": "developer",

quickstart.md +213 −4

Details

261 "fmt"261 "fmt"

262 262 

263 "github.com/openai/openai-go/v3"263 "github.com/openai/openai-go/v3"

264 "github.com/openai/openai-go/v3/option"

265 "github.com/openai/openai-go/v3/responses"264 "github.com/openai/openai-go/v3/responses"

266)265)

267 266 

268func main() {267func main() {

269 client := openai.NewClient(268 client := openai.NewClient()

270 option.WithAPIKey("My API Key"), // or set OPENAI_API_KEY in your env

271 )

272 269 

273 resp, err := client.Responses.New(context.TODO(), responses.ResponseNewParams{270 resp, err := client.Responses.New(context.TODO(), responses.ResponseNewParams{

274 Model: "gpt-5.6",271 Model: "gpt-5.6",


452print(response.output_text)449print(response.output_text)

453```450```

454 451 

452```go

453package main

454 

455import (

456 "context"

457 "fmt"

458 

459 "github.com/openai/openai-go/v3"

460 "github.com/openai/openai-go/v3/responses"

461)

462 

463func main() {

464 client := openai.NewClient()

465 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

466 Model: "gpt-5.6",

467 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: responses.ResponseInputParam{

468 responses.ResponseInputItemParamOfMessage(

469 responses.ResponseInputMessageContentListParam{

470 responses.ResponseInputContentParamOfInputText("What is in this image?"),

471 {OfInputImage: &responses.ResponseInputImageParam{

472 Detail: responses.ResponseInputImageDetailAuto,

473 ImageURL: openai.String("https://openai-documentation.vercel.app/images/cat_and_otter.png"),

474 }},

475 },

476 responses.EasyInputMessageRoleUser,

477 ),

478 }},

479 })

480 if err != nil {

481 panic(err)

482 }

483 fmt.Println(response.OutputText())

484}

485```

486 

455```csharp487```csharp

456using OpenAI.Responses;488using OpenAI.Responses;

457#pragma warning disable OPENAI001489#pragma warning disable OPENAI001


994print(response.output_text)1026print(response.output_text)

995```1027```

996 1028 

1029```go

1030package main

1031 

1032import (

1033 "context"

1034 "fmt"

1035 

1036 "github.com/openai/openai-go/v3"

1037 "github.com/openai/openai-go/v3/responses"

1038)

1039 

1040func main() {

1041 client := openai.NewClient()

1042 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

1043 Model: "gpt-5.6",

1044 Tools: []responses.ToolUnionParam{

1045 responses.ToolParamOfWebSearch(responses.WebSearchToolTypeWebSearch),

1046 },

1047 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("What was a positive news story from today?")},

1048 })

1049 if err != nil {

1050 panic(err)

1051 }

1052 fmt.Println(response.OutputText())

1053}

1054```

1055 

997```csharp1056```csharp

998using OpenAI.Responses;1057using OpenAI.Responses;

999#pragma warning disable OPENAI0011058#pragma warning disable OPENAI001


1087print(response)1146print(response)

1088```1147```

1089 1148 

1149```go

1150package main

1151 

1152import (

1153 "context"

1154 "fmt"

1155 

1156 "github.com/openai/openai-go/v3"

1157 "github.com/openai/openai-go/v3/responses"

1158)

1159 

1160func main() {

1161 client := openai.NewClient()

1162 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

1163 Model: "gpt-5.6",

1164 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("What is deep research by OpenAI?")},

1165 Tools: []responses.ToolUnionParam{responses.ToolParamOfFileSearch([]string{"<vector_store_id>"})},

1166 })

1167 if err != nil {

1168 panic(err)

1169 }

1170 fmt.Println(response)

1171}

1172```

1173 

1090```csharp1174```csharp

1091using OpenAI.Responses;1175using OpenAI.Responses;

1092#pragma warning disable OPENAI0011176#pragma warning disable OPENAI001


1170print(response.output_text)1254print(response.output_text)

1171```1255```

1172 1256 

1257```go

1258package main

1259 

1260import (

1261 "context"

1262 "fmt"

1263 

1264 "github.com/openai/openai-go/v3"

1265 "github.com/openai/openai-go/v3/responses"

1266)

1267 

1268func main() {

1269 client := openai.NewClient()

1270 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

1271 Model: "gpt-5.6",

1272 Instructions: openai.String("You are a personal math tutor. When asked a math question, write and run code to answer the question."),

1273 Tools: []responses.ToolUnionParam{

1274 responses.ToolParamOfCodeInterpreter(responses.ToolCodeInterpreterContainerCodeInterpreterContainerAutoParam{}),

1275 },

1276 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("I need to solve the equation 3x + 11 = 14. Can you help me?")},

1277 })

1278 if err != nil {

1279 panic(err)

1280 }

1281 fmt.Println(response.OutputText())

1282}

1283```

1284 

1173```ruby1285```ruby

1174require "openai"1286require "openai"

1175 1287 


1288print(response.output[0].to_json())1400print(response.output[0].to_json())

1289```1401```

1290 1402 

1403```go

1404package main

1405 

1406import (

1407 "context"

1408 "fmt"

1409 

1410 "github.com/openai/openai-go/v3"

1411 "github.com/openai/openai-go/v3/responses"

1412)

1413 

1414func main() {

1415 client := openai.NewClient()

1416 parameters := map[string]any{

1417 "type": "object",

1418 "properties": map[string]any{

1419 "location": map[string]any{

1420 "type": "string",

1421 "description": "City and country e.g. Bogotá, Colombia",

1422 },

1423 },

1424 "required": []string{"location"},

1425 "additionalProperties": false,

1426 }

1427 tool := responses.ToolParamOfFunction("get_weather", parameters, true)

1428 tool.OfFunction.Description = openai.String("Get current temperature for a given location.")

1429 

1430 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

1431 Model: "gpt-5.6",

1432 Input: responses.ResponseNewParamsInputUnion{OfInputItemList: responses.ResponseInputParam{

1433 responses.ResponseInputItemParamOfMessage("What is the weather like in Paris today?", responses.EasyInputMessageRoleUser),

1434 }},

1435 Tools: []responses.ToolUnionParam{tool},

1436 })

1437 if err != nil {

1438 panic(err)

1439 }

1440 fmt.Println(response.Output)

1441}

1442```

1443 

1291```csharp1444```csharp

1292using System.Text.Json;1445using System.Text.Json;

1293using System.Text.Json.Serialization.Metadata;1446using System.Text.Json.Serialization.Metadata;


1476print(resp.output_text)1629print(resp.output_text)

1477```1630```

1478 1631 

1632```go

1633package main

1634 

1635import (

1636 "context"

1637 "fmt"

1638 

1639 "github.com/openai/openai-go/v3"

1640 "github.com/openai/openai-go/v3/responses"

1641)

1642 

1643func main() {

1644 client := openai.NewClient()

1645 tool := responses.ToolParamOfMcp("dmcp")

1646 tool.OfMcp.ServerDescription = openai.String("A Dungeons and Dragons MCP server to assist with dice rolling.")

1647 tool.OfMcp.ServerURL = openai.String("https://dmcp-server.deno.dev/mcp")

1648 tool.OfMcp.RequireApproval = responses.ToolMcpRequireApprovalUnionParam{OfMcpToolApprovalSetting: openai.String("never")}

1649 

1650 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{

1651 Model: "gpt-5.6",

1652 Tools: []responses.ToolUnionParam{tool},

1653 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Roll 2d4+1")},

1654 })

1655 if err != nil {

1656 panic(err)

1657 }

1658 fmt.Println(response.OutputText())

1659}

1660```

1661 

1479```csharp1662```csharp

1480using OpenAI.Responses;1663using OpenAI.Responses;

1481#pragma warning disable OPENAI0011664#pragma warning disable OPENAI001


1580 print(event)1763 print(event)

1581```1764```

1582 1765 

1766```go

1767package main

1768 

1769import (

1770 "context"

1771 "fmt"

1772 

1773 "github.com/openai/openai-go/v3"

1774 "github.com/openai/openai-go/v3/responses"

1775)

1776 

1777func main() {

1778 client := openai.NewClient()

1779 stream := client.Responses.NewStreaming(context.Background(), responses.ResponseNewParams{

1780 Model: "gpt-5.6",

1781 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Say 'double bubble bath' ten times fast.")},

1782 })

1783 for stream.Next() {

1784 fmt.Println(stream.Current().Type)

1785 }

1786 if err := stream.Err(); err != nil {

1787 panic(err)

1788 }

1789}

1790```

1791 

1583```csharp1792```csharp

1584using OpenAI.Responses;1793using OpenAI.Responses;

1585#pragma warning disable OPENAI0011794#pragma warning disable OPENAI001