Skip to content

Open-source Go SDK

GoAI

AI SDK, the Go way.

One unified API across 22+ providers. Streaming, structured output, MCP support, minimal dependencies.

$go get github.com/zendev-sh/goai@latestcopy
main.go
 1  package main
 2
 3  import (
 4      "context"
 5      "fmt"
 6
 7      "github.com/zendev-sh/goai"
 8      "github.com/zendev-sh/goai/provider/openai"
 9  )
10
11  func main() {
12      result, _ := goai.GenerateText(
13          context.Background(),
14          openai.Chat("gpt-4o"),
15          goai.WithPrompt("Explain goroutines."),
16      )
17      fmt.Println(result.Text)
18  }
22providers
100+models tested
24xfaster cold start
0third-party deps

What's New

v0.6.0 — OpenTelemetry tracing + metrics, context propagation via RequestInfo.Ctx, Langfuse data race fix. Changelog →

v0.5.8 — RunPod provider (serverless vLLM), Bedrock embeddings, and docs accuracy improvements. Changelog →

What is GoAI SDK?

GoAI SDK is an open-source Go library for building AI applications. It provides one unified API across 22+ LLM providers — OpenAI, Anthropic, Google Gemini, AWS Bedrock, Azure OpenAI, Groq, Mistral, Cohere, DeepSeek, Ollama, vLLM, and more.

Inspired by the Vercel AI SDK, GoAI is designed idiomatically for Go with generics, interfaces, and channels.

Core Features

  • GenerateText — non-streaming text generation across all providers
  • StreamText — real-time streaming with auto tool loops via Go channels
  • GenerateObject[T] — type-safe structured output using Go generics
  • StreamObject[T] — partial object streaming with typed results
  • Embed / EmbedMany — text embeddings with auto-chunking
  • GenerateImage — image generation (OpenAI, Google, Azure, Vertex AI)
  • Tool Calling — custom tools with auto tool loops (MaxSteps)
  • 20 Provider-Defined Tools — web search, code execution, computer use, file search
  • MCP Client — connect to any MCP server (stdio, HTTP, SSE), auto-convert tools for GoAI
  • Prompt Caching — automatic cache control for Anthropic and OpenAI
  • Observability — built-in Langfuse and OpenTelemetry integrations for tracing generations, tools, and multi-step loops

Why GoAI?

  • One API, 22+ providers — switch providers by changing one line of code
  • Minimal deps — core requires only golang.org/x/oauth2; optional OTel integration in separate submodule
  • Go-native design — generics for type safety, channels for streaming, interfaces for extensibility
  • 24x faster cold start than Vercel AI SDK (569μs vs 13.9ms)
  • 3.1x less memory per request (220KB vs 676KB)

Quick Start

go
package main

import (
    "context"
    "fmt"

    "github.com/zendev-sh/goai"
    "github.com/zendev-sh/goai/provider/openai"
)

func main() {
    result, _ := goai.GenerateText(context.Background(),
        openai.Chat("gpt-4o"),
        goai.WithPrompt("Explain Go interfaces in one sentence."),
    )
    fmt.Println(result.Text)
}

MCP Support v0.5.0

Connect to any MCP server and use its tools with GoAI:

go
transport := mcp.NewStdioTransport("npx", []string{"-y", "@modelcontextprotocol/server-github"})
client := mcp.NewClient("my-app", "1.0", mcp.WithTransport(transport))
_ = client.Connect(ctx)
defer client.Close()

tools, _ := client.ListTools(ctx, nil)
goaiTools := mcp.ConvertTools(client, tools.Tools)

result, _ := goai.GenerateText(ctx, model,
    goai.WithTools(goaiTools...),
    goai.WithPrompt("Search for popular Go repositories"),
    goai.WithMaxSteps(5),
)

3 transports (stdio, HTTP, SSE), tools/prompts/resources, pagination, notifications. Learn more →

Supported Providers

OpenAI, Anthropic, Google Gemini, AWS Bedrock, Azure OpenAI, Vertex AI, Cohere, Mistral, xAI (Grok), Groq, DeepSeek, Fireworks, Together AI, DeepInfra, OpenRouter, Perplexity, Cerebras, Ollama, vLLM, RunPod, and any OpenAI-compatible endpoint.

View all providers →

Explore the architecture →

Compare with other Go AI libraries →

Released under the MIT License.