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.
useChat hook.Get started
Go from an empty directory to a real model response in three small steps.
-
Create the project
Install the core module and only the provider your application uses.
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 -
Generate a response
Create a model, pass a typed user message, and handle the ordinary Go result.
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
Set the provider credential and run the program.
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.