Skip to content

Installation ​

Requirements ​

  • Go 1.25 or later

Install ​

bash
go get github.com/zendev-sh/goai@latest

This installs the core SDK. Provider packages are included - no separate installs needed.

Import ​

go
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:

go
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:

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:

bash
export OPENAI_API_KEY="sk-..."
go run main.go

If you see a response from the model, the installation is working.

Dependencies ​

The only external runtime dependency in the core module is golang.org/x/oauth2, used by the Vertex AI provider for Application Default Credentials. The module also uses go.uber.org/goleak in tests; all other provider runtime code uses the standard library.

The optional observability/otel submodule has its own go.mod with OpenTelemetry SDK dependencies. It is not pulled into your project unless you explicitly import it.

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 the provider import and model constructor while keeping the same core API. GoAI exposes eight core functions: GenerateText, StreamText, GenerateObject, StreamObject, Embed, EmbedMany, GenerateImage, and GenerateVideo. Model capabilities vary by provider.

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 25+ providers (vs ~10), uses Go generics for type-safe structured output (GenerateObject[T]), and has minimal dependencies. See the comparison page for details.

Released under the MIT License.