SpyBara
Go Premium

Reference 2026-08-17 22:57 UTC to 2026-08-18 22:02 UTC

2 files changed +59 −14. View all changes and history on the product overview
2026
Thu 20 01:57 Wed 19 21:01 Tue 18 22:02 Mon 17 22:57 Sun 16 16:58 Sat 15 02:02 Fri 14 23:57 Thu 13 22:00 Wed 12 16:01 Tue 11 22:59 Mon 10 22:00 Sat 8 00:59 Fri 7 21:59 Thu 6 18:59 Wed 5 02:01 Tue 4 22:59 Mon 3 21:58 Sat 1 01:00

go/index.md +32 −14

Details

282 282 

283// Structured Outputs uses a subset of JSON schema283// Structured Outputs uses a subset of JSON schema

284// These flags are necessary to comply with the subset284// These flags are necessary to comply with the subset

285func GenerateSchema[T any]() map[string]any {285func GenerateSchema[T any]() (map[string]any, error) {

286 reflector := jsonschema.Reflector{286 reflector := jsonschema.Reflector{

287 AllowAdditionalProperties: false,287 AllowAdditionalProperties: false,

288 DoNotReference: true,288 DoNotReference: true,


290 var v T290 var v T

291 schema := reflector.Reflect(v)291 schema := reflector.Reflect(v)

292 292 

293 data, _ := json.Marshal(schema)293 data, err := json.Marshal(schema)

294 var result map[string]any294 if err != nil {

295 json.Unmarshal(data, &result)295 return nil, err

296 return result296 }

297 // Preserve schema values as raw JSON so integer constraints are not rounded

298 // through float64 before the SDK serializes the request.

299 var rawSchema map[string]json.RawMessage

300 if err := json.Unmarshal(data, &rawSchema); err != nil {

301 return nil, err

302 }

303 result := make(map[string]any, len(rawSchema))

304 for key, value := range rawSchema {

305 result[key] = value

306 }

307 return result, nil

297}308}

298 309 

299// Generate the JSON schema at initialization time

300var HistoricalComputerSchema = GenerateSchema[HistoricalComputer]()

301 

302func main() {310func main() {

303 client := openai.NewClient()311 client := openai.NewClient()

304 ctx := context.Background()312 ctx := context.Background()

313 schema, err := GenerateSchema[HistoricalComputer]()

314 if err != nil {

315 panic(err)

316 }

305 317 

306 response, err := client.Responses.New(ctx, responses.ResponseNewParams{318 response, err := client.Responses.New(ctx, responses.ResponseNewParams{

307 Model: openai.ChatModelGPT5_2,319 Model: openai.ChatModelGPT5_2,


309 OfString: openai.String("What computer ran the first neural network?"),321 OfString: openai.String("What computer ran the first neural network?"),

310 },322 },

311 Text: responses.ResponseTextConfigParam{323 Text: responses.ResponseTextConfigParam{

312 Format: responses.ResponseFormatTextConfigParamOfJSONSchema(324 Format: responses.ResponseFormatTextConfigUnionParam{

313 "historical_computer",325 OfJSONSchema: &responses.ResponseFormatTextJSONSchemaConfigParam{

314 HistoricalComputerSchema,326 Name: "historical_computer",

315 ),327 Description: openai.String("Notable information about a computer"),

328 Schema: schema,

329 Strict: openai.Bool(true),

330 },

331 },

316 },332 },

317 })333 })

318 if err != nil {334 if err != nil {


321 337 

322 // extract into a well-typed struct338 // extract into a well-typed struct

323 var historicalComputer HistoricalComputer339 var historicalComputer HistoricalComputer

324 _ = json.Unmarshal([]byte(response.OutputText()), &historicalComputer)340 if err := json.Unmarshal([]byte(response.OutputText()), &historicalComputer); err != nil {

341 panic(err)

342 }

325 343 

326 historicalComputer.Name344 historicalComputer.Name

327 historicalComputer.Origin.YearBuilt345 historicalComputer.Origin.YearBuilt


332}350}

333```351```

334 352 

335> See the [full structured outputs example](./examples/responses-structured-outputs/main.go)353> See the [full structured outputs example](./examples/structured-outputs/main.go)

336 354 

337</details>355</details>

338 356 

ruby/index.md +27 −0

Details

50end50end

51```51```

52 52 

53### Realtime WebSockets

54 

55The SDK supports block-scoped, typed Realtime WebSocket sessions for

56server-side text and committed-turn transcription workflows. Add the optional

57`async-websocket` gem, then use `client.realtime.connect`:

58 

59```ruby

60client.realtime.connect(model: "gpt-realtime-2.1") do |connection|

61 connection.session.update(type: :realtime, output_modalities: [:text])

62 connection.conversation.items.create(

63 type: :message,

64 role: :user,

65 content: [{type: :input_text, text: "Hello"}]

66 )

67 connection.response.create

68 

69 connection.each do |event|

70 print(event.delta) if event.is_a?(OpenAI::Realtime::ResponseTextDeltaEvent)

71 break if event.is_a?(OpenAI::Realtime::ResponseDoneEvent)

72 end

73end

74```

75 

76See the [Realtime WebSocket guide](realtime.md) and the runnable

77[text and transcription examples](examples/realtime/README.md) for lifecycle,

78authentication, proxy, TLS, and custom transport details.

79 

53### Pagination80### Pagination

54 81 

55List methods in the OpenAI API are paginated.82List methods in the OpenAI API are paginated.