Go SDK

Official Go SDK for CaptchaSonic

Go SDK

Our Go SDK is designed for developers building concurrent scrapers and distributed automation workers. It leverages Go's concurrency primitives to provide a safe and efficient interface to our API.


Installation

go get github.com/captchasonic/captchasonic-go

Implementation

A robust example using context for timeout management.

package main

import (
	"context"
	"fmt"
	"time"

	"github.com/captchasonic/captchasonic-go"
)

func main() {
	// 1. Create client
	client := captchasonic.NewClient("YOUR_API_KEY")

	// 2. Define task (proxyless or with proxy)
	task := captchasonic.RecaptchaV2TaskProxyless{
		WebsiteURL: "https://example.com",
		WebsiteKey: "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
	}

	// 3. Create context with timeout
	ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
	defer cancel()

	// 4. Submit & Wait
	taskID, err := client.CreateTask(ctx, task)
	if err != nil {
		panic(err)
	}

	result, err := client.WaitForResult(ctx, taskID)
	if err != nil {
		panic(err)
	}

	if result.Status == "ready" {
		fmt.Printf("Solved: %s\n", result.Solution.GRecaptchaResponse)
	}
}

Advanced Features

Custom HTTP Client

You can inject a custom http.Client for specific proxy or TLS requirements.

customClient := &http.Client{Timeout: 30 * time.Second}
client := captchasonic.NewClientWithHTTP("YOUR_API_KEY", customClient)

Supported Structs

The library includes pre-defined structs for:

  • RecaptchaV2Task / RecaptchaV3Task
  • HCaptchaTask
  • GeeTestTask
  • TurnstileTask
  • ImageToTextTask

Best Practices

  1. Context Usage: Always use a context with a timeout to avoid hanging goroutines in case of network instability.
  2. Concurrency: The Client is thread-safe. You can share a single client instance across multiple goroutines.
  3. Error Check: Always check for captchasonic.ErrInsufficientFunds to trigger alerts for topping up your account.