Skip to content

openclaw-goThe Go SDK for OpenClaw

Connect agents, stream responses, discover gateways โ€” typed and production-ready.

openclaw-go mascot

Install โ€‹

sh
go get github.com/a3tai/openclaw-go@latest

Requires Go 1.24+. Single external dependency: gorilla/websocket.

Quick Start โ€‹

go
package main

import (
    "context"
    "encoding/json"
    "fmt"
    "log"

    "github.com/a3tai/openclaw-go/gateway"
    "github.com/a3tai/openclaw-go/identity"
    "github.com/a3tai/openclaw-go/protocol"
)

func main() {
    // Load or generate a device keypair for authenticated access.
    store, _ := identity.NewStore("~/.openclaw-go/identity")
    id, _ := store.LoadOrGenerate()
    deviceToken := store.LoadDeviceToken()

    client := gateway.NewClient(
        gateway.WithToken("my-token"),
        gateway.WithIdentity(id, deviceToken),
        gateway.WithRole(protocol.RoleOperator),
        gateway.WithScopes(protocol.ScopeOperatorRead, protocol.ScopeOperatorWrite),
        gateway.WithOnEvent(func(ev protocol.Event) {
            if ev.EventName == "chat" {
                var chat protocol.ChatEvent
                json.Unmarshal(ev.Payload, &chat)
                if chat.State == "delta" {
                    fmt.Print(string(chat.Message))
                }
            }
        }),
    )
    defer client.Close()

    ctx := context.Background()
    if err := client.Connect(ctx, "wss://my-gateway.example.com"); err != nil {
        log.Fatal(err)
    }

    // Send a message โ€” streaming deltas arrive via the event handler above.
    result, err := client.ChatSend(ctx, protocol.ChatSendParams{
        SessionKey:     "main",
        Message:        "Hello from Go!",
        IdempotencyKey: "hello-1",
    })
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("Run started: %s\n", result.RunID)
}

About โ€‹

openclaw-go is maintained by A3T โ€” the enterprise agent platform built on OpenClaw.

CIGo ReferenceLicense: MIT

Released under the MIT License.