May 7, 2025
SDKs
Jacob Zimmerman

Go SDK generator V2

We released a “V2” of the Go SDK generator, with a completely redesigned JSON model, more ergonomic union types, and a cleaner DX across the board.

  • No need for pkg.F(…) constructors
    • petstore.Pet{ Name: petstore.F("Joey") }petstore.Pet{ Name: "Joey" }
  • Pointer-free JSON model using omitzero: Ergonomic optional and nullable parameters using the new standard library omitzero JSON semantics.
  • Improved discoverability of union variants: Unions now use a struct-based design with json:",omitzero,inline" semantics instead of interfaces for better discoverability
  • Ergonomic access to shared fields in union types: No need to switch on variants when you know the property you want
  • Automatic helper generation for complex union variants:
// Old: Manually constructed variants

openai.ChatCompletionNewParams{
   	Messages: openai.F([]openai.ChatCompletionMessageParam{
   		openai.ChatCompletionUserMessageParam{
     		Content: openai.F([]openai.ChatCompletionMessageContent{
       			openai.UnionString("Write me a poem")
       		}),
		Type: openai.F[ChatCompletionMessageParamRole]("user"),
    }),
    Model: openai.ChatModelO3Mini,
}

// New: Automatically generated helpers

openai.ChatCompletionNewParams{
	Messages: []openai.ChatCompletionMessageParamUnion{
		openai.UserMessage("Write me a poem"),
	},
	Model: openai.ChatModelO3Mini,
}
// New: Automatically generated helpers

openai.ChatCompletionNewParams{
		Messages: []openai.ChatCompletionMessageParamUnion{
			openai.UserMessage("How can I list all files in a directory using Python?"),
		},
		Model: openai.ChatModelO3Mini,
	},
  • Supports unmarshalling into parameters: Request parameter types, including unions, can now be unmarshalled from external input.

We’re continuing to expand Go support. Send us a note if there is anything you’d like to see in upcoming updates. support@stainless.com