or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

audio-text-captchas.mdcloud-captchas.mdcore-solver.mdemerging-captchas.mdimage-captchas.mdindex.mdinteractive-captchas.mdspecialized-captchas.md

core-solver.mddocs/

0

# Core Solver API

1

2

The core solver API provides the foundation for all captcha solving operations through the TwoCaptcha class. It handles initialization, generic solving methods, account management, and error handling.

3

4

## Capabilities

5

6

### TwoCaptcha Class

7

8

Main solver class that provides both high-level captcha-specific methods and low-level generic solving capabilities.

9

10

```python { .api }

11

class TwoCaptcha:

12

def __init__(self, apiKey, softId=4580, callback=None,

13

defaultTimeout=120, recaptchaTimeout=600,

14

pollingInterval=10, server='2captcha.com',

15

extendedResponse=None):

16

"""

17

Initialize the 2captcha solver.

18

19

Parameters:

20

- apiKey (str): Your 2captcha API key (required)

21

- softId (int): Software developer ID (default: 4580)

22

- callback (str): URL for pingback when captcha is solved

23

- defaultTimeout (int): Default timeout in seconds for most captcha types (default: 120)

24

- recaptchaTimeout (int): Timeout in seconds for reCAPTCHA (default: 600)

25

- pollingInterval (int): Interval in seconds between result polling (default: 10)

26

- server (str): 2captcha server domain (default: '2captcha.com')

27

- extendedResponse (bool): Return extended response format

28

"""

29

```

30

31

### Generic Solving Methods

32

33

Core methods for submitting captchas and retrieving results, providing manual control over the solving process.

34

35

```python { .api }

36

def solve(self, timeout=0, polling_interval=0, **kwargs):

37

"""

38

Generic solve method that submits captcha and waits for result.

39

40

Parameters:

41

- timeout (int): Override default timeout (0 = use default)

42

- polling_interval (int): Override default polling interval (0 = use default)

43

- **kwargs: Captcha-specific parameters

44

45

Returns:

46

dict: {'captchaId': str, 'code': str} or extended format if enabled

47

"""

48

49

def send(self, **kwargs):

50

"""

51

Manually submit captcha without waiting for result.

52

53

Parameters:

54

- method (str): Captcha type method

55

- **kwargs: Captcha-specific parameters

56

57

Returns:

58

str: Captcha ID for later result retrieval

59

"""

60

61

def get_result(self, id_):

62

"""

63

Manually poll for captcha result.

64

65

Parameters:

66

- id_ (str): Captcha ID returned from send() method

67

68

Returns:

69

str: Solution code or dict if extendedResponse enabled

70

"""

71

```

72

73

### Account Management

74

75

Methods for managing your 2captcha account including balance checking and solution quality reporting.

76

77

```python { .api }

78

def balance(self):

79

"""

80

Get current account balance.

81

82

Returns:

83

float: Account balance in USD

84

"""

85

86

def report(self, id_, correct):

87

"""

88

Report captcha solution quality for refund eligibility.

89

90

Parameters:

91

- id_ (str): Captcha ID of solved captcha

92

- correct (bool): True if solution was correct, False if incorrect

93

"""

94

```

95

96

### Internal Helper Methods

97

98

Internal utility methods used by the solver but not intended for direct use by end users. These methods are accessible but primarily used internally by the TwoCaptcha class.

99

100

```python { .api }

101

def wait_result(self, id_, timeout, polling_interval):

102

"""

103

Internal method to wait for captcha result with custom timeout and polling.

104

105

Parameters:

106

- id_ (str): Captcha ID

107

- timeout (int): Maximum wait time in seconds

108

- polling_interval (int): Seconds between polls

109

110

Returns:

111

str: Solution code or dict if extendedResponse enabled

112

113

Note: This is an internal method. Use solve() for automatic solving.

114

"""

115

116

def get_method(self, file):

117

"""

118

Internal method to determine API submission method based on file input.

119

120

Parameters:

121

- file (str): File path or base64 string

122

123

Returns:

124

dict: Method parameters for API submission

125

126

Note: This is an internal method used by captcha solving methods.

127

"""

128

```

129

130

## Usage Examples

131

132

### Basic Automatic Solving

133

134

```python

135

from twocaptcha import TwoCaptcha

136

137

# Initialize solver

138

solver = TwoCaptcha('your_api_key')

139

140

# Automatic solving (submit and wait)

141

try:

142

result = solver.solve(method='post', file='captcha.jpg')

143

print(f"Solved: {result['code']}")

144

except Exception as e:

145

print(f"Error: {e}")

146

```

147

148

### Manual Control

149

150

```python

151

from twocaptcha import TwoCaptcha, TimeoutException

152

153

solver = TwoCaptcha('your_api_key')

154

155

try:

156

# Submit captcha

157

captcha_id = solver.send(method='post', file='captcha.jpg')

158

print(f"Submitted: {captcha_id}")

159

160

# Wait for result with custom timeout

161

result = solver.wait_result(captcha_id, timeout=60, polling_interval=5)

162

print(f"Solved: {result}")

163

164

except TimeoutException:

165

print("Captcha solving timed out")

166

except Exception as e:

167

print(f"Error: {e}")

168

```

169

170

### Account Management

171

172

```python

173

from twocaptcha import TwoCaptcha

174

175

solver = TwoCaptcha('your_api_key')

176

177

# Check balance

178

balance = solver.balance()

179

print(f"Balance: ${balance}")

180

181

# Report incorrect solution for refund

182

solver.report('captcha_id_here', correct=False)

183

```

184

185

### Custom Configuration

186

187

```python

188

from twocaptcha import TwoCaptcha

189

190

# Custom timeouts and server

191

solver = TwoCaptcha(

192

apiKey='your_api_key',

193

defaultTimeout=180, # 3 minutes for normal captchas

194

recaptchaTimeout=900, # 15 minutes for reCAPTCHA

195

pollingInterval=5, # Check every 5 seconds

196

server='rucaptcha.com', # Alternative server

197

extendedResponse=True # Get detailed response format

198

)

199

```