Go SDK

In Development

The Go SDK is under active development. API surface is stabilizing but may still change before v1.0.

github.com/useioxyz/io-sdk-go — idiomatic Go SDK for IO. context.Context throughout, SSE streaming, testify-tested.


Installation

go get github.com/useioxyz/io-sdk-go

Requires: Go 1.21+


Quick Start

package main
 
import (
    "context"
    "fmt"
    "log"
 
    "github.com/useioxyz/io-sdk-go"
)
 
func main() {
    ctx := context.Background()
    client := io.New("your-api-key")
 
    resp, err := client.Completions.Create(ctx, io.CompletionRequest{
        Model: "auto",
        Messages: []io.Message{{
            Role: "user", Content: "Hello, IO!",
        }},
    })
    if err != nil {
        log.Fatal(err)
    }
 
    fmt.Println(resp.Message)
    fmt.Println("Receipt:", resp.Receipt.Signature)
}

Streaming

ctx := context.Background()
stream, err := client.Stream.Create(ctx, io.StreamRequest{
    Model: "auto",
    Messages: []io.Message{{
        Role: "user", Content: "Count to 10",
    }},
})
if err != nil {
    log.Fatal(err)
}
defer stream.Close()
 
for chunk := range stream.Chunks() {
    fmt.Print(chunk.Delta)
}

Package Layout

io-sdk-go/
├── pkg/
│   ├── client.go       # HTTP client, auth, base URL
│   ├── completions.go  # Completions API
│   ├── stream.go       # SSE streaming
│   ├── broadcast.go    # Broadcast API
│   ├── diffuse.go      # Diffuse API
│   ├── batch.go        # Batch API
│   ├── diff.go         # Diff API
│   ├── receipts.go     # Receipt verification
│   ├── redact.go       # PII redaction
│   ├── models.go       # Model listing
│   ├── health.go       # Health checks
│   ├── timer.go        # Self-destruct timers
│   └── types.go        # Shared types
└── examples/
    └── basic/
        └── main.go

Error Handling

resp, err := client.Completions.Create(ctx, req)
if err != nil {
    var rateErr *io.RateLimitError
    if errors.As(err, &rateErr) {
        fmt.Printf("Rate limited. Retry after %ds\n", rateErr.RetryAfter)
    }
    var authErr *io.AuthError
    if errors.As(err, &authErr) {
        fmt.Println("Invalid API key")
    }
}