# Go

URL: https://docs.hanzo.ai/docs/sdks/go

> go get github.com/hanzoai/go-sdk/v8 — package hanzoai at the module root, one service per capability, generated from the API's own document.

```bash
go get github.com/hanzoai/go-sdk/v8
```

```go
import hanzoai "github.com/hanzoai/go-sdk/v8"
```

The package name is `hanzoai` and it sits at the module root, beside `go.mod` —
which is why the import path and the package identifier differ. The module path
carries its major, `/v8`, as Go requires of any release past v1: without it,
`go get github.com/hanzoai/go-sdk` resolves v1.0.5, an older client whose
methods are spelled differently. The source lives at
[hanzo-go/sdk](https://github.com/hanzo-go/sdk).

Set the key:

```bash
export HANZO_API_KEY="sk-..."   # from platform.hanzo.ai
```

## The shape

One configuration, one client, one service field per capability:

```go
package main

import (
    "context"
    "fmt"
    "os"

    hanzoai "github.com/hanzoai/go-sdk/v8"
)

func main() {
    cfg := hanzoai.NewConfiguration()
    cfg.AddDefaultHeader("Authorization", "Bearer "+os.Getenv("HANZO_API_KEY"))
    client := hanzoai.NewAPIClient(cfg)

    models, _, err := client.AiAPI.GetModels(context.Background()).Execute()
    if err != nil {
        panic(err)
    }
    fmt.Println(models)
}
```

Every operation is a request builder: the method takes a `context.Context` and
returns a request you finish with `.Execute()`, which answers the decoded value,
the `*http.Response` and an error. Optional parameters are setters on the
request in between.

The service field is the capability — `client.AiAPI`, `client.BillingAPI`,
`client.KmsAPI` — and the method is the operation. The
[reference](https://docs.hanzo.ai/docs/openapi) prints the pair for each one.

> **OpenAI-shaped calls**
>
> The chat, embeddings and messages routes speak the OpenAI and Anthropic wire
> formats, so an existing Go client for either works against
> `https://api.hanzo.ai/v1` with a Hanzo key. This client adds the rest of `/v1`.

## Resources

- [`github.com/hanzoai/go-sdk/v8` on pkg.go.dev](https://pkg.go.dev/github.com/hanzoai/go-sdk/v8)
- Source — [hanzo-go/sdk](https://github.com/hanzo-go/sdk)
- [Every `/v1` operation →](https://docs.hanzo.ai/docs/openapi)
