example

command
v0.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Command example shows the public API of the core/llm/openai package: build a reusable Client, bind a structured-output type with New, and call Generate to get a fully decoded value plus token usage and finish reason.

It needs a real OpenAI key, so it reads two env vars and is a no-op without them. Run it from the core module with:

export OPENAI_API_KEY=sk-...        # your key
export OPENAI_MODEL=gpt-5.5         # any model id (never hard-coded)
go run ./llm/openai/example

Cloud-credential recipe (#854 auth matrix — Azure OpenAI): the server module's llmauth package builds the credentialed client (core cannot import it; module DAG):

hc, _ := llmauth.NewAzureManagedIdentityHTTPClient()        // or NewAzureClientSecretHTTPClient
c := openai.NewClient("", model,                            // empty key: transport owns auth
	openai.WithBaseURL("https://<resource>.openai.azure.com/openai/v1"),
	openai.WithHTTPClient(hc))

Classic static-key Azure uses WithAPIKeyHeader("api-key") instead of an injected client.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL