Installation
Requirements
- Go 1.25 or later
Install
go get github.com/zendev-sh/goai@latestThis installs the core SDK. Provider packages are included - no separate installs needed.
Import
import (
"github.com/zendev-sh/goai"
"github.com/zendev-sh/goai/provider/openai"
)Each provider has its own sub-package under provider/. Import only the providers you use:
import "github.com/zendev-sh/goai/provider/anthropic"
import "github.com/zendev-sh/goai/provider/google"
import "github.com/zendev-sh/goai/provider/bedrock"Verify
Create a file main.go:
package main
import (
"context"
"fmt"
"github.com/zendev-sh/goai"
"github.com/zendev-sh/goai/provider/openai"
)
func main() {
model := openai.Chat("gpt-4o")
result, err := goai.GenerateText(context.Background(), model,
goai.WithPrompt("Say hello in one sentence."),
)
if err != nil {
panic(err)
}
fmt.Println(result.Text)
}Set your API key and run:
export OPENAI_API_KEY="sk-..."
go run main.goIf you see a response from the model, the installation is working.
Dependencies
The only external dependency is golang.org/x/oauth2, used by the Vertex AI provider for Application Default Credentials. All other providers use the standard library.
Frequently Asked Questions
What Go version does GoAI SDK require?
GoAI SDK requires Go 1.25 or later due to its use of generics and latest standard library features.
Do I need to configure API keys manually?
No. GoAI SDK auto-resolves API keys from environment variables. Set OPENAI_API_KEY in your environment and openai.Chat("gpt-4o") will use it automatically. No explicit WithAPIKey needed.
Is GoAI SDK free for commercial use?
Yes. GoAI SDK is released under the MIT License, which allows free commercial use, modification, and distribution with no restrictions.
How do I switch between LLM providers?
Change one line — the provider import and model initialization. All 7 core functions (GenerateText, StreamText, GenerateObject, StreamObject, Embed, EmbedMany, GenerateImage) work identically across all 20+ providers.
Does GoAI SDK work with local models?
Yes. GoAI SDK supports Ollama and vLLM for local model serving. No API key required. You can also use the generic compat provider with any OpenAI-compatible endpoint.
What makes GoAI different from LangChainGo?
GoAI SDK is designed from scratch for Go with generics and interfaces, while LangChainGo is a port of Python's LangChain. GoAI supports 20+ providers (vs ~10), uses Go generics for type-safe structured output (GenerateObject[T]), and has minimal dependencies (stdlib only). See the comparison page for details.