AI Decision System
Replayable, offline-verifiable records for AI-assisted go/no-go decisions: experiment promotions, typed model answers and human-approved actions.
翻譯準備中
Golang 的 AI 工具包。GO AI SDK 是免費開源的程式庫,用於構建 AI 驅動的應用程式與代理。
AI 翻譯
The AI Toolkit for Golang. The GO AI SDK is a free open-source library for building AI-powered applications and agents
取自儲存庫 README
正在載入完整 README。 以下為已儲存的摘錄。
The AI SDK, in Go.
Generate and stream text, call tools, run agents and connect to MCP servers
across 49 providers, with one API that tracks the TypeScript AI SDK.
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 the documentation.檢視完整 README ↗go get github.com/digitallysavvy/go-ai
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 the documentation.
GenerateText / StreamText now stop after one step unless you set StopWhen (TS parity); use ai.IsStepCount(n) or ai.IsLoopFinished() to run tool loops. agent.NewToolLoopAgent defaults to 20 stepsChunkTypeFinish now fires once per call (not once per step); each step is bracketed by new ChunkTypeStartStep / ChunkTypeFinishStep chunks, and StreamText itself returns before the first model requestLanguageModel() (Responses API) is the only xAI language modelbedrock.LanguageModel now calls the Converse API instead of /invoke; Bedrock-Anthropic is rebuilt on anthropic.LanguageModelai.ExperimentalStartVideo / ExperimentalGetVideoStatus for fal, Google, Google Vertex, Replicate and xAI, plus Google Vertex Veo supportpkg/codemode runs model-written JavaScript in a QuickJS-on-WebAssembly sandbox with TS execution-policy limitspkg/harness (Go port of @ai-sdk/harness) with adapters for Claude Code, Codex, OpenCode, Deep Agents, ACP, Cursor, GitHub Copilot, Grok Build, and a Vercel Sandbox providerSee the full release notes and changelog, and the v0.4 → v0.5 migration guide.
You will need Go 1.26+ installed on your local development machine.
go get github.com/digitallysavvy/[email protected]
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
📖 Generating text · GenerateText reference
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-6-astra")
result, _ := ai.GenerateText(ctx, ai.GenerateTextOptions{
Model: model,
Prompt: "What is an agent?",
})
fmt.Println(result.Text)
}
📖 Streaming · StreamText reference
stream, _ := ai.StreamText(ctx, ai.StreamTextOptions{
Model: model,
Prompt: "Write a story about Go programming",
})
defer stream.Close()
for chunk := range stream.Chunks() {
if chunk.Type == provider.ChunkTypeText {
fmt.Print(chunk.Text)
}
}
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)
📖 Agents overview · Building agents
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.NewToolLoopAgent(agent.AgentConfig{
Model: model,
System: "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)
📖 Tools and tool calling · MCP tools
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("gpt-image-2")
result, _ := ai.GenerateImage(ctx, ai.GenerateImageOptions{
Model: imageModel,
Prompt: "A serene mountain landscape at sunset",
Size: "1024x1024",
})
// result.Image contains the generated image bytes
📖 Speech · Transcription
// Generate speech
speechModel, _ := provider.SpeechModel("gpt-4o-mini-tts")
result, _ := ai.GenerateSpeech(ctx, ai.GenerateSpeechOptions{
Model: speechModel,
Text: "Hello, welcome to the Go AI SDK!",
Voice: "alloy",
})
// Transcribe audio
transcriptionModel, _ := provider.TranscriptionModel("gpt-4o-transcribe")
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:
See examples/features/retention for detailed usage.
The Go AI SDK supports 49 providers:
| Provider | Language Models | Embeddings | Images / Video | Speech |
|---|---|---|---|---|
| OpenAI | GPT-5 family, o-series | ✓ | GPT Image | TTS, Whisper |
| Anthropic | Claude Opus, Sonnet, Haiku | - | - | - |
| Gemini 3 family | ✓ | Gemini image, Veo | TTS, transcription | |
| Google Vertex | Gemini (enterprise) | ✓ | Gemini image, Veo | TTS, transcription |
| AWS Bedrock | Claude, Titan, Nova, Llama | ✓ | - | - |
| Azure OpenAI | Azure-hosted models | ✓ | ✓ | ✓ |
| xAI | Grok 4 family (Responses) | - | ✓ | - |
| Mistral | Large, Medium, 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 | ✓ | - | - |
| QuiverAI | SVG generation/vectorization | - | SVG | - |
| KlingAI | - | - |
And more (Replicate, Hugging Face, Stability, ElevenLabs, Deepgram, Gladia, LMNT, ByteDance, Baseten, Cerebras, DeepInfra, Gateway, GMI Cloud, Z.AI, MiniMax, TypeSafe AI, Fish Audio, Cartesia, Rev.ai, Hume, Luma, BFL, Voyage, AssemblyAI, Vercel, Moonshot, Anthropic AWS, Google Vertex xAI, Open Responses, QuiverAI, Topaz Labs)...
GenerateText() and StreamText()GenerateObject() with JSON validationReasoning parameter across providers (Anthropic, OpenAI, Google, Bedrock, xAI, and more)ToolLoopAgent"openai:gpt-5.4")pkg/ai stream transport helpers:
CreateTextStreamResponse(), PipeTextStreamToResponse(), CreateUIMessageStream(), CreateUIMessageStreamResponse(), PipeUIMessageStreamToResponse(), ReadUIMessageStream()pkg/ai utility compatibility helpers:
ConsumeStream(), ParsePartialJSON(), SimulateReadableStream()pkg/ai middleware aliases:
WrapLanguageModel(), WrapEmbeddingModel(), WrapProvider()DefaultSettingsMiddleware(), SimulateStreamingMiddleware(), ExtractJSONMiddleware(), ExtractReasoningMiddleware(), AddToolInputExamplesMiddleware()pkg/agent UI stream helpers:
CreateAgentUIStream(), CreateAgentUIStreamResponse(), PipeAgentUIStreamToResponse()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:
go vetShipyard is a Next.js chat UI backed by a Go server built with this SDK. It uses the stock useChat hook, gates a tool behind a signed user approval, and hands code changes to Claude Code or Codex through the harness. Read the code with the guides:
Short task pages with runnable programs are in Recipes, built from examples/recipes.
The full docs site is at https://goaisdk.com/.
llms.txt indexes every docs page; llms-full.txt is the whole documentation in one file..md appended returns that page as markdown, for example https://goaisdk.com/docs/foundations/tools.md.This SDK maintains 1:1 feature parity with the Vercel AI SDK [email protected] for backend functionality:
A handful of features are intentionally TS-only (browser WebRTC realtime, the
@ai-sdk/harness-cline / @ai-sdk/harness-pi Node-SDK-in-process harnesses,
durable webhook video suspension inside workflows) — see
Known Differences.
Not included: React/UI components (@ai-sdk/react, @ai-sdk/vue, etc.) — these are client-side only in the TypeScript SDK.
The Go AI SDK community can be found on GitHub where you can ask questions, voice ideas, and share your projects:
Contributions to the Go AI SDK are welcome and highly appreciated. However, before you jump right into it, we would like you to review our Contribution Guidelines to make sure you have a smooth experience contributing to the Go AI SDK.
Apache 2.0 - See LICENSE for details.
Go is a trademark of Google.
The Go gopher, whenever used, is an original creation by Renée French.
This library is created by @digitallysavvy, inspired by the Vercel AI SDK, with contributions from the Open Source Community.
| Video (v3.0) |
| - |
| Prodia | img2img | - | Video (T2V/I2V) | - |
| Ollama | Local models | ✓ | - | - |