GRAFANA LABS AI WEEK 27–31 JUL 2026 SAVE THE DATE

AI SDK

Go API. React-native streaming. One path from model call to user interface.

Build text, structured output, tools, and agent loops with one API—without a protocol adapter.

Start building View on GitHub

The Grafana AI SDK streaming a response from a Go server to an AI SDK React chat client over Server-Sent Events.
One Go handler streams the UI message protocol consumed by the AI SDK React useChat hook.

Get started

Go from an empty directory to a real model response in three small steps.

  1. Create the project

    Install the core module and only the provider your application uses.

    Terminal
     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
  2. Generate a response

    Create a model, pass a typed user message, and handle the ordinary Go result.

    main.go
    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)
    }
  3. Run it

    Set the provider credential and run the program.

    Terminal
     ANTHROPIC_API_KEY=sk-... go run .

    Provider modules stay separate, so applications only carry the integrations they need. Read the installation guide.

Start with what you need to build

Move directly from an application outcome to the maintained guide and runnable code.

See example apps