A production-ready Go SDK for building AI-powered applications. Provider-agnostic, type-safe, and observable.
- Multi-Provider Support: OpenAI, Anthropic, Gemini, Groq, xAI, and any OpenAI-compatible endpoint
- Type-Safe Tools: Generic tool framework with automatic JSON schema derivation from Go types
- Normalized Streaming: Unified
gai.events.v1event schema across all providers (SSE/NDJSON) - Structured Outputs: Type-safe structured generation with automatic repair
- Multi-Step Runner: Orchestrates tool execution with stop conditions and finalizers
- Observability: Built-in OpenTelemetry tracing and metrics
- Multimodal: Support for text, images, audio, video, and files
go get github.com/shillcollin/gaipackage main
import (
"context"
"fmt"
"os"
"github.com/shillcollin/gai/core"
"github.com/shillcollin/gai/providers/openai"
)
func main() {
client := openai.New(
openai.WithAPIKey(os.Getenv("OPENAI_API_KEY")),
openai.WithModel("gpt-4o"),
)
result, err := client.GenerateText(context.Background(), core.Request{
Messages: []core.Message{
core.UserMessage(core.TextPart("Hello, world!")),
},
})
if err != nil {
panic(err)
}
fmt.Println(result.Text)
}| Provider | Package | Status |
|---|---|---|
| OpenAI | providers/openai |
Stable |
| OpenAI Responses API | providers/openai-responses |
Stable |
| Anthropic | providers/anthropic |
Stable |
| Google Gemini | providers/gemini |
Stable |
| Groq | providers/groq |
Stable |
| xAI | providers/xai |
Stable |
| OpenAI-Compatible | providers/compat |
Stable |
core/- Provider interface, messages, parts, requests, streaming, structured outputsproviders/- Provider implementationsrunner/- Multi-step tool execution orchestratortools/- Type-safe tool frameworkstream/- Streaming helpers for SSE/NDJSONobs/- OpenTelemetry integrationprompts/- Versioned prompt registry
See the examples/ directory for runnable examples:
examples/basic/- Basic text generationexamples/streaming/- Streaming responsesexamples/structured/- Structured outputsexamples/tools/- Tool usageexamples/observability/- OpenTelemetry integration
MIT