The Go AI SDK is a comprehensive toolkit designed to help you build AI-powered applications and agents using Go. It provides 1:1 feature parity with the Vercel AI SDK for backend functionality.
To learn more about how to use the Go AI SDK, check out our Documentation.
Reasoning parameter across 10+ providersSee the full release notes and changelog.
You will need Go 1.21+ installed on your local development machine.
go get github.com/digitallysavvy/go-ai@v0.4.0
The Go AI SDK provides a unified API to interact with model providers like OpenAI, Anthropic, Google, and more.
go get github.com/digitallysavvy/go-ai/pkg/providers/openai
go get github.com/digitallysavvy/go-ai/pkg/providers/anthropic
go get github.com/digitallysavvy/go-ai/pkg/providers/google
import (
"context"
"fmt"
"os"
"github.com/digitallysavvy/go-ai/pkg/ai"
"github.com/digitallysavvy/go-ai/pkg/providers/openai"
)
func main() {
ctx := context.Background()
provider := openai.New(openai.Config{
APIKey: os.Getenv("OPENAI_API_KEY"),
})
model, _ := provider.LanguageModel("gpt-5.4")
result, _ := ai.GenerateText(ctx, ai.GenerateTextOptions{
Model: model,
Prompt: "What is an agent?",
})
fmt.Println(result.Text)
}
stream, _ := ai.StreamText(ctx, ai.StreamTextOptions{
Model: model,
Prompt: "Write a story about Go programming",
})
for chunk := range stream.TextChannel {
fmt.Print(chunk)
}
import "github.com/digitallysavvy/go-ai/pkg/schema"
type Recipe struct {
Name string `json:"name"`
Ingredients []string `json:"ingredients"`
Steps []string `json:"steps"`
}
recipeSchema := schema.NewSimpleJSONSchema(map[string]interface{}{
"type": "object",
"properties": map[string]interface{}{
"name": map[string]interface{}{"type": "string"},
"ingredients": map[string]interface{}{"type": "array", "items": map[string]interface{}{"type": "string"}},
"steps": map[string]interface{}{"type": "array", "items": map[string]interface{}{"type": "string"}},
},
"required": []string{"name", "ingredients", "steps"},
})
result, _ := ai.GenerateObject(ctx, ai.GenerateObjectOptions{
Model: model,
Prompt: "Generate a lasagna recipe.",
Schema: recipeSchema,
})
var recipe Recipe
json.Unmarshal([]byte(result.Object), &recipe)
fmt.Printf("Recipe: %s\n", recipe.Name)
Build autonomous agents with multi-step reasoning:
import (
"github.com/digitallysavvy/go-ai/pkg/agent"
"github.com/digitallysavvy/go-ai/pkg/provider/types"
)
myAgent := agent.New(agent.Config{
Model: model,
Instructions: "You are a helpful research assistant.",
Tools: []types.Tool{
searchTool,
calculatorTool,
},
MaxSteps: 10,
})
result, _ := myAgent.Execute(ctx, "What is the population of Tokyo?")
fmt.Println(result.Text)
Extend AI capabilities with custom tools:
import "github.com/digitallysavvy/go-ai/pkg/provider/types"
weatherTool := types.Tool{
Name: "get_weather",
Description: "Get current weather for a location",
Parameters: map[string]interface{}{
"type": "object",
"properties": map[string]interface{}{
"location": map[string]interface{}{
"type": "string",
"description": "City name",
},
},
"required": []string{"location"},
},
Execute: func(ctx context.Context, params map[string]interface{}, opts types.ToolExecutionOptions) (interface{}, error) {
location := params["location"].(string)
return map[string]interface{}{
"temperature": 72,
"condition": "sunny",
}, nil
},
}
result, _ := ai.GenerateText(ctx, ai.GenerateTextOptions{
Model: model,
Prompt: "What's the weather in San Francisco?",
Tools: []types.Tool{weatherTool},
})
Generate embeddings for semantic search:
embeddingModel, _ := provider.EmbeddingModel("text-embedding-3-small")
result, _ := ai.Embed(ctx, ai.EmbedOptions{
Model: embeddingModel,
Input: "Go is great for building AI applications",
})
// result.Embedding contains the vector
imageModel, _ := provider.ImageModel("dall-e-3")
result, _ := ai.GenerateImage(ctx, ai.GenerateImageOptions{
Model: imageModel,
Prompt: "A serene mountain landscape at sunset",
Size: "1024x1024",
})
// result.Image contains the generated image bytes
// Generate speech
speechModel, _ := provider.SpeechModel("tts-1")
result, _ := ai.GenerateSpeech(ctx, ai.GenerateSpeechOptions{
Model: speechModel,
Text: "Hello, welcome to the Go AI SDK!",
Voice: "alloy",
})
// Transcribe audio
transcriptionModel, _ := provider.TranscriptionModel("whisper-1")
transcript, _ := ai.Transcribe(ctx, ai.TranscribeOptions{
Model: transcriptionModel,
Audio: audioBytes,
})
Reduce memory consumption by 50-80% for image-heavy or large-context workloads using retention settings:
import "github.com/digitallysavvy/go-ai/pkg/provider/types"
// Enable memory optimization
retention := &types.RetentionSettings{
RequestBody: types.BoolPtr(false), // Don't retain request
ResponseBody: types.BoolPtr(false), // Don't retain response
}
result, _ := ai.GenerateText(ctx, ai.GenerateTextOptions{
Model: model,
Prompt: "Analyze this image...",
ExperimentalRetention: retention,
})
// Result still has usage, finish reason, text, etc.
// But raw request/response bodies are excluded to save memory
Perfect for: - 🖼️ Image processing workloads - 📄 Large document analysis - 🔒 Privacy-sensitive applications - ⚡ Long-running services
See examples/features/retention for detailed usage.
The Go AI SDK supports 30+ providers:
| Provider | Language Models | Embeddings | Images / Video | Speech |
|---|---|---|---|---|
| OpenAI | GPT-5.4, GPT-5.3, O3, O4 | ✓ | DALL-E | TTS, Whisper |
| Anthropic | Claude Sonnet 4.6, Opus 4.6 | - | - | - |
| Gemini 3, 2.5 Pro/Flash | ✓ | - | - | |
| Google Vertex | Gemini (enterprise) | ✓ | Imagen | - |
| AWS Bedrock | Claude, Titan, Nova, Llama | ✓ | - | - |
| Azure OpenAI | Azure-hosted models | ✓ | ✓ | ✓ |
| xAI | Grok-3 (Responses API) | - | ✓ | - |
| Mistral | Large, Small | ✓ | - | - |
| Cohere | Command R+, Command | ✓ | - | - |
| Groq | Llama, Mixtral | - | - | Whisper |
| Together AI | Llama, Mixtral, Qwen | - | Stable Diffusion | - |
| Fireworks | Llama, Mixtral | ✓ | FLUX Kontext | - |
| Perplexity | Sonar models | - | - | - |
| DeepSeek | DeepSeek R1, Chat | - | - | - |
| Alibaba | Qwen models | ✓ | - | - |
| KlingAI | - | - | Video (v3.0) | - |
| Prodia | img2img | - | Video (T2V/I2V) | - |
| Ollama | Local models | ✓ | - | - |
And more (Replicate, Hugging Face, Stability, ElevenLabs, Deepgram, Gladia, LMNT, ByteDance, Baseten, Cerebras, DeepInfra, Gateway)...
GenerateText() and StreamText()GenerateObject() with JSON validationReasoning parameter across providers (Anthropic, OpenAI, Google, Bedrock, xAI, and more)ToolLoopAgent"openai:gpt-5.4")While Python dominates AI/ML model training, Go excels at building production AI applications:
We provide 50+ production-ready examples covering every feature. See the examples directory for complete working code.
net/http with SSE streamingAll examples: - ✅ Comp
$ claude mcp add go-ai \
-- python -m otcore.mcp_server <graph>