skip to content
Alvin Lucillo

Using API Key on default code playground

/ 1 min read

Visit https://ai.azure.com/ and create a Foundry resource, then create a new project.

Inside the project, click the Build menu at the top and click Models on the left navigation.

Choose a model like gpt-5-mini, and on the playground tab, click Continue in code.

package main

import (
	"context"

	"github.com/openai/openai-go/v3"
	"github.com/openai/openai-go/v3/option"
	"github.com/openai/openai-go/v3/responses"
)

func playground() {
	const endpoint = "https://redacted-resource.services.ai.azure.com/openai/v1"
	const deploymentName = "gpt-5-mini"

	// token_credential, err := azidentity.NewDefaultAzureCredential(nil)
	// if err != nil {
	// 	println("Error creating credential.")
	// 	panic(err)
	// }

	client := openai.NewClient(
		option.WithBaseURL(endpoint),
		option.WithAPIKey("redacted"),
	)
	ctx := context.Background()

	question := "Write me a haiku about computers"

	resp, err := client.Responses.New(ctx, responses.ResponseNewParams{
		Input: responses.ResponseNewParamsInputUnion{OfString: openai.String(question)},
		Model: deploymentName,
	})

	if err != nil {
		panic(err)
	}

	println(resp.OutputText())
}
go run .

Silent silicon
whirring fans and neon glow
dreams in binary