Screenshot API for Go

Capture full-page screenshots, scrape structured data, generate PDFs, and record videos from Go applications using SnapAPI. No browser installation required.

Get Free API Key

Quick Start in Go

SnapAPI is a REST API that works with Go's standard net/http package. No external dependencies required — call the API from any Go version with a simple HTTP GET or POST request.

package main

import (
    "encoding/json"
    "fmt"
    "io"
    "net/http"
    "net/url"
    "os"
)

type ScreenshotResponse struct {
    URL string `json:"url"`
    CDN string `json:"cdn_url"`
}

func TakeScreenshot(targetURL, apiKey string) (*ScreenshotResponse, error) {
    params := url.Values{}
    params.Set("url", targetURL)
    params.Set("full_page", "true")
    params.Set("access_key", apiKey)

    resp, err := http.Get("https://api.snapapi.pics/v1/screenshot?" + params.Encode())
    if err != nil {
        return nil, err
    }
    defer resp.Body.Close()

    var result ScreenshotResponse
    if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
        return nil, err
    }
    return &result, nil
}

func main() {
    result, err := TakeScreenshot("https://example.com", os.Getenv("SNAP_API_KEY"))
    if err != nil {
        panic(err)
    }
    fmt.Println("Screenshot URL:", result.CDN)
}

Using the Official Go SDK

SnapAPI provides an official Go SDK on GitHub that wraps all API endpoints with typed structs, context support, and built-in error handling. Install it with go get:

go get github.com/Sleywill/snapapi-go

The SDK uses Go modules and supports Go 1.18 and later. It provides a SnapAPI client struct with methods for every endpoint: Screenshot, Scrape, Extract, PDF, Video, and Analyze.

import "github.com/Sleywill/snapapi-go"

client := snapapi.New(os.Getenv("SNAP_API_KEY"))

// Full-page screenshot with custom viewport
result, err := client.Screenshot(context.Background(), snapapi.ScreenshotRequest{
    URL:       "https://example.com",
    FullPage:  true,
    Width:     1440,
    Height:    900,
    BlockAds:  true,
})

// Structured data extraction
data, err := client.Extract(context.Background(), snapapi.ExtractRequest{
    URL:     "https://news.example.com",
    Schema:  map[string]string{"headline": "h1", "byline": ".author"},
})

Go-Specific Integration Patterns

Go's concurrency model is well-suited for batch screenshot operations. Use goroutines and channels to capture hundreds of URLs concurrently while respecting API rate limits.

// Batch screenshots with worker pool
func BatchScreenshots(urls []string, apiKey string) []string {
    sem := make(chan struct{}, 5) // max 5 concurrent
    results := make([]string, len(urls))
    var wg sync.WaitGroup

    for i, u := range urls {
        wg.Add(1)
        go func(idx int, url string) {
            defer wg.Done()
            sem <- struct{}{}
            defer func() { <-sem }()

            r, err := TakeScreenshot(url, apiKey)
            if err == nil {
                results[idx] = r.CDN
            }
        }(i, u)
    }
    wg.Wait()
    return results
}

This worker pool pattern limits concurrent API calls to five, preventing rate limit errors while maximising throughput for large batch jobs. Adjust the semaphore size based on your plan limits.

PDF Generation from Go

Generating PDFs from HTML in Go typically requires CGo dependencies like wkhtmltopdf or heavy headless Chrome setups. SnapAPI eliminates these complications entirely.

func GeneratePDF(htmlContent, apiKey string) ([]byte, error) {
    body := map[string]interface{}{
        "html":       htmlContent,
        "format":     "A4",
        "print_bg":   true,
        "margin_top": "20mm",
    }
    payload, _ := json.Marshal(body)

    req, _ := http.NewRequest("POST",
        "https://api.snapapi.pics/v1/pdf",
        bytes.NewReader(payload))
    req.Header.Set("X-Api-Key", apiKey)
    req.Header.Set("Content-Type", "application/json")

    resp, err := http.DefaultClient.Do(req)
    if err != nil {
        return nil, err
    }
    defer resp.Body.Close()
    return io.ReadAll(resp.Body)
}

Frequently Asked Questions

Does SnapAPI work with Go 1.18 generics?

Yes. The SDK uses generics for typed response handling where applicable, and the raw HTTP approach works with any Go version from 1.13 onwards.

How do I handle context cancellation?

Pass a context.Context to all SDK methods. If the context is cancelled, the HTTP request is aborted and the SDK returns a context.Canceled error. Use context.WithTimeout for per-request deadlines.

Can I use SnapAPI in a Lambda-style Go function?

Absolutely. SnapAPI is a stateless HTTP API, so it works perfectly in AWS Lambda, Google Cloud Functions, or Cloudflare Workers with the TinyGo runtime. No persistent browser process means no cold-start penalty.

What response format does the API return?

JSON with a cdn_url field pointing to the screenshot or PDF stored in S3. For PDFs with the raw=true parameter, the response body is the binary PDF directly — useful for streaming to the client without storing to disk first.

Start Capturing Screenshots from Go Today

200 free captures per month. No credit card required. Full API key in 30 seconds.

Create Free Account

Web Scraping and Data Extraction with Go

Go is an excellent language for high-throughput data pipelines. Pair goroutines with SnapAPI's extract endpoint to scrape thousands of pages concurrently without managing browser processes. The extract endpoint accepts CSS selectors and returns structured JSON, eliminating the need for HTML parsing libraries in your Go code.

type ExtractRequest struct {
    URL    string            `json:"url"`
    Schema map[string]string `json:"schema"`
    Stealth bool             `json:"stealth"`
}

type ExtractResponse struct {
    Data map[string]interface{} `json:"data"`
}

func ExtractData(targetURL string, schema map[string]string, apiKey string) (map[string]interface{}, error) {
    reqBody, _ := json.Marshal(ExtractRequest{URL: targetURL, Schema: schema, Stealth: true})
    req, _ := http.NewRequest("POST", "https://api.snapapi.pics/v1/extract", bytes.NewReader(reqBody))
    req.Header.Set("X-Api-Key", apiKey)
    req.Header.Set("Content-Type", "application/json")

    resp, err := http.DefaultClient.Do(req)
    if err != nil {
        return nil, err
    }
    defer resp.Body.Close()

    var result ExtractResponse
    json.NewDecoder(resp.Body).Decode(&result)
    return result.Data, nil
}

AI-Powered Page Analysis from Go

SnapAPI's analyze endpoint combines browser rendering with an LLM to answer natural language questions about any webpage. Pass a URL and a prompt, and the API returns a structured answer. This is useful for content classification, quality scoring, SEO auditing, and competitive intelligence pipelines written in Go.

type AnalyzeRequest struct {
    URL    string `json:"url"`
    Prompt string `json:"prompt"`
}

func AnalyzePage(url, prompt, apiKey string) (string, error) {
    body, _ := json.Marshal(AnalyzeRequest{URL: url, Prompt: prompt})
    req, _ := http.NewRequest("POST", "https://api.snapapi.pics/v1/analyze", bytes.NewReader(body))
    req.Header.Set("X-Api-Key", apiKey)
    req.Header.Set("Content-Type", "application/json")

    resp, _ := http.DefaultClient.Do(req)
    defer resp.Body.Close()

    var out map[string]string
    json.NewDecoder(resp.Body).Decode(&out)
    return out["result"], nil
}

// Usage:
result, _ := AnalyzePage(
    "https://competitor.com/pricing",
    "What pricing tiers does this page offer? List each plan name and price.",
    os.Getenv("SNAP_API_KEY"),
)

SnapAPI vs. Running Playwright in Go

ConsiderationSnapAPIPlaywright via Go subprocess
Browser installationNone — API handles it250MB+ Chromium binary in Docker image
Memory per request~1MB (HTTP call)200-300MB per browser instance
ConcurrencyUnlimited goroutinesLimited by server RAM
Anti-bot bypassBuilt-in stealth modeRequires manual stealth patches
MaintenanceZero — API versionedBrowser updates, dependency drift

For Go services running in Docker or Kubernetes, avoiding a Chromium dependency keeps container images small and startup times fast. SnapAPI fits naturally into microservice architectures where each service does one thing well: your Go service focuses on data processing, and SnapAPI handles all browser concerns.

Pricing and Plan Selection for Go Applications

All SnapAPI plans include the full feature set — no endpoint restrictions at any tier. The Free plan provides 200 monthly captures, sufficient for local development and integration testing. The Starter plan at nineteen dollars per month covers 5,000 monthly requests, appropriate for small monitoring tools and low-volume SaaS features. Pro at seventy-nine dollars handles 50,000 monthly requests for production workloads with moderate volume. Business at two hundred and ninety-nine dollars provides 500,000 monthly requests for high-volume data pipelines.

Go applications that process request queues with BullMQ-style workers or cron jobs benefit from predictable per-request pricing. Store your API key in an environment variable, rotate it from the dashboard if compromised, and monitor usage via the get_usage endpoint to stay within quota.

Testing Go Integrations with SnapAPI

Write testable Go code by defining an interface for the API client and injecting it via dependency injection. Mock the interface in unit tests to verify your business logic without making real API calls during CI runs. Reserve integration tests for a dedicated test suite that runs against the real API with a designated test API key.

// Define interface for testability
type ScreenshotClient interface {
    Capture(ctx context.Context, url string) (string, error)
}

// Mock for unit tests
type MockScreenshotClient struct {
    CaptureFunc func(ctx context.Context, url string) (string, error)
}

func (m *MockScreenshotClient) Capture(ctx context.Context, url string) (string, error) {
    return m.CaptureFunc(ctx, url)
}

// In your service
type ReportService struct {
    Screenshots ScreenshotClient
}

func (s *ReportService) GenerateReport(ctx context.Context, pageURL string) (*Report, error) {
    imgURL, err := s.Screenshots.Capture(ctx, pageURL)
    if err != nil {
        return nil, fmt.Errorf("screenshot: %w", err)
    }
    return &Report{ScreenshotURL: imgURL}, nil
}

Deploying Go Services with SnapAPI

Store your API key in environment variables and never commit it to version control. In Kubernetes, use a Secret object and inject it as an env var. In Docker Compose, pass it via the environment block in docker-compose.yml. For serverless deployments on AWS Lambda, GCP Cloud Run, or Fly.io, set the environment variable in the function configuration.

SnapAPI's infrastructure runs on globally distributed servers, so API latency from major cloud regions averages under 200ms excluding browser render time. For latency-sensitive use cases, consider making screenshot calls asynchronously via a job queue and returning the result URL to the client once the job completes.

Get Started with SnapAPI and Go

Create a free SnapAPI account to get your API key. The free tier includes 200 monthly captures with no credit card required. All API endpoints, stealth mode, ad blocking, and device emulation presets are available on every plan including free. Start building your Go integration today and upgrade as your usage grows.

Get Free API Key

SnapAPI is available via the official Go SDK at github.com/Sleywill/snapapi-go and works with all major Go deployment environments including AWS Lambda, Google Cloud Run, Fly.io, Railway, and Render. The SDK is licensed under MIT and accepts community contributions. Open an issue or pull request on GitHub if you encounter a problem or want to request a feature.