Skip to content
dhanu docs
Browse pages

SDKs

Go SDK

The official dhanu-go module, one client, every resource, retries and webhook verification, no dependencies.

go get github.com/dhanu-ai/dhanu-go
import dhanu "github.com/dhanu-ai/dhanu-go"

client, err := dhanu.NewClient(os.Getenv("DHANU_API_KEY"))
if err != nil { log.Fatal(err) }

text, err := client.Text.Generate(ctx, dhanu.GenerateTextParams{Prompt: "Write a haiku about Kathmandu"})

task, err := client.Tasks.Create(ctx, dhanu.CreateTaskParams{Input: "Summarise this week's tickets", StaffID: staffID})
page, err := client.Tasks.Messages(ctx, task.ID, dhanu.PageParams{Limit: 50})

result, err := client.Text.Stream(ctx, dhanu.GenerateTextParams{Prompt: "Explain Bikram Sambat"}, func(d dhanu.TextDelta) {
    fmt.Print(d.Text)
})

file, err := client.Files.Upload(ctx, "notes.txt", "text/plain", data)
job, err := client.Jobs.Wait(ctx, jobID, 2*time.Second)
event, err := client.Webhooks.Verify(rawBody, r.Header.Get("Dhanu-Signature"), secret)

Every call takes a context.Context and returns a typed value or *dhanu.Error (Code, Status, Message, RequestID). Network errors, 408, 429 and 5xx are retried twice honouring Retry-After; JSON POSTs carry a generated Idempotency-Key unless you pass one in RequestOptions. DHANU_BASE_URL or dhanu.WithBaseURL points the client at a local server; dhanu.WithHTTPClient swaps the transport.