# Go LLM SDK for streaming, tool-calling AI backends (plus frontend React lib)

> Source: <https://github.com/grafana/ai-sdk>
> Published: 2026-07-30 11:55:39+00:00

Call language models, stream responses, execute tools, and serve AI-powered endpoints from Go. Use the SDK on its own or pair it with an AI SDK React frontend.

The SDK gives Go applications one API for model calls, streaming, tools,
structured output, and multi-step agents across supported providers. It follows
the design of [Vercel's AI SDK](https://ai-sdk.dev) and stays wire-compatible
with its TypeScript frontend hooks. A Go endpoint can stream Server-Sent Events
(SSE) directly to hooks such as `useChat`

.

```
   Go backend                          React frontend
   ──────────                          ──────────────
   aisdk.StreamText(...)   ── SSE ──▶  useChat({ transport })
   aisdk.WriteUIMessageStream(w, …)    // same protocol
```

See [How a request runs](/grafana/ai-sdk/blob/main/docs/concepts/architecture.md) for the generation,
tool, and streaming flow. Reuse an existing AI SDK React frontend or replace a
TypeScript backend with Go without adding a protocol adapter.

— stream a response or wait for the complete result, with retries and multi-step tool execution`StreamText`

/`GenerateText`

**React compatibility**— serve`useChat`

,`useCompletion`

, and`useObject`

**Composable tools**— call plain Go functions from a model and require approval for consequential actions** Structured output**— generate schema-validated objects, arrays, and choices** Multiple providers**— call Anthropic, Amazon Bedrock, OpenAI, OpenAI-compatible APIs, and Grafana's hosted endpoint from internal services** Production controls**— configure timeouts, fallback, logging, Prometheus metrics, and[Agent Observability](/grafana/ai-sdk/blob/main/docs/middleware/agent-observability.md)

Create a Go project and install the core module and one provider:

```
mkdir ai-sdk-quickstart
cd ai-sdk-quickstart
go mod init example.com/ai-sdk-quickstart
go get github.com/grafana/ai-sdk
go get github.com/grafana/ai-sdk/providers/anthropic
```

See [Choose a provider](/grafana/ai-sdk/blob/main/docs/providers/overview.md) for Amazon Bedrock, OpenAI,
OpenAI-compatible APIs, and the internally provisioned Grafana hosted endpoint.

Save this complete program as `main.go`

. It makes one model call and prints the
response:

```
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	aisdk "github.com/grafana/ai-sdk"
	"github.com/grafana/ai-sdk/provider"
	"github.com/grafana/ai-sdk/providers/anthropic"
)

func main() {
	apiKey := os.Getenv("ANTHROPIC_API_KEY")
	if apiKey == "" {
		log.Fatal("ANTHROPIC_API_KEY is required")
	}

	model := anthropic.New(apiKey, "claude-sonnet-5")
	result, err := aisdk.GenerateText(context.Background(), model,
		aisdk.WithModelMessages(provider.UserText("Explain goroutines in one sentence.")),
	)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(result.Text)
}
```

Run it with an Anthropic API key:

```
ANTHROPIC_API_KEY=sk-... go run .
```

For project initialization and credential guidance, follow
[Installation](/grafana/ai-sdk/blob/main/docs/getting-started/installation.md). To stream this response to
a React client, continue with [Build a full-stack chat](/grafana/ai-sdk/blob/main/docs/getting-started/full-stack-chat.md).

| Goal | Start here |
|---|---|
| Make model calls from Go |
|

[Full-stack chat](/grafana/ai-sdk/blob/main/docs/getting-started/full-stack-chat.md)[Structured output](/grafana/ai-sdk/blob/main/docs/guides/structured-output.md)[Tools](/grafana/ai-sdk/blob/main/docs/guides/tools.md)[Agent loops](/grafana/ai-sdk/blob/main/docs/guides/agent-loops.md)[Provider overview](/grafana/ai-sdk/blob/main/docs/providers/overview.md)[Middleware overview](/grafana/ai-sdk/blob/main/docs/middleware/overview.md)[Production checklist](/grafana/ai-sdk/blob/main/docs/best-practices/production.md)Full index: ** Documentation** · Runnable code:

**· Exact APIs:**

[Examples](/grafana/ai-sdk/blob/main/examples)

[pkg.go.dev](https://pkg.go.dev/github.com/grafana/ai-sdk)Contributions are welcome. [CONTRIBUTING.md](/grafana/ai-sdk/blob/main/CONTRIBUTING.md) covers the
development setup, the two conventions that make this repository unusual —
upstream parity with the Vercel AI SDK, and spec-driven development with
OpenSpec — and the pull request checklist. All participants follow our
[Code of Conduct](/grafana/ai-sdk/blob/main/CODE_OF_CONDUCT.md).

[Apache License 2.0](/grafana/ai-sdk/blob/main/LICENSE). This SDK follows the design of
[Vercel's AI SDK](https://github.com/vercel/ai), also Apache-2.0 licensed;
attribution is recorded in [NOTICE](/grafana/ai-sdk/blob/main/NOTICE).
