Menu
Official SDKv1.x

Go SDK

Official Go SDK for SnapSharp. Take screenshots, generate OG images, and run site audits with go get.

Installation

Install the Go SDK using your package manager:

shell
go get github.com/bogdanov-igor/snapsharp-go

Then import and initialise the client:

go
import snapsharp "github.com/bogdanov-igor/snapsharp-go"

snap := snapsharp.New("sk_live_...")

Replace sk_live_... with your API key from the dashboard.

Quick Start

Three common use cases to get you up and running in minutes.

1. Take a Screenshot

Capture a screenshot and write the bytes to a file.

go
package main

import (
    "fmt"
    "os"

    snapsharp "github.com/bogdanov-igor/snapsharp-go"
)

func main() {
    snap := snapsharp.New("sk_live_...")

    data, err := snap.Screenshot("https://example.com", &snapsharp.ScreenshotParams{
        Width:    1280,
        Height:   720,
        Format:   "png",
        FullPage: false,
    })
    if err != nil {
        panic(err)
    }

    os.WriteFile("screenshot.png", data, 0644)
    fmt.Println("Screenshot saved!")
}

2. Generate an OG Image

Create Open Graph images for social-media previews.

go
snap := snapsharp.New("sk_live_...")

data, err := snap.OGImage("https://example.com", &snapsharp.OGImageParams{
    Template: "default",
    Width:    1200,
    Height:   630,
})
if err != nil {
    log.Fatal(err)
}

os.WriteFile("og-image.png", data, 0644)

3. Render HTML to Image

Convert raw HTML and CSS into an image without hosting a page.

go
snap := snapsharp.New("sk_live_...")

data, err := snap.HTMLToImage("<h1>Hello World</h1>", &snapsharp.HTMLToImageParams{
    Width:  800,
    Height: 400,
    Format: "png",
    CSS:    "body { font-family: sans-serif; background: #1a1a2e; color: #fff; display: grid; place-items: center; }",
})
if err != nil {
    log.Fatal(err)
}

os.WriteFile("html-render.png", data, 0644)

API Reference

Complete list of methods available on the Go client.

Screenshot()

Screenshot(url string, params *ScreenshotParams) ([]byte, error)

Captures a screenshot of the given URL. Params include Width, Height, Format, FullPage, Device, DarkMode, Delay, and Headers.

OGImage()

OGImage(url string, params *OGImageParams) ([]byte, error)

Generates an Open Graph image for the URL. Supports Template, Width, and Height params.

HTMLToImage()

HTMLToImage(html string, params *HTMLToImageParams) ([]byte, error)

Renders raw HTML/CSS into an image. Supports Width, Height, Format, CSS, and TransparentBg params.

SiteAudit()

SiteAudit(url string, params *SiteAuditParams) (*AuditResult, error)

Runs a Lighthouse-style performance and SEO audit. Returns an AuditResult struct with scores and diagnostics.

All methods that return images accept an optional format parameter ("png", "jpeg", "webp"). Default is "png". See the full API reference for every available option.

Error Handling

The SDK throws typed errors with HTTP status, message, and a unique request ID for debugging. Always wrap calls in a try/catch to handle rate limits and authentication errors gracefully.

go
import (
    "errors"
    "fmt"

    snapsharp "github.com/bogdanov-igor/snapsharp-go"
)

data, err := snap.Screenshot("https://example.com", nil)
if err != nil {
    var apiErr *snapsharp.APIError
    if errors.As(err, &apiErr) {
        fmt.Printf("Error %d: %s\n", apiErr.Status, apiErr.Message)
        fmt.Printf("Request ID: %s\n", apiErr.RequestID)

        if apiErr.Status == 429 {
            fmt.Printf("Rate limited. Retry after %ds\n", apiErr.RetryAfter)
        }
    } else {
        fmt.Printf("Unexpected error: %v\n", err)
    }
}
StatusMeaningAction
400Bad Request — invalid parametersCheck the request body and query params
401Unauthorized — invalid or missing API keyVerify your API key in the dashboard
429Too Many Requests — rate limit exceededWait for retryAfter seconds
500Internal Server ErrorRetry with exponential back-off

Configuration

Customise the client with optional settings passed at initialisation.

go
import "time"

snap := snapsharp.New("sk_live_...",
    snapsharp.WithBaseURL("https://api.snapsharp.dev"),  // Custom API base URL
    snapsharp.WithTimeout(30 * time.Second),              // Request timeout
    snapsharp.WithRetries(2),                             // Auto-retry on 5xx
)
OptionDefaultDescription
baseUrlapi.snapsharp.devOverride the API base URL (e.g. for on-premise)
timeout30sMaximum time to wait for a response
retries0Number of automatic retries on 5xx errors

SDKs for other languages

Ready to start building?

Get your free API key and start capturing screenshots in under a minute. 100 free screenshots every month — no credit card required.