More languages
How to solve reCAPTCHA v3 in C#
This guide builds a reCAPTCHA v3 solver for .NET 8 that deserializes into typed records, polls with PeriodicTimer and honours cancellation, then sends the token the way the page does. Each token costs $0.70 per 1,000.
What you are building
A small service class, V3Tokens, with one method: give it the page URL, the site key and the action, and it returns the token plus the User-Agent it was solved under. Inside, it posts a ReCaptchaV3TaskProxyLess task and polls until the answer is ready. The code targets .NET 8 and uses only the base class library: System.Net.Http.Json for JSON and PeriodicTimer for the polling rhythm.
Before writing code, collect the site key (from api.js?render=), the action (from grecaptcha.execute) and the request that carries the token (from the Network tab when you submit once by hand). The guide on finding the page action covers the tricky cases.
One generic result type
Both API endpoints share the same envelope: errorId, errorCode, and either taskId or status plus solution. A generic record models that once, with the solution type as a parameter. Property names are matched case insensitively by the web defaults of System.Text.Json, so they can stay in normal C# casing.
using System.Net.Http.Json; // PostAsJsonAsync with explicit options
using System.Text.Json;
using System.Text.Json.Serialization; // JsonPropertyName on a record parameter
public sealed record ApiReply<TSolution>(
int ErrorId,
string? ErrorCode,
string? ErrorDescription,
string? TaskId,
string? Status,
TSolution? Solution) where TSolution : class;
public sealed record ScoreSolution(
[property: JsonPropertyName("gRecaptchaResponse")] string Token,
string? UserAgent);
public sealed class GateSolverException(string code, string? detail)
: Exception($"{code} {detail}".Trim())
{
public string ErrorCode { get; } = code;
public bool WorthRetrying => ErrorCode is "ERROR_CAPTCHA_UNSOLVABLE" or "ERROR_SERVICE_UNAVAILABLE" or "ERROR_RATE_LIMIT";
}
The WorthRetrying property puts the retry decision next to the error, so callers do not need their own list of codes.
The solver with PeriodicTimer
PeriodicTimer ticks at a fixed interval and its WaitForNextTickAsync takes a cancellation token, which makes it a natural fit for polling. A linked token source adds a two minute ceiling on top of whatever the caller passes in.
public sealed class V3Tokens(HttpClient http, string apiKey)
{
private static readonly JsonSerializerOptions Web = new(JsonSerializerDefaults.Web);
private async Task<ApiReply<T>> PostAsync<T>(string path, object body, CancellationToken ct) where T : class
{
using var res = await http.PostAsJsonAsync(path, body, Web, ct);
var reply = await res.Content.ReadFromJsonAsync<ApiReply<T>>(Web, ct)
?? throw new GateSolverException("EMPTY_REPLY", path);
if (reply.ErrorId != 0) throw new GateSolverException(reply.ErrorCode ?? "ERROR", reply.ErrorDescription);
return reply;
}
public async Task<ScoreSolution> ForActionAsync(string pageUrl, string siteKey, string action,
CancellationToken ct = default)
{
using var ceiling = CancellationTokenSource.CreateLinkedTokenSource(ct);
ceiling.CancelAfter(125_000);
var task = new { type = "ReCaptchaV3TaskProxyLess", websiteURL = pageUrl, websiteKey = siteKey, pageAction = action };
var made = await PostAsync<object>("createTask", new { clientKey = apiKey, task }, ceiling.Token);
using var timer = new PeriodicTimer(TimeSpan.FromSeconds(3));
while (await timer.WaitForNextTickAsync(ceiling.Token))
{
var r = await PostAsync<ScoreSolution>("getTaskResult", new { clientKey = apiKey, taskId = made.TaskId }, ceiling.Token);
if (r.Status == "ready" && r.Solution is not null) return r.Solution;
if (r.Status == "failed") throw new GateSolverException("TASK_FAILED", "no charge");
}
throw new OperationCanceledException();
}
}
Construct it with an HttpClient whose BaseAddress is https://gatesolver.com/ (note the trailing slash, so relative paths resolve correctly). If the ceiling passes, WaitForNextTickAsync throws an OperationCanceledException, which callers can treat as a timeout. A task unsolved at 120 seconds is marked failed and not charged.
Register it with dependency injection
In an ASP.NET Core app or a worker service, a named client with a typed client factory keeps HttpClient lifetimes correct and lets you pass the key, which the container could not resolve on its own:
builder.Services.AddHttpClient("gatesolver", c =>
{
c.BaseAddress = new Uri("https://gatesolver.com/");
c.Timeout = TimeSpan.FromSeconds(30);
}).AddTypedClient<V3Tokens>((client, sp) =>
new V3Tokens(client, sp.GetRequiredService<IConfiguration>()["GateSolver:ApiKey"]!));
The key comes from configuration, so it can live in user secrets during development and in an environment variable in production.
Send the token in the site's request
A v3 page normally posts the token to an API endpoint as part of a JSON body. Reproduce that request with the same field name and add the returned User-Agent:
var solver = app.Services.GetRequiredService<V3Tokens>();
var sol = await solver.ForActionAsync("https://shop.example.net/newsletter", "6Lc_SHOP_V3_KEY", "subscribe");
using var site = new HttpClient(new HttpClientHandler { UseCookies = true });
using var msg = new HttpRequestMessage(HttpMethod.Post, "https://shop.example.net/api/newsletter")
{
Content = JsonContent.Create(new { email = "qa+news@example.com", captcha = sol.Token })
};
if (!string.IsNullOrEmpty(sol.UserAgent)) msg.Headers.UserAgent.ParseAdd(sol.UserAgent);
using var answer = await site.SendAsync(msg);
Console.WriteLine($"{(int)answer.StatusCode} {await answer.Content.ReadAsStringAsync()}");
Here the field is called captcha because that is what this example site reads; yours may differ. Read it from the request the browser sent.
If the site turns the token down
- Check that the action matches the page for this request. A token for
homepageis not a token forsubscribe. - Do not cache tokens. Each one works once and for about two minutes.
- Load the page first with the same cookie handler if the endpoint needs a session or CSRF cookie.
- If the script is
enterprise.js, switch to reCAPTCHA v3 Enterprise.
The score explainer covers how the site turns a token into a decision.
Retrying with Polly or plain code
If you use Polly or the .NET resilience packages, configure the retry predicate as ex is GateSolverException g && g.WorthRetrying with two attempts and a short delay. Without a library, a for loop with the same condition does the job. Never retry on ERROR_ZERO_BALANCE or ERROR_KEY_DENIED_ACCESS; they need a person.
Unit testing the solver
Pass an HttpClient built on a custom HttpMessageHandler that returns canned JSON: a task id, then processing, then ready. Because PeriodicTimer waits three real seconds, tests take a few seconds; if that matters, move the interval into a constructor parameter.
Why typed records pay off here
Working with JsonElement trees is quick for a single call, but a solver that will live in a service for months benefits from types. A misspelled property name becomes a null you can test for instead of a runtime exception deep in a job. The same ApiReply<T> works for other task types too: define a TokenSolution record with a Token property for Turnstile, or a CookieSolution for AWS WAF, and reuse PostAsync<T> unchanged. That keeps one tested envelope for every CAPTCHA type your application handles.
Logging and secrets
Log the task id, the action and the elapsed time with structured logging (ILogger message templates work well), and leave the token itself out of the logs. Store the API key with user secrets in development and in your host's secret store in production. Rotating the key from the account page replaces the old one, so update configuration in the same step.
Choosing the poll interval
Three seconds suits v3. A shorter interval does not make the answer arrive sooner and only spends requests from your 600 per minute. If you reuse the class for image tasks, make the interval a constructor parameter and set it to one second there.
A quick manual check
Before automating, compare one manual submit with one automated submit in a proxy tool or the browser's Network tab. If the bodies match field for field, apart from the token, the site has no reason to treat them differently.
Common questions
Which .NET version does this code need?
.NET 8 or newer, for primary constructors on classes and PeriodicTimer. On older versions use a normal constructor and Task.Delay.
Why a generic ApiReply record?
Both endpoints share one envelope. A generic solution type avoids separate classes for each reply and each CAPTCHA type.
Does HttpClient need a trailing slash in BaseAddress?
Yes, when you post to relative paths like createTask. Without it the last segment of the base address is replaced.
Can I solve v3 tokens in parallel?
Yes. Concurrent tasks are not limited; keep the total requests under 600 per minute per key.
What does the userAgent in the solution do?
It names the browser under which the token was produced. Sending the same value with your request keeps the visit consistent.
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 scores explainedHow Google turns page signals into a v3 score, how sites act on it, and what a solver can and cannot influence.
- pageAction (reCAPTCHA action)The action label a page passes to grecaptcha.execute, how to locate it, and why a wrong label sinks good tokens.