Getting Started
The following guides are intended to provide you with an introduction to some of the core features provided by the Go AI SDK.
Quick Start
Get started quickly with our comprehensive tutorial:
- Go Quick Start - Build your first AI agent with the Go AI SDK in 5 minutes
Learn the Library
- Navigating the Library - Understand the structure and choose the right tools for your needs
What You'll Learn
These guides will walk you through:
- Setting up your environment - Install the SDK and configure your API keys
- Core concepts - Understand providers, models, and streaming
- Streaming - Print text as the model produces it
- Using tools - Extend your agent with external capabilities and build a chat loop
- Production patterns - Best practices for real-world applications
Prerequisites
To follow these guides, you'll need:
- Go 1.26+ installed on your development machine
- An API key from at least one AI provider (OpenAI, Anthropic, Google, etc.)
- Basic Go knowledge - Understanding of packages, error handling, and goroutines
Quick Installation
go get github.com/digitallysavvy/go-ai
Example: Your First AI Application
Set your API key in the shell, then run a minimal program:
export OPENAI_API_KEY=sk-...
package main
import (
"context"
"fmt"
"log"
"github.com/digitallysavvy/go-ai/pkg/ai"
"github.com/digitallysavvy/go-ai/pkg/providers/openai"
)
func main() {
model, err := openai.New(openai.Config{}).LanguageModel(openai.ModelGPT6Astra)
if err != nil {
log.Fatal(err)
}
result, err := ai.GenerateText(context.Background(), ai.GenerateTextOptions{
Model: model,
Prompt: "Explain what makes Go great for AI applications.",
})
if err != nil {
log.Fatal(err)
}
fmt.Println(result.Text)
}
The Go Quick Start builds on this program with streaming, a tool, and a chat loop.
API Servers and Frameworks
You can use the Go AI SDK with any Go web framework or server:
- net/http - Standard library HTTP server
- Gin - High-performance web framework
- Echo - Minimalist web framework
- Fiber - Express-inspired framework
- Chi - Lightweight router
- Gorilla - Web toolkit
- gRPC - For high-performance RPC services
Example with net/http:
func streamHandler(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
stream, err := ai.StreamText(ctx, ai.StreamTextOptions{
Model: model,
Prompt: "Write a story...",
})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "text/event-stream")
w.Header().Set("Cache-Control", "no-cache")
flusher, _ := w.(http.Flusher)
for chunk := range stream.Chunks() {
fmt.Fprintf(w, "data: %s\n\n", chunk.Text)
flusher.Flush()
}
}
Next Steps
After completing the getting started guide, explore:
- Build a chat app - Serve a
useChatfrontend from Go, add tool approval and run coding agents, based on the Shipyard demo - Recipes - Short, complete programs for common tasks
- Foundations - Deep dive into core concepts
- AI SDK Core - Complete API reference
- Agents - Build autonomous agents
- Advanced Topics - Production-ready patterns
Need Help?
- Documentation: You're reading it!
- GitHub Issues: Report bugs or ask questions
- Examples: Check the
examples/directory in the repository