capbypass

package module
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2026 License: MIT Imports: 9 Imported by: 0

README ΒΆ

CapBypass Go SDK

Go Reference Go Report Card

Official Go SDK for the CapBypass CAPTCHA solving service. Supports reCAPTCHA v2, reCAPTCHA v3, and AWS WAF challenges.

Features

  • βœ… Simple API: One-line Solve() method or advanced CreateTask()/GetTaskResult() control
  • πŸ”„ Automatic Polling: Built-in adaptive polling with exponential backoff
  • πŸ›‘οΈ Robust Error Handling: Typed errors for all API and network failures
  • πŸ” Smart Retry Logic: Automatic retry on network/gateway errors
  • 🎯 Type-Safe: Full Go type safety with structs and constants

Installation

go get github.com/CapBypass-Development/capbypass-sdk-go

Quick Start

package main

import (
    "fmt"
    "log"

    "github.com/CapBypass-Development/capbypass-sdk-go"
)

func main() {
    client, err := capbypass.NewClient("your-api-key")
    if err != nil {
        log.Fatal(err)
    }

    solution, err := client.Solve(capbypass.Task{
        "type":       capbypass.TaskTypeReCaptchaV2ProxyLess,
        "websiteURL": "https://www.google.com/recaptcha/api2/demo",
        "websiteKey": "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
    }, 120)

    if err != nil {
        log.Fatal(err)
    }

    fmt.Println("Token:", solution["gRecaptchaResponse"])
}

API Reference

Client Creation
// With API key parameter
client, err := capbypass.NewClient("your-api-key")

// From CAPBYPASS_API_KEY environment variable
client, err := capbypass.NewClient("")

Solve - One-step CAPTCHA solving:

solution, err := client.Solve(task, timeout)
  • task: Task configuration (see Task Types below)
  • timeout: Maximum wait time in seconds (default: 120)
  • Returns: Solution map or error
Advanced API

For full control over task lifecycle:

// Create task
taskID, err := client.CreateTask(task)

// Poll for result
result, err := client.GetTaskResult(taskID)

// Check balance
balance, err := client.GetBalance()

Task Types

reCAPTCHA v2
client.Solve(capbypass.Task{
    "type":       capbypass.TaskTypeReCaptchaV2ProxyLess,
    "websiteURL": "https://example.com",
    "websiteKey": "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
}, 120)

Invisible reCAPTCHA v2:

client.Solve(capbypass.Task{
    "type":        capbypass.TaskTypeReCaptchaV2ProxyLess,
    "websiteURL":  "https://example.com",
    "websiteKey":  "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
    "isInvisible": true,
}, 120)
reCAPTCHA v3
client.Solve(capbypass.Task{
    "type":       capbypass.TaskTypeReCaptchaV3ProxyLess,
    "websiteURL": "https://example.com",
    "websiteKey": "6LcR_okUAAAAAPYrPe-HK_0RULO1aZM15ENyM-Mf",
    "pageAction": "submit",
}, 120)
AWS WAF Challenge
client.Solve(capbypass.Task{
    "type":           capbypass.TaskTypeAntiAwsWafProxyLess,
    "websiteURL":     "https://example.com",
    "awsChallengeJS": "https://[...].awswaf.com/[...]/challenge.js",
}, 120)
With Proxy

All task types support proxy configuration:

client.Solve(capbypass.Task{
    "type":          capbypass.TaskTypeReCaptchaV2Task,
    "websiteURL":    "https://example.com",
    "websiteKey":    "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
    "proxyType":     "http",
    "proxyAddress":  "proxy.example.com",
    "proxyPort":     8080,
    "proxyLogin":    "username",
    "proxyPassword": "password",
}, 120)

Error Handling

The SDK uses typed errors for precise error handling:

solution, err := client.Solve(task, 120)
if err != nil {
    switch e := err.(type) {
    case *capbypass.ErrAuthentication:
        // Invalid API key
    case *capbypass.ErrInsufficientBalance:
        // No balance
    case *capbypass.ErrValidation:
        // Invalid task parameters
    case *capbypass.ErrTimeout:
        // Task took too long
    case *capbypass.ErrSolver:
        // CAPTCHA could not be solved
    case *capbypass.ErrNetwork:
        // Network/connection error
    case *capbypass.ErrGateway:
        // Gateway error (502/503/504)
    default:
        // Other error
    }
}

Task Type Constants

// AWS WAF
TaskTypeAntiAwsWaf          = "AntiAwsWafTask"
TaskTypeAntiAwsWafProxyLess = "AntiAwsWafTaskProxyLess"

// reCAPTCHA v2
TaskTypeReCaptchaV2          = "ReCaptchaV2Task"
TaskTypeReCaptchaV2ProxyLess = "ReCaptchaV2TaskProxyLess"

// reCAPTCHA v3
TaskTypeReCaptchaV3          = "ReCaptchaV3Task"
TaskTypeReCaptchaV3ProxyLess = "ReCaptchaV3TaskProxyLess"

// reCAPTCHA v3 Enterprise
TaskTypeReCaptchaV3Enterprise          = "ReCaptchaV3EnterpriseTask"
TaskTypeReCaptchaV3EnterpriseProxyLess = "ReCaptchaV3EnterpriseTaskProxyLess"

Documentation

πŸ“š Core Documentation
πŸ”§ Advanced Guides
πŸ”„ Migration

Examples

Basic Examples

See the examples directory for complete runnable examples:

Advanced Examples

Full integration examples in the documentation:

  • E-commerce checkout automation
  • Social media automation
  • Web scraping with CAPTCHA handling
  • Microservice integration patterns

Testing

# Run unit tests
go test -v

# Run with coverage
go test -v -cover

# Run integration tests (requires API key)
export CAPBYPASS_API_KEY=your-api-key
go test -v -tags=integration

License

MIT License - see LICENSE file for details.

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

View Source
const (
	// AWS WAF task types
	TaskTypeAntiAwsWaf          = "AntiAwsWafTask"
	TaskTypeAntiAwsWafProxyLess = "AntiAwsWafTaskProxyLess"

	// reCAPTCHA v2 task types
	TaskTypeReCaptchaV2          = "ReCaptchaV2Task"
	TaskTypeReCaptchaV2ProxyLess = "ReCaptchaV2TaskProxyLess"

	// reCAPTCHA v3 task types
	TaskTypeReCaptchaV3          = "ReCaptchaV3Task"
	TaskTypeReCaptchaV3ProxyLess = "ReCaptchaV3TaskProxyLess"

	// reCAPTCHA v3 Enterprise task types
	TaskTypeReCaptchaV3Enterprise          = "ReCaptchaV3EnterpriseTask"
	TaskTypeReCaptchaV3EnterpriseProxyLess = "ReCaptchaV3EnterpriseTaskProxyLess"
)

Task type constants for CapBypass API.

Variables ΒΆ

This section is empty.

Functions ΒΆ

This section is empty.

Types ΒΆ

type APIError ΒΆ

type APIError struct {
	ErrorID          int    `json:"errorId,omitempty"`
	ErrorCode        string `json:"errorCode,omitempty"`
	ErrorDescription string `json:"errorDescription,omitempty"`
}

APIError represents a CapBypass API error with Capsolver-compatible structure.

func (*APIError) Error ΒΆ

func (e *APIError) Error() string

type Client ΒΆ

type Client struct {
	// contains filtered or unexported fields
}

Client is the CapBypass API client.

func NewClient ΒΆ

func NewClient(apiKey string) (*Client, error)

NewClient creates a new CapBypass client. If apiKey is empty, it will be read from CAPBYPASS_API_KEY environment variable.

func (*Client) CreateTask ΒΆ

func (c *Client) CreateTask(task Task) (string, error)

CreateTask creates a new CAPTCHA solving task.

func (*Client) GetBalance ΒΆ

func (c *Client) GetBalance() (float64, error)

GetBalance retrieves the account balance.

func (*Client) GetPricing ΒΆ added in v1.0.1

func (c *Client) GetPricing() ([]PricingItem, error)

GetPricing retrieves pricing for all task types. This is a public endpoint and does not require authentication.

func (*Client) GetTaskResult ΒΆ

func (c *Client) GetTaskResult(taskID string) (*TaskResult, error)

GetTaskResult retrieves the result of a task.

func (*Client) SetBaseURL ΒΆ

func (c *Client) SetBaseURL(baseURL string)

SetBaseURL sets a custom base URL for the API.

func (*Client) SetDeveloperKey ΒΆ added in v1.0.1

func (c *Client) SetDeveloperKey(key string)

SetDeveloperKey sets the developer affiliate key for commission attribution. Can also be set via CAPBYPASS_DEVELOPER_KEY environment variable.

func (*Client) Solve ΒΆ

func (c *Client) Solve(task Task, timeout int) (map[string]interface{}, error)

Solve creates a task and polls until it's solved or times out.

type CreateTaskRequest ΒΆ

type CreateTaskRequest struct {
	ClientKey    string `json:"clientKey"`
	Task         Task   `json:"task"`
	DeveloperKey string `json:"developerKey,omitempty"`
}

CreateTaskRequest represents the request for createTask.

type CreateTaskResponse ΒΆ

type CreateTaskResponse struct {
	ErrorID          int    `json:"errorId"`
	ErrorCode        string `json:"errorCode,omitempty"`
	ErrorDescription string `json:"errorDescription,omitempty"`
	TaskID           string `json:"taskId,omitempty"`
}

CreateTaskResponse represents the response from createTask.

type ErrAuthentication ΒΆ

type ErrAuthentication struct {
	APIError
}

ErrAuthentication indicates invalid API key.

type ErrGateway ΒΆ

type ErrGateway struct {
	StatusCode int
	Message    string
}

ErrGateway indicates a gateway error (HTTP 502/503/504).

func (*ErrGateway) Error ΒΆ

func (e *ErrGateway) Error() string

type ErrInsufficientBalance ΒΆ

type ErrInsufficientBalance struct {
	APIError
}

ErrInsufficientBalance indicates zero or insufficient account balance.

type ErrInternal ΒΆ

type ErrInternal struct {
	APIError
}

ErrInternal indicates an internal server error.

type ErrNetwork ΒΆ

type ErrNetwork struct {
	Message string
	Err     error
}

ErrNetwork indicates a network connection error.

func (*ErrNetwork) Error ΒΆ

func (e *ErrNetwork) Error() string

func (*ErrNetwork) Unwrap ΒΆ

func (e *ErrNetwork) Unwrap() error

type ErrParse ΒΆ

type ErrParse struct {
	Message string
	Err     error
}

ErrParse indicates a JSON parsing error.

func (*ErrParse) Error ΒΆ

func (e *ErrParse) Error() string

func (*ErrParse) Unwrap ΒΆ

func (e *ErrParse) Unwrap() error

type ErrRateLimit ΒΆ

type ErrRateLimit struct {
	Message string
}

ErrRateLimit indicates rate limiting (HTTP 429).

func (*ErrRateLimit) Error ΒΆ

func (e *ErrRateLimit) Error() string

type ErrServer ΒΆ

type ErrServer struct {
	StatusCode int
	Message    string
}

ErrServer indicates a server error (HTTP 500).

func (*ErrServer) Error ΒΆ

func (e *ErrServer) Error() string

type ErrSolver ΒΆ

type ErrSolver struct {
	APIError
}

ErrSolver indicates the CAPTCHA could not be solved.

type ErrTaskNotFound ΒΆ

type ErrTaskNotFound struct {
	APIError
}

ErrTaskNotFound indicates the task ID does not exist.

type ErrTimeout ΒΆ

type ErrTimeout struct {
	APIError
}

ErrTimeout indicates the solve operation exceeded the timeout.

type ErrValidation ΒΆ

type ErrValidation struct {
	APIError
}

ErrValidation indicates invalid task data or parameters.

type GetBalanceRequest ΒΆ

type GetBalanceRequest struct {
	ClientKey string `json:"clientKey"`
}

GetBalanceRequest represents the request for getBalance.

type GetBalanceResponse ΒΆ

type GetBalanceResponse struct {
	ErrorID          int     `json:"errorId"`
	ErrorCode        string  `json:"errorCode,omitempty"`
	ErrorDescription string  `json:"errorDescription,omitempty"`
	Balance          float64 `json:"balance,omitempty"`
}

GetBalanceResponse represents the response from getBalance.

type GetTaskResultRequest ΒΆ

type GetTaskResultRequest struct {
	ClientKey string `json:"clientKey"`
	TaskID    string `json:"taskId"`
}

GetTaskResultRequest represents the request for getTaskResult.

type PricingItem ΒΆ added in v1.0.1

type PricingItem struct {
	TaskType string  `json:"task_type"`
	UserCost float64 `json:"user_cost"`
	Status   string  `json:"status"`
}

PricingItem represents pricing for a single task type.

type PricingResponse ΒΆ added in v1.0.1

type PricingResponse struct {
	Pricing []PricingItem `json:"pricing"`
}

PricingResponse represents the response from GET /pricing.

type Task ΒΆ

type Task map[string]interface{}

Task represents a CAPTCHA solving task.

type TaskResult ΒΆ

type TaskResult struct {
	ErrorID          int                    `json:"errorId"`
	ErrorCode        string                 `json:"errorCode,omitempty"`
	ErrorDescription string                 `json:"errorDescription,omitempty"`
	Status           string                 `json:"status,omitempty"`
	Solution         map[string]interface{} `json:"solution,omitempty"`
}

TaskResult represents the response from getTaskResult.

Directories ΒΆ

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL