Developers / SDKs

Go SDK.

Go 1.18+, no dependencies. One file. Give it a page address, get the token.

1. Add the client

Save the client as captora/captora.go inside your module and import it from your module path.

captora.go
// Package captora is a zero-dependency Captora client for Go 1.18+ (standard library only).package captoraimport (	"bytes"	"encoding/json"	"errors"	"fmt"	"io"	"net/http"	"time")type Client struct {	APIKey  string	BaseURL string	Poll    time.Duration	Timeout time.Duration	HTTP    *http.Client}func New(apiKey string) *Client {	return &Client{		APIKey:  apiKey,		BaseURL: "https://api.captora.me",		Poll:    3 * time.Second,		Timeout: 180 * time.Second,		HTTP:    &http.Client{Timeout: 60 * time.Second},	}}type task struct {	TaskID string         `json:"taskId"`	Status string         `json:"status"`	Result map[string]any `json:"result"`}func (c *Client) do(method, path string, body any, out any) error {	var reader io.Reader	if body != nil {		b, err := json.Marshal(body)		if err != nil {			return err		}		reader = bytes.NewReader(b)	}	req, err := http.NewRequest(method, c.BaseURL+path, reader)	if err != nil {		return err	}	req.Header.Set("Authorization", "Bearer "+c.APIKey)	req.Header.Set("Content-Type", "application/json")	req.Header.Set("User-Agent", "captora-go/1.0")	res, err := c.HTTP.Do(req)	if err != nil {		return err	}	defer res.Body.Close()	data, _ := io.ReadAll(res.Body)	if res.StatusCode >= 400 {		return fmt.Errorf("captora error %d: %s", res.StatusCode, data)	}	return json.Unmarshal(data, out)}// Balance returns the balance in paise (100 paise = Rs 1).func (c *Client) Balance() (int64, error) {	var out struct {		BalancePaise int64 `json:"balance_paise"`	}	err := c.do("GET", "/v1/balance", nil, &out)	return out.BalancePaise, err}// SolveURL is the simple way: give the address of a page with a captcha. Captora recognises the captcha,// solves it, and returns its result (usually {"token": ...}). Put "html" (the page source) in extra for pages// that add the captcha with JavaScript or need a login. It returns an error if it can't be solved (not charged).func (c *Client) SolveURL(websiteURL string, extra map[string]any) (map[string]any, error) {	body := map[string]any{"websiteURL": websiteURL}	for k, v := range extra {		body[k] = v	}	return c.wait("/v1/solve", body)}// Solve is for when you already know the captcha type. It waits for the task and returns its result.func (c *Client) Solve(captchaType string, params map[string]any) (map[string]any, error) {	body := map[string]any{"type": captchaType}	for k, v := range params {		body[k] = v	}	return c.wait("/v1/tasks", body)}func (c *Client) wait(path string, body map[string]any) (map[string]any, error) {	var t task	if err := c.do("POST", path, body, &t); err != nil {		return nil, err	}	deadline := time.Now().Add(c.Timeout)	for t.Status == "processing" && time.Now().Before(deadline) {		time.Sleep(c.Poll)		var next task		if err := c.do("GET", "/v1/tasks/"+t.TaskID, nil, &next); err != nil {			return nil, err		}		t = next	}	switch t.Status {	case "completed":		return t.Result, nil	case "failed":		return nil, errors.New("could not be solved (refunded)")	}	return nil, errors.New("timed out")}

2. Solve a captcha with one call

Put your API key in the CAPTORA_API_KEY environment variable (create one in your dashboard).

example.go
package mainimport (	"fmt"	"log"	"os"	"example.com/yourapp/captora" // the captora.go file above, saved as its own package)func main() {	client := captora.New(os.Getenv("CAPTORA_API_KEY"))	// Give it the page with the captcha. Captora finds the captcha and solves it.	result, err := client.SolveURL("https://example.com/login", nil)	if err != nil {		log.Fatal(err)	}	fmt.Println(result["token"]) // submit this token with your form}

3. That's it. No captcha type to pick

Captora recognises the captcha on the page. For pages that add it with JavaScript or sit behind a login, pass the page's HTML as well (see the docs). If you already know the type, the client has a second method for that. Every captcha we support, and its price, is on the captchas page.

Keep in mind

  • Keep your API key on your server. Never ship it in a browser or mobile app.
  • Solving can take from a few seconds to a minute or more, so run it in the background of your app.
  • Unsolved tasks raise an error and are refunded automatically.

Build once.
Connect with flexibility.