◉ Pulse
grafana avatar
#53 today

grafana/ai-sdk

Go AI

Grafana AI SDK for Go — streaming, tool-calling AI backends that speak fluent @ai-sdk/react

Created Jul 28, 2026
Stars
17
Today
+6
Forks
0
Quality
85/100
Momentum
18

README

Fetched from GitHub on Oct 30, 2026, 10:17 PM UTC · README.md

View original on GitHub

Third-party content — Open Source Pulse is not the owner of this repository.

This README belongs to grafana/ai-sdk and its contributors. We fetch it directly from the project’s public GitHub repository and display it for reference only. All text, code, images and trademarks remain the property of their respective authors. See the repository for its license terms. Copyright / takedown policy.

Grafana AI SDK for Go — streaming, tool-calling AI backends that speak fluent @ai-sdk/react

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.

Quick start · Documentation · Examples · API reference


Why

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 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 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.

Features

  • StreamText / GenerateText — stream a response or wait for the complete result, with retries and multi-step tool execution
  • 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, and OpenAI-compatible APIs
  • Production controls — configure timeouts, fallback, logging, Prometheus metrics, and Agent Observability

Install

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 for Amazon Bedrock, OpenAI, and OpenAI-compatible APIs.

Quick start

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. To stream this response to a React client, continue with Build a full-stack chat.

Where to go next

Goal Start here
Make model calls from Go Generate text from Go
Build a React chat Full-stack chat
Return typed data Structured output
Let a model call Go code Tools
Build a reusable agent Agent loops
Choose a model provider Provider overview
Add logging or observability Middleware overview
Prepare for production Production checklist

Full index: Documentation · Runnable code: Examples · Exact APIs: pkg.go.dev

Contributing

Contributions are welcome. 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.

License

The reusable SDK is licensed under Apache-2.0. The separate ai-gateway/ module is licensed under AGPL-3.0-only. See the SDK NOTICE and Gateway NOTICE for attribution.

Rendered by GitHub from the repository’s README. Scroll to read the full file.
First trending

Jul 29, 2026

first spotted on the list

Best rank

#14

highest position reached

Appearances

2

times on the trending list

Quality score

85

out of 100

Momentum

18

trend strength indicator

Star velocity

0.18

stars per day since creation

Activity — last 60 days

daily counts, collected every 6 hours
  • Stars
  • Forks
  • Merged PRs
  • Issues
  • Closed issues

Collecting activity data since launch — check back in a few days.

Star history

total stars per snapshot
1012141618grafana/ai-sdk · Jul 29, 2 PM UTC: 11 starsgrafana/ai-sdk · Jul 29, 7 PM UTC: 17 stars2:18 PM4:50 PM7:21 PM

Rank history

position on trending · lower is better
#1#10#20#30#40#50#60Jul 29, 2 PM UTC: rank #14Jul 29, 7 PM UTC: rank #532:18 PM4:50 PM7:21 PM

3D card for your website

Live HTML card with a glass surface and pointer tilt. Paste the iframe on any website.

<iframe src="https://www.notionpulse.cc/embed/grafana/ai-sdk" width="420" height="240" style="border:0;max-width:100%;background:transparent" loading="lazy" title="grafana/ai-sdk — trending on Open Source Pulse"></iframe>

Stars badge

Show current stars in your README or profile. Auto-updates every 6 hours.

grafana/ai-sdk stars badge
Markdown
[![grafana/ai-sdk](https://www.notionpulse.cc/api/badge/grafana/ai-sdk.svg)](https://www.notionpulse.cc/repo/grafana/ai-sdk)
HTML
<a href="https://www.notionpulse.cc/repo/grafana/ai-sdk"><img src="https://www.notionpulse.cc/api/badge/grafana/ai-sdk.svg" alt="grafana/ai-sdk stars badge" /></a>

Repository of the Day

#14 Repository of the Day

Repository of the Week

#14 Repository of the Week

Repository of the Month

#14 Repository of the Month