More languages
How to solve reCAPTCHA v3 in Go
reCAPTCHA v3 has no checkbox, so a Go program never touches a widget: it asks for a token tied to an action and sends it in the request the page would have made. Tokens cost $0.70 per 1,000 and usually arrive under 3 seconds.
How v3 differs for a Go program
With reCAPTCHA v3 the page calls grecaptcha.execute(siteKey, {action: 'login'}) in the background and gets a token. It then sends that token to its own back end, usually inside a JSON or form request, and the back end asks Google for a score. Nothing is clicked and nothing is shown. For a Go program that means two jobs: get a token for the same site key and action, and send it in the same request the page sends. There is no DOM to fill.
The page action is the part people get wrong. Google records the action with the token, and many back ends compare it with what they expect. A token minted for homepage sent to a login endpoint can be refused even though it is valid.
Collect three values from the page
Open the page in a desktop browser with the developer tools on and note:
- The site key. It appears in the script URL
recaptcha/api.js?render=6Lc...or in the first argument ofgrecaptcha.execute. - The action. The
actionproperty of the second argument. Search the page scripts forexecute(if it is not obvious; the guide to finding the reCAPTCHA page action shows more ways. - The request that carries the token. In the Network tab, submit the form once and find the call whose body contains a long string starting with
03A. Note its URL, method, content type and the field name.
A client built with functional options
The client below keeps configuration in options, so tests can swap the base URL and poll interval without exported fields. It uses only the standard library and respects context cancellation, which lets a caller put a hard deadline on the whole solve.
package scoretoken
import (
"bytes"
"context"
"encoding/json"
"fmt"
"net/http"
"time"
)
type Option func(*Fetcher)
func WithBase(u string) Option { return func(f *Fetcher) { f.base = u } }
func WithEvery(d time.Duration) Option { return func(f *Fetcher) { f.every = d } }
func WithHTTP(c *http.Client) Option { return func(f *Fetcher) { f.web = c } }
type Fetcher struct {
key, base string
every time.Duration
web *http.Client
}
func New(apiKey string, opts ...Option) *Fetcher {
f := &Fetcher{key: apiKey, base: "https://gatesolver.com", every: 3 * time.Second,
web: &http.Client{Timeout: 25 * time.Second}}
for _, o := range opts {
o(f)
}
return f
}
func (f *Fetcher) rpc(ctx context.Context, path string, in map[string]any, out any) error {
in["clientKey"] = f.key
raw, _ := json.Marshal(in)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, f.base+path, bytes.NewReader(raw))
if err != nil {
return err
}
req.Header["Content-Type"] = []string{"application/json"}
resp, err := f.web.Do(req)
if err != nil {
return fmt.Errorf("%s: %w", path, err)
}
defer resp.Body.Close()
return json.NewDecoder(resp.Body).Decode(out)
}
Request the token for an action
The solve method creates a ReCaptchaV3TaskProxyLess task with pageAction, then polls with a select on the context and a timer. A one line reply type covers both endpoints, since unused fields simply stay empty.
type reply struct {
Bad int `json:"errorId"`
Reason string `json:"errorCode"`
Job string `json:"taskId"`
Step string `json:"status"`
Answer struct {
Tok string `json:"gRecaptchaResponse"`
UA string `json:"userAgent"`
} `json:"solution"`
}
func (f *Fetcher) Token(ctx context.Context, pageURL, siteKey, action string) (string, string, error) {
ctx, stop := context.WithTimeout(ctx, 2*time.Minute+5*time.Second)
defer stop()
var made reply
task := map[string]any{"type": "ReCaptchaV3TaskProxyLess", "websiteURL": pageURL,
"websiteKey": siteKey, "pageAction": action}
if err := f.rpc(ctx, "/createTask", map[string]any{"task": task}, &made); err != nil {
return "", "", err
}
if made.Bad != 0 {
return "", "", fmt.Errorf("createTask refused: %s", made.Reason)
}
for {
select {
case <-ctx.Done():
return "", "", ctx.Err()
case <-time.After(f.every):
}
var st reply
if err := f.rpc(ctx, "/getTaskResult", map[string]any{"taskId": made.Job}, &st); err != nil {
return "", "", err
}
switch {
case st.Bad != 0:
return "", "", fmt.Errorf("result: %s", st.Reason)
case st.Step == "ready":
return st.Answer.Tok, st.Answer.UA, nil
case st.Step == "failed":
return "", "", fmt.Errorf("task failed (free)")
}
}
}
The timeout is slightly over two minutes because a task still unsolved at 120 seconds is marked failed on our side and not charged; waiting longer gains nothing.
Send the token the way the page does
Most v3 sites send the token in a JSON body to an API route. Build the same body your browser sent, put the token under the same field name, and use the User-Agent from the solution so the request looks like it came from the browser that earned the token.
type signIn struct {
Email string `json:"email"`
Password string `json:"password"`
Recaptcha string `json:"recaptchaToken"`
}
func submit(ctx context.Context, f *Fetcher, jar http.CookieJar) error {
page := "https://app.example.com/login"
tok, ua, err := f.Token(ctx, page, "6Lc_EXAMPLE_V3_KEY", "login")
if err != nil {
return err
}
body, _ := json.Marshal(signIn{Email: "qa@example.com", Password: "from-your-vault", Recaptcha: tok})
req, _ := http.NewRequestWithContext(ctx, "POST", "https://app.example.com/api/session", bytes.NewReader(body))
req.Header.Set("Content-Type", "application/json") // as the page sends it
req.Header.Set("User-Agent", ua)
req.Header.Set("Origin", "https://app.example.com")
res, err := (&http.Client{Jar: jar, Timeout: 20 * time.Second}).Do(req)
if err != nil {
return err
}
defer res.Body.Close()
fmt.Println("site replied", res.Status)
return nil
}
The field name recaptchaToken is only an example; copy the real one. Some sites send the token as a header instead, often named after the product, and some as form data under g-recaptcha-response. The Network tab tells you which.
Why the site may still say no
A v3 token is a ticket to be scored, not a pass. If the back end rejects it, check these in order:
- Wrong action. The action in the task must match what the page uses for that request.
- Old token. Tokens expire about two minutes after they are issued. Call
Tokenright before the request, never in advance. - Missing context. Some back ends also require cookies from a prior page load, a CSRF header, or an
Originheader. Load the page once with the same cookie jar. - Enterprise variant. If the script URL is
recaptcha/enterprise.js, use the reCAPTCHA v3 Enterprise task type instead.
Testing the client
Because the base URL is an option, httptest.NewServer can stand in for the API: return a task id from /createTask, then processing once and ready on the second poll, and pass WithEvery(10*time.Millisecond) so the test runs instantly. Add one case that returns errorId: 1 with ERROR_ZERO_BALANCE and assert that Token returns at once. None of this spends balance.
Running many solves
One Fetcher is safe to share between goroutines, since it holds no mutable state. There is no limit on concurrent tasks, but each key allows 600 requests per minute, and each running solve polls about twenty times a minute. A buffered channel used as a semaphore with a capacity of about twenty keeps a burst of goroutines comfortably under that.
Where the token travels on real sites
v3 integrations vary more than checkbox ones, because each site decides how to ship the token to its own back end. Three shapes cover most of what you will meet. A JSON API call, as in the example, with the token as one property of the body. A classic form post, where the page's script writes the token into a hidden input just before submitting, usually named g-recaptcha-response or recaptcha_token. And a request header, where a single page app adds the token to a fetch call. In Go, the first is json.Marshal, the second is url.Values with http.PostForm style encoding, and the third is req.Header.Set. The Network tab tells you which one in under a minute, and copying it exactly is what makes the difference between a working client and a puzzling refusal.
Logging that helps later
Log the task id, the action, the target endpoint and the site's HTTP status for every submit, but never the token or the password. When a site changes its action name or moves the token to a header, the logs show the first refusals with enough context to fix the client quickly.
Common questions
Do I need a headless browser to use reCAPTCHA v3 from Go?
No. The token comes from the API, and you send it in the HTTP request the page would make, so net/http is enough.
Where do I find the action name?
In the page script, as the action property passed to grecaptcha.execute. It is often login, submit or homepage.
Can I reuse a v3 token for several requests?
No. Each token is single use and expires after about two minutes, so request one per call.
Can I ask for a specific score?
No. The score is decided by Google when the site verifies the token. Matching the action and request context helps it come out right.
Is the Fetcher safe for concurrent use?
Yes. It has no mutable state after construction, so goroutines can share one instance.
Keep reading
- reCAPTCHA v3 solver$0.70 per 1,000 tasks, answers under 3 seconds.
- Find the reCAPTCHA v3 action nameLocate the exact action string a page passes to grecaptcha.execute using script search, breakpoints or the outgoing request.
- reCAPTCHA v3 scoreThe 0.0 to 1.0 number behind reCAPTCHA v3, the thresholds sites pick, and why the decision happens on their server.
- reCAPTCHA v3 scores explainedHow Google turns page signals into a v3 score, how sites act on it, and what a solver can and cannot influence.