openclaw-go

March 25, 2026 · View on GitHub

CI codecov Go Report Card Go Reference License: MIT Go Version

The Go client library for OpenClaw — the open gateway for AI agents. Maintained by A3T.

go get github.com/a3tai/openclaw-go

Provides typed clients for the Gateway WebSocket protocol, OpenAI-compatible HTTP APIs, local network discovery, and the Agent Client Protocol (ACP).

Install

go get github.com/a3tai/openclaw-go

Requires Go 1.25+. The only external dependency is gorilla/websocket.

Packages

PackageImportDescription
protocolgithub.com/a3tai/openclaw-go/protocolWire types, constants, and serialization for the Gateway WebSocket protocol (v3)
gatewaygithub.com/a3tai/openclaw-go/gatewayWebSocket client with full handshake, 96+ typed RPC methods, event/invoke callbacks
chatcompletionsgithub.com/a3tai/openclaw-go/chatcompletionsOpenAI-compatible Chat Completions HTTP client (streaming + non-streaming)
openresponsesgithub.com/a3tai/openclaw-go/openresponsesOpenAI Responses API HTTP client with typed SSE events and tool calling
toolsinvokegithub.com/a3tai/openclaw-go/toolsinvokeTools Invoke HTTP client (POST /tools/invoke)
discoverygithub.com/a3tai/openclaw-go/discoverymDNS/DNS-SD local network gateway discovery
acpgithub.com/a3tai/openclaw-go/acpAgent Client Protocol (JSON-RPC 2.0 over NDJSON) server for IDE integration

Quick Start

Gateway WebSocket Client

package main

import (
	"context"
	"fmt"
	"log"
	"time"

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

func main() {
	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
	defer cancel()

	client := gateway.NewClient(
		gateway.WithToken("my-token"),
		gateway.WithOnEvent(func(ev protocol.Event) {
			fmt.Printf("event: %s\n", ev.EventName)
		}),
	)
	defer client.Close()

	if err := client.Connect(ctx, "ws://localhost:18789/ws"); err != nil {
		log.Fatal(err)
	}

	result, err := client.ChatSend(ctx, protocol.ChatSendParams{
		SessionKey: "main",
		Message:    "Hello from Go!",
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("chat response: %+v\n", result)
}

Chat Completions (OpenAI-compatible)

client := &chatcompletions.Client{
	BaseURL: "http://localhost:18789",
	Token:   "my-token",
}

resp, _ := client.Create(ctx, chatcompletions.Request{
	Model:    "openclaw:main",
	Messages: []chatcompletions.Message{
		{Role: "user", Content: "Hello!"},
	},
})
fmt.Println(resp.Choices[0].Message.Content)

// Streaming
stream, _ := client.CreateStream(ctx, chatcompletions.Request{
	Model:    "openclaw:main",
	Messages: []chatcompletions.Message{
		{Role: "user", Content: "Tell me about Go"},
	},
})
defer stream.Close()

for {
	chunk, err := stream.Recv()
	if err == io.EOF { break }
	fmt.Print(chunk.Choices[0].Delta.Content)
}

Tools Invoke

client := &toolsinvoke.Client{
	BaseURL: "http://localhost:18789",
	Token:   "my-token",
}

resp, _ := client.Invoke(ctx, toolsinvoke.Request{
	Tool:   "sessions_list",
	Action: "json",
})
fmt.Printf("result: %s\n", resp.Result)

Network Discovery

browser := discovery.NewBrowser()
beacons, _ := browser.Browse(ctx)
for _, b := range beacons {
	fmt.Printf("%s -> %s\n", b.DisplayName, b.WebSocketURL())
}

Examples

Runnable examples are in examples/. Start the mock server first:

go run ./examples/server

Then run any example:

go run ./examples/chat
go run ./examples/client
go run ./examples/openresponses
go run ./examples/agents
go run ./examples/sessions
go run ./examples/approvals
go run ./examples/pairing
go run ./examples/config
go run ./examples/cron
go run ./examples/node
go run ./examples/discovery
go run ./examples/acp
ExampleWhat it demonstrates
serverMock gateway for local development
clientAll three APIs: WebSocket, Chat Completions, Tools Invoke
chatInteractive chat with streaming events
openresponsesOpenAI Responses API with tool definitions
agentsAgent CRUD: list, create, update, files, delete
sessionsSession management: list, preview, patch, usage, reset
approvalsExec approval flow: listen, approve/reject, admin config
pairingNode and device pairing workflows
configGateway configuration: get, schema, patch, apply
cronCron jobs: list, add, run, history, remove
nodeConnect as a node: declare capabilities, handle invocations
discoveryScan the LAN for gateways via mDNS
acpACP agent server over stdio

Testing

go test ./... -race
go vet ./...

All library packages target 100% statement coverage (except discovery/ at 98.2% due to platform exec wrappers).

Documentation

See the docs/ directory for per-package API guides:

About

This project is independently maintained by Rude Company LLC (d/b/a a3t.ai) and is not officially affiliated with the OpenClaw project.

Many thanks to Peter Steinberger for creating OpenClaw and giving it to the world. His vision for an open, local-first AI gateway has made projects like this possible. With all love and respect.

Author: Steve Rude steve@a3t.ai

License

MIT -- see LICENSE for details.