GoAIAI SDK, the Go way.
One unified API across 20 providers. Streaming via channels, type-safe structured output with generics, zero external dependencies.
Open-source Go SDK
AI SDK, the Go way.
One unified API across 20 providers. Streaming via channels, type-safe structured output with generics, zero external dependencies.
go get github.com/zendev-sh/goai@latestcopy 1 package main
2
3 import (
4 "context"
5 "fmt"
6
7 "github.com/zendev-sh/goai"
8 "github.com/zendev-sh/goai/provider/openai"
9 )
10
11 func main() {
12 result, _ := goai.GenerateText(
13 context.Background(),
14 openai.Chat("gpt-4o"),
15 goai.WithPrompt("Explain goroutines."),
16 )
17 fmt.Println(result.Text)
18 }result, _ := goai.GenerateText(ctx,
openai.Chat("gpt-4o"),
goai.WithPrompt("Hello."),
)
fmt.Println(result.Text)stream, _ := goai.StreamText(ctx,
anthropic.Chat("claude-sonnet-4-6"),
goai.WithMessages(msgs...),
)
for chunk := range stream.TextStream() {
fmt.Print(chunk)
}type Recipe struct {
Name string `json:"name"`
Steps []string `json:"steps"`
}
recipe, _ := goai.GenerateObject[Recipe](ctx,
google.Chat("gemini-2.5-flash"),
goai.WithPrompt("Pho recipe"),
)calc := goai.Tool{
Name: "calc",
Execute: evalMath,
}
result, _ := goai.GenerateText(ctx, model,
goai.WithTools(calc),
goai.WithMaxSteps(5), // auto loop
goai.WithPrompt("127 * 43?"),
)// Auto-refresh OAuth tokens
ts := provider.CachedTokenSource(
func(ctx) (*provider.Token, error) {
tok, _ := oauth.Exchange(ctx, code)
return &provider.Token{
Value: tok.AccessToken,
ExpiresAt: tok.Expiry,
}, nil
},
)
model := openai.Chat("gpt-4o",
openai.WithTokenSource(ts),
)One unified API across 20 providers. Streaming via channels, type-safe structured output with generics, zero external dependencies.
