Documentation
¶
Overview ¶
Package captchasonic is the official Go SDK for the CaptchaSonic API.
Public Endpoints ¶
Transport Endpoint Protocol ─────────── ──────────────────────────────────── ───────────────────── gRPC api.captchasonic.com:443 gRPC binary (HTTP/2) HTTP/REST https://api.captchasonic.com JSON REST
Usage ¶
gRPC transport (default — fastest, binary, zero base64 overhead):
c, _ := captchasonic.NewClient("sonic_xxxx")
defer c.Close()
resp, _ := c.SolvePopularCaptcha(ctx, images, "Select all buses", "objectClassify")
HTTP transport (universal fallback — images auto-encoded to base64):
c, _ := captchasonic.NewClient("sonic_xxxx", captchasonic.WithHTTP())
defer c.Close()
Local dev (insecure gRPC):
c, _ := captchasonic.NewClient("sonic_xxxx",
captchasonic.WithEndpoint("localhost:50052"),
captchasonic.WithInsecure())
Index ¶
- Constants
- func WithCaseSensitive() func(*v1.Task)
- func WithExamples(ex [][]byte) func(*v1.Task)
- func WithGeetestVersion(v int32) func(*v1.Task)
- func WithImages(imgs [][]byte) func(*v1.Task)
- func WithLengthRange(min, max int32) func(*v1.Task)
- func WithModule(m string) func(*v1.Task)
- func WithNumeric() func(*v1.Task)
- func WithProxy(p string) func(*v1.Task)
- func WithProxyless() func(*v1.Task)
- func WithQuestionType(qt string) func(*v1.Task)
- func WithScreenshot() func(*v1.Task)
- func WithWebsite(url, key string) func(*v1.Task)
- func WithWebsiteURL(url string) func(*v1.Task)
- type Client
- func (c *Client) Close() error
- func (c *Client) CreateTask(ctx context.Context, task *v1.Task) (*v1.CreateTaskResponse, error)
- func (c *Client) GetBalance(ctx context.Context) (float64, error)
- func (c *Client) GetTaskResult(ctx context.Context, taskID string) (*v1.GetTaskResultResponse, error)
- func (c *Client) HealthCheck(ctx context.Context) (*v1.HealthCheckResponse, error)
- func (c *Client) SolveAwsWaf(ctx context.Context, images [][]byte, question string, opts ...func(*v1.Task)) (*v1.CreateTaskResponse, error)
- func (c *Client) SolveBinance(ctx context.Context, binanceType, question string, images [][]byte, ...) (*v1.CreateTaskResponse, error)
- func (c *Client) SolveCloudflare(ctx context.Context, websiteURL, websiteKey, proxy string) (*v1.CreateTaskResponse, error)
- func (c *Client) SolveGeetest(ctx context.Context, geetestType, question string, opts ...func(*v1.Task)) (*v1.CreateTaskResponse, error)
- func (c *Client) SolveOcr(ctx context.Context, images [][]byte, opts ...func(*v1.Task)) (*v1.CreateTaskResponse, error)
- func (c *Client) SolvePopularCaptcha(ctx context.Context, images [][]byte, question, questionType string, ...) (*v1.CreateTaskResponse, error)
- func (c *Client) SolvePopularCaptchaToken(ctx context.Context, websiteURL, websiteKey string, opts ...func(*v1.Task)) (*v1.CreateTaskResponse, error)
- func (c *Client) SolveRecaptchaV2(ctx context.Context, images [][]byte, question string, opts ...func(*v1.Task)) (*v1.CreateTaskResponse, error)
- func (c *Client) SolveRecaptchaV2Token(ctx context.Context, websiteURL, websiteKey string, opts ...func(*v1.Task)) (*v1.CreateTaskResponse, error)
- func (c *Client) SolveRecaptchaV3Token(ctx context.Context, websiteURL, websiteKey string, opts ...func(*v1.Task)) (*v1.CreateTaskResponse, error)
- func (c *Client) SolveSlideImage(ctx context.Context, images [][]byte) (*v1.CreateTaskResponse, error)
- func (c *Client) SolveTikTok(ctx context.Context, tikTokType, question string, images [][]byte, ...) (*v1.CreateTaskResponse, error)
- func (c *Client) SolveTurnstile(ctx context.Context, websiteURL, websiteKey string, opts ...func(*v1.Task)) (*v1.CreateTaskResponse, error)
- type Option
- type SonicError
Constants ¶
const ( TransportGRPC = "grpc" // native gRPC (default) — fastest, binary, zero base64 overhead TransportHTTP = "http" // REST JSON — images sent as base64, universal (browsers + Node) )
Transport constants.
const DefaultEndpoint = "api.captchasonic.com:443"
DefaultEndpoint is the production CaptchaSonic gRPC endpoint (host:port, no scheme).
const DefaultHTTPEndpoint = "https://api.captchasonic.com"
DefaultHTTPEndpoint is the production HTTP/REST endpoint.
Variables ¶
This section is empty.
Functions ¶
func WithCaseSensitive ¶
func WithExamples ¶
func WithGeetestVersion ¶
func WithImages ¶
WithImages sets the images on a task (useful for SolveGeetest where images are passed via options instead of positional args).
func WithLengthRange ¶
func WithModule ¶
func WithNumeric ¶
func WithProxyless ¶
WithProxyless signals a token task should use the proxyless variant (no proxy needed).
func WithQuestionType ¶
WithQuestionType sets the questionType (e.g. "split_33" for RecaptchaV2, "objectDrag" for PopularCaptcha).
func WithScreenshot ¶
func WithWebsite ¶
func WithWebsiteURL ¶
WithWebsiteURL sets only the websiteURL (no sitekey). Use for analytics.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a thread-safe, connection-pooled client for the CaptchaSonic API. Create once and reuse across goroutines.
func NewClient ¶
NewClient creates a Client. All URL formats are accepted via WithEndpoint — see WithEndpoint docs.
Examples:
// Production gRPC (default)
c, _ := captchasonic.NewClient("sonic_xxxx")
// Any of these endpoint formats work:
c, _ := captchasonic.NewClient("sonic_xxxx", captchasonic.WithEndpoint("api.captchasonic.com"))
c, _ := captchasonic.NewClient("sonic_xxxx", captchasonic.WithEndpoint("api.captchasonic.com:443"))
c, _ := captchasonic.NewClient("sonic_xxxx", captchasonic.WithEndpoint("https://api.captchasonic.com"))
// Local dev:
c, _ := captchasonic.NewClient("sonic_xxxx", captchasonic.WithEndpoint("localhost:50052"), captchasonic.WithInsecure())
// HTTP transport
c, _ := captchasonic.NewClient("sonic_xxxx", captchasonic.WithHTTP())
func (*Client) CreateTask ¶
CreateTask submits a task and polls until ready (if server returns "processing").
func (*Client) GetBalance ¶
GetBalance returns the account balance in USD.
func (*Client) GetTaskResult ¶
func (c *Client) GetTaskResult(ctx context.Context, taskID string) (*v1.GetTaskResultResponse, error)
GetTaskResult fetches the result of an async task.
func (*Client) HealthCheck ¶
HealthCheck verifies the server is alive.
func (*Client) SolveAwsWaf ¶
func (c *Client) SolveAwsWaf(ctx context.Context, images [][]byte, question string, opts ...func(*v1.Task)) (*v1.CreateTaskResponse, error)
SolveAwsWaf solves an AWS WAF image challenge. question format: "type:category:target" e.g. "grid:vehicles:cars" Server auto-detects: "grid" → grid select; "toycarcity" → toycarcity; else → others.
Optional opts: WithWebsite(url, key), WithWebsiteURL(url).
func (*Client) SolveBinance ¶
func (c *Client) SolveBinance(ctx context.Context, binanceType, question string, images [][]byte, opts ...func(*v1.Task)) (*v1.CreateTaskResponse, error)
SolveBinance solves a Binance CAPTCHA challenge with type-based routing.
binanceType selects the sub-type (alias expansion built-in):
"grid" or "binance_grid" — grid select (question required) "slide" or "binance_slide" — slide puzzle
Example:
c.SolveBinance(ctx, "grid", "Select the bicycle", images) c.SolveBinance(ctx, "slide", "", images)
func (*Client) SolveCloudflare ¶
func (c *Client) SolveCloudflare(ctx context.Context, websiteURL, websiteKey, proxy string) (*v1.CreateTaskResponse, error)
SolveCloudflare solves a Cloudflare challenge via browser automation (polls until ready). Task type: AntiCloudflareTask. Proxy is ALWAYS required.
func (*Client) SolveGeetest ¶
func (c *Client) SolveGeetest(ctx context.Context, geetestType, question string, opts ...func(*v1.Task)) (*v1.CreateTaskResponse, error)
SolveGeetest solves a Geetest challenge.
geetestType selects the sub-type:
"click" — click matching objects. question = what to find, e.g. "the bear". Pass images via WithImages. "slide" — slide pixel offset. Pass puzzle images via WithImages, slice piece via WithExamples. "nine" — nine-tile grid. question = what to find. Pass images via WithImages. "match" — 3x3 swap puzzle. No images needed. "winlinze" — 5x5 swap puzzle. No images needed.
Example:
c.SolveGeetest(ctx, "click", "the bear", WithImages(tiles)) c.SolveGeetest(ctx, "slide", "", WithImages(puzzle), WithExamples(slice)) c.SolveGeetest(ctx, "nine", "the bear", WithImages(tiles)) c.SolveGeetest(ctx, "match", "")
func (*Client) SolveOcr ¶
func (c *Client) SolveOcr(ctx context.Context, images [][]byte, opts ...func(*v1.Task)) (*v1.CreateTaskResponse, error)
SolveOcr solves an image-to-text (OCR) task. Max 50 images.
Optional opts:
- WithModule("bls") — BLS/Morocco: numeric=true, maxLength=3, needs exactly 9 images.
- WithNumeric() — digits only.
- WithCaseSensitive() — preserve letter case.
- WithLengthRange(3, 8) — min/max text length.
func (*Client) SolvePopularCaptcha ¶
func (c *Client) SolvePopularCaptcha(ctx context.Context, images [][]byte, question, questionType string, opts ...func(*v1.Task)) (*v1.CreateTaskResponse, error)
SolvePopularCaptcha solves a popular CAPTCHA image classification task (PopularCaptcha image classification (grid/bbox)).
Task type: PopularCaptchaImage Billing: grid/objectClassify=ceil(len(images)/9) credits; bbox/objectClick=len(images) credits
questionType accepted values (server may override via text inference):
- "objectClassify" — grid select. Returns TypedSolution.Grid.Objects ([]bool).
- "objectClick" — bbox click per image. Returns TypedSolution.Click.
- "objectDrag" — drag pairs. Returns TypedSolution.Drag.
- "grid" — same as objectClassify.
Optional opts: WithExamples, WithScreenshot, WithWebsite.
func (*Client) SolvePopularCaptchaToken ¶
func (c *Client) SolvePopularCaptchaToken(ctx context.Context, websiteURL, websiteKey string, opts ...func(*v1.Task)) (*v1.CreateTaskResponse, error)
SolvePopularCaptchaToken solves a popular CAPTCHA browser automation token task (polls until ready). Use WithProxy(...) for PopularTask or WithProxyless() for PopularTaskProxyless.
func (*Client) SolveRecaptchaV2 ¶
func (c *Client) SolveRecaptchaV2(ctx context.Context, images [][]byte, question string, opts ...func(*v1.Task)) (*v1.CreateTaskResponse, error)
SolveRecaptchaV2 solves a reCAPTCHA v2 image classification task.
question accepts plain text OR Google class codes:
- Plain: "traffic lights", "bicycles", "fire hydrant"
- Codes: "/m/015qff" (traffic light), "/m/0k4j" (car), "/m/07r04" (truck)
Optional opts: WithQuestionType("split_33"), WithWebsite(url, key), WithWebsiteURL(url).
func (*Client) SolveRecaptchaV2Token ¶
func (c *Client) SolveRecaptchaV2Token(ctx context.Context, websiteURL, websiteKey string, opts ...func(*v1.Task)) (*v1.CreateTaskResponse, error)
SolveRecaptchaV2Token solves a reCAPTCHA v2 browser automation token task (polls until ready). Use WithProxy(...) for RecaptchaV2Task or WithProxyless() for RecaptchaV2TaskProxyless.
func (*Client) SolveRecaptchaV3Token ¶
func (c *Client) SolveRecaptchaV3Token(ctx context.Context, websiteURL, websiteKey string, opts ...func(*v1.Task)) (*v1.CreateTaskResponse, error)
SolveRecaptchaV3Token solves a reCAPTCHA v3 browser automation token task (polls until ready). Use WithProxy(...) for RecaptchaV3Task or WithProxyless() for RecaptchaV3TaskProxyless.
func (*Client) SolveSlideImage ¶
func (c *Client) SolveSlideImage(ctx context.Context, images [][]byte) (*v1.CreateTaskResponse, error)
SolveSlideImage solves a slide CAPTCHA using local alpha/contour detection (no AI). Task type: SlideImage. Billed as PopularCaptcha credits. Pass 1–2 images: single image with transparent overlay, or [background, piece]. Returns TypedSolution.GetSlide().GetX() as pixel offset.
func (*Client) SolveTikTok ¶
func (c *Client) SolveTikTok(ctx context.Context, tikTokType, question string, images [][]byte, opts ...func(*v1.Task)) (*v1.CreateTaskResponse, error)
SolveTikTok solves a TikTok CAPTCHA challenge with type-based routing.
tikTokType selects the sub-type (alias expansion built-in):
"click" or "tiktok_click" — click matching objects "whirl" or "tiktok_whirl" — rotation puzzle "slide" or "tiktok_slide" — slide puzzle
Example:
c.SolveTikTok(ctx, "whirl", "Rotate to match", images) c.SolveTikTok(ctx, "click", "Select shape", images, captchasonic.WithExamples(ex))
func (*Client) SolveTurnstile ¶
func (c *Client) SolveTurnstile(ctx context.Context, websiteURL, websiteKey string, opts ...func(*v1.Task)) (*v1.CreateTaskResponse, error)
SolveTurnstile solves a Cloudflare Turnstile token task (polls until ready, up to 120s). Use WithProxy("http://user:pass@host:port") for proxy variant, or WithProxyless() for no-proxy (AntiTurnstileTaskProxyless).
type Option ¶
type Option func(*config)
Option configures the Client.
func WithEndpoint ¶
WithEndpoint overrides the server address. All formats are accepted:
"api.captchasonic.com" → gRPC: host:443, HTTP: https://host "api.captchasonic.com:443" → gRPC: host:443, HTTP: https://host:443 "https://api.captchasonic.com" → gRPC: host:443, HTTP: https://host (scheme stripped for gRPC) "localhost:50052" → gRPC: localhost:50052, HTTP: http://localhost:50052 "http://localhost:50052" → gRPC: localhost:50052, HTTP: http://localhost:50052
func WithGRPC ¶
func WithGRPC() Option
WithGRPC explicitly selects gRPC transport (this is the default).
func WithGRPCMsgSize ¶
WithGRPCMsgSize sets max gRPC message size in bytes (default 50 MB).
func WithHTTP ¶
func WithHTTP() Option
WithHTTP switches to HTTP/JSON transport. Images are automatically base64-encoded before sending.
func WithHTTPPool ¶
WithHTTPPool configures the HTTP connection pool.
func WithInsecure ¶
func WithInsecure() Option
WithInsecure disables TLS on gRPC (local / internal servers only).
func WithTimeout ¶
WithTimeout sets the per-call timeout (default 30s).
type SonicError ¶
SonicError is returned for all API-level and transport-level errors.
func (*SonicError) Error ¶
func (e *SonicError) Error() string