SDKs
Go SDK
The Hanzo Go Cloud SDK — go get github.com/hanzoai/go-sdk. Functional options, minimal dependencies.
Go SDK
The Go Cloud SDK is a typed client for the entire Open AI Cloud (/v1/*) —
functional-options API, minimal dependencies, context-aware. Generally available.
Install
go get github.com/hanzoai/go-sdkimport (
"github.com/hanzoai/go-sdk"
"github.com/hanzoai/go-sdk/option"
)Set your key:
export HANZO_API_KEY="hk-..." # from console.hanzo.aiQuick start
package main
import (
"context"
"fmt"
"github.com/hanzoai/go-sdk"
"github.com/hanzoai/go-sdk/option"
)
func main() {
client := hanzoai.NewClient(
option.WithAPIKey("hk-your-key"), // or HANZO_API_KEY
)
resp, err := client.Chat.Completions.New(context.TODO(), hanzoai.ChatCompletionNewParams{
Model: hanzoai.F("zen5"),
Messages: hanzoai.F([]hanzoai.ChatCompletionMessageParamUnion{
hanzoai.UserMessage("Explain quantum computing"),
}),
})
if err != nil {
panic(err)
}
fmt.Println(resp.Choices[0].Message.Content)
}Streaming
stream := client.Chat.Completions.NewStreaming(ctx, hanzoai.ChatCompletionNewParams{
Model: hanzoai.F("zen5-coder"),
Messages: hanzoai.F([]hanzoai.ChatCompletionMessageParamUnion{
hanzoai.UserMessage("Write a haiku about AI"),
}),
})
for stream.Next() {
chunk := stream.Current()
if len(chunk.Choices) > 0 {
fmt.Print(chunk.Choices[0].Delta.Content)
}
}
if stream.Err() != nil {
panic(stream.Err())
}Base URL
Point the client at any service with option.WithBaseURL("https://api.hanzo.ai/v1")
— the default. One key works across every /v1 service.
Resources
- Cloud SDK —
go get github.com/hanzoai/go-sdk· org hanzo-go - Umbrella — hanzoai/sdk
- API reference — every
/v1endpoint →
How is this guide?
Last updated on