Skip to main content

Go SDK

The official Visent Go SDK provides high-performance integration with Visent APIs, designed for production applications requiring low latency and high throughput. Built with Go’s concurrency patterns and comprehensive error handling. Supports Go 1.19+ with full context support, structured logging, and graceful shutdown patterns.

Installation

# Using go mod
go get github.com/visent/go-sdk

# In your go.mod
require github.com/visent/go-sdk v1.0.0

Quick Start

Basic Setup

package main

import (
    "context"
    "fmt"
    "log"
    "os"
    
    "github.com/visent/go-sdk"
)

func main() {
    // Initialize client
    client := visent.NewClient(visent.Config{
        APIKey: os.Getenv("VISENT_API_KEY"),
        // Optional: custom HTTP client
        // HTTPClient: &http.Client{Timeout: 30 * time.Second},
    })
    
    ctx := context.Background()
    
    // Use the client
    metrics, err := client.Telemetry.GetMetrics(ctx, &visent.MetricsRequest{
        Node: "gpu-worker-1",
        GPU:  visent.Int(0),
    })
    if err != nil {
        log.Fatal(err)
    }
    
    fmt.Printf("GPU Utilization: %.1f%%\n", metrics.Utilization)
}

Telemetry API

// Get current metrics
metrics, err := client.Telemetry.GetMetrics(ctx, &visent.MetricsRequest{
    Node: "gpu-worker-1",
    GPU:  visent.Int(0),
})
if err != nil {
    return fmt.Errorf("failed to get metrics: %w", err)
}

// Stream real-time metrics
stream, err := client.Telemetry.StreamMetrics(ctx, &visent.StreamRequest{
    Nodes: []string{"gpu-worker-1", "gpu-worker-2"},
})
if err != nil {
    return err
}
defer stream.Close()

for {
    metric, err := stream.Recv()
    if err != nil {
        if err == io.EOF {
            break
        }
        return err
    }
    
    fmt.Printf("Received metric: %+v\n", metric)
}

// Create alert
alert, err := client.Telemetry.CreateAlert(ctx, &visent.AlertRequest{
    Name:      "High GPU Temperature",
    Condition: "gpu_temperature > 85",
    Duration:  "5m",
    Severity:  visent.SeverityCritical,
})

Atlas API

// Get current pricing
pricing, err := client.Atlas.GetCurrentPricing(ctx, &visent.PricingRequest{
    GPU:      "h100",
    Provider: "aws",
    Region:   "us-east-1",
})
if err != nil {
    return err
}

fmt.Printf("Price: $%.2f/hour\n", pricing.PricePerHour)

// Get optimization recommendations
recommendations, err := client.Atlas.GetOptimizationRecommendations(ctx, &visent.OptimizationRequest{
    Workload: "ml-training",
    Budget:   10000,
    Duration: "30d",
    Requirements: map[string]interface{}{
        "min_gpus":        8,
        "memory_per_gpu": "80GB",
    },
})

Forge API

// Start benchmark
benchmark, err := client.Forge.StartBenchmark(ctx, &visent.BenchmarkRequest{
    Type: "ml-training",
    GPU:  "h100",
    Config: map[string]interface{}{
        "model":      "resnet50",
        "batch_size": 32,
        "iterations": 100,
    },
})
if err != nil {
    return err
}

fmt.Printf("Benchmark started: %s\n", benchmark.JobID)

// Wait for completion with polling
result, err := client.Forge.WaitForCompletion(ctx, benchmark.JobID, visent.WaitOptions{
    PollInterval: 30 * time.Second,
    Timeout:      time.Hour,
})
if err != nil {
    return err
}

fmt.Printf("Throughput: %.1f ops/sec\n", result.Metrics.Throughput)

Error Handling

import "github.com/visent/go-sdk/errors"

metrics, err := client.Telemetry.GetMetrics(ctx, req)
if err != nil {
    var apiErr *errors.APIError
    if errors.As(err, &apiErr) {
        switch apiErr.Code {
        case "RATE_LIMITED":
            fmt.Printf("Rate limited, retry after: %v\n", apiErr.RetryAfter)
        case "UNAUTHORIZED":
            fmt.Println("Invalid API key")
        default:
            fmt.Printf("API error: %s\n", apiErr.Message)
        }
    }
    return err
}

Concurrency

// Concurrent API calls
var wg sync.WaitGroup
errCh := make(chan error, 2)

// Get metrics for multiple nodes
nodes := []string{"gpu-worker-1", "gpu-worker-2"}
for _, node := range nodes {
    wg.Add(1)
    go func(node string) {
        defer wg.Done()
        
        metrics, err := client.Telemetry.GetMetrics(ctx, &visent.MetricsRequest{
            Node: node,
        })
        if err != nil {
            errCh <- err
            return
        }
        
        fmt.Printf("Node %s utilization: %.1f%%\n", node, metrics.Utilization)
    }(node)
}

wg.Wait()
close(errCh)

// Check for errors
for err := range errCh {
    if err != nil {
        log.Printf("Error: %v", err)
    }
}

Configuration

Coming soon - advanced configuration options and middleware.

Context and Cancellation

Coming soon - proper context usage and cancellation patterns.

Testing

Coming soon - testing applications with the Go SDK.

Examples

Coming soon - comprehensive examples and integration patterns.

Next Steps