@@ -26,9 +26,11 @@ const client = new BrowserUse({
26
26
apiKey: process .env [' BROWSER_USE_API_KEY' ], // This is the default and can be omitted
27
27
});
28
28
29
- const me = await client .users .me .retrieve ();
29
+ const task = await client .tasks .create ({
30
+ task: ' Search for the top 10 Hacker News posts and return the title and url.' ,
31
+ });
30
32
31
- console .log (me . additionalCreditsBalanceUsd );
33
+ console .log (task . id );
32
34
```
33
35
34
36
### Request & Response types
@@ -43,7 +45,10 @@ const client = new BrowserUse({
43
45
apiKey: process .env [' BROWSER_USE_API_KEY' ], // This is the default and can be omitted
44
46
});
45
47
46
- const me: BrowserUse .Users .MeRetrieveResponse = await client .users .me .retrieve ();
48
+ const params: BrowserUse .TaskCreateParams = {
49
+ task: ' Search for the top 10 Hacker News posts and return the title and url.' ,
50
+ };
51
+ const task: BrowserUse .TaskCreateResponse = await client .tasks .create (params );
47
52
```
48
53
49
54
Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.
@@ -56,15 +61,17 @@ a subclass of `APIError` will be thrown:
56
61
57
62
<!-- prettier-ignore -->
58
63
``` ts
59
- const me = await client .users .me .retrieve ().catch (async (err ) => {
60
- if (err instanceof BrowserUse .APIError ) {
61
- console .log (err .status ); // 400
62
- console .log (err .name ); // BadRequestError
63
- console .log (err .headers ); // {server: 'nginx', ...}
64
- } else {
65
- throw err ;
66
- }
67
- });
64
+ const task = await client .tasks
65
+ .create ({ task: ' Search for the top 10 Hacker News posts and return the title and url.' })
66
+ .catch (async (err ) => {
67
+ if (err instanceof BrowserUse .APIError ) {
68
+ console .log (err .status ); // 400
69
+ console .log (err .name ); // BadRequestError
70
+ console .log (err .headers ); // {server: 'nginx', ...}
71
+ } else {
72
+ throw err ;
73
+ }
74
+ });
68
75
```
69
76
70
77
Error codes are as follows:
@@ -96,7 +103,7 @@ const client = new BrowserUse({
96
103
});
97
104
98
105
// Or, configure per-request:
99
- await client .users . me . retrieve ( {
106
+ await client .tasks . create ({ task : ' Search for the top 10 Hacker News posts and return the title and url. ' }, {
100
107
maxRetries: 5 ,
101
108
});
102
109
```
@@ -113,7 +120,7 @@ const client = new BrowserUse({
113
120
});
114
121
115
122
// Override per-request:
116
- await client .users . me . retrieve ( {
123
+ await client .tasks . create ({ task: ' Search for the top 10 Hacker News posts and return the title and url. ' }, {
117
124
timeout: 5 * 1000 ,
118
125
});
119
126
```
@@ -136,13 +143,17 @@ Unlike `.asResponse()` this method consumes the body, returning once it is parse
136
143
``` ts
137
144
const client = new BrowserUse ();
138
145
139
- const response = await client .users .me .retrieve ().asResponse ();
146
+ const response = await client .tasks
147
+ .create ({ task: ' Search for the top 10 Hacker News posts and return the title and url.' })
148
+ .asResponse ();
140
149
console .log (response .headers .get (' X-My-Header' ));
141
150
console .log (response .statusText ); // access the underlying Response object
142
151
143
- const { data : me, response : raw } = await client .users .me .retrieve ().withResponse ();
152
+ const { data : task, response : raw } = await client .tasks
153
+ .create ({ task: ' Search for the top 10 Hacker News posts and return the title and url.' })
154
+ .withResponse ();
144
155
console .log (raw .headers .get (' X-My-Header' ));
145
- console .log (me . additionalCreditsBalanceUsd );
156
+ console .log (task . id );
146
157
```
147
158
148
159
### Logging
@@ -222,7 +233,7 @@ parameter. This library doesn't validate at runtime that the request matches the
222
233
send will be sent as-is.
223
234
224
235
``` ts
225
- client .users . me . retrieve ({
236
+ client .tasks . create ({
226
237
// ...
227
238
// @ts-expect-error baz is not yet public
228
239
baz: ' undocumented option' ,
0 commit comments