@getanyapi/sdk 0.178.19 → 0.179.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -1
- package/dist/index.cjs +18 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +18 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -135,7 +135,7 @@ Per-call transport overrides: `timeoutMs`, `maxRetries`, `maxInProgressWaitMs`,
|
|
|
135
135
|
| `InsufficientBalanceError` | 402 | Wallet balance or per-key cap exceeded |
|
|
136
136
|
| `NotFoundError` | 404 | Slug or resource does not exist |
|
|
137
137
|
| `ResultNotFoundError` | - | `unwrap` on an empty found-data result |
|
|
138
|
-
| `RateLimitedError` | 429 | Too many requests
|
|
138
|
+
| `RateLimitedError` | 429 | Too many requests; see below |
|
|
139
139
|
| `UpstreamError` | 502 | An upstream backend failed |
|
|
140
140
|
| `ConnectionError` | 0 | Network or transport failure |
|
|
141
141
|
| `TimeoutError` | 0 | Request exceeded its timeout (not retried) |
|
|
@@ -148,6 +148,14 @@ billed `POST /v1/run` are not retried because the call may already have been cha
|
|
|
148
148
|
send phase is unknown, the SDK does not retry. Configure with
|
|
149
149
|
`new AnyAPI({ timeoutMs, maxRetries })`.
|
|
150
150
|
|
|
151
|
+
### Rate limits
|
|
152
|
+
|
|
153
|
+
Each account may start a limited number of new requests to one API per UTC minute. A request over
|
|
154
|
+
the limit gets `429` with `code` `rate_limited` and `Retry-After` set to the seconds until the
|
|
155
|
+
next minute; nothing was run or charged. `RateLimitedError.retryAfterSeconds` carries that delay. The SDK
|
|
156
|
+
retries a 429 only when its `Retry-After` is 8 seconds or less, waiting it in full; a longer one
|
|
157
|
+
is raised at once so you can wait or spread the load.
|
|
158
|
+
|
|
151
159
|
### Waiting out a run that is still in flight
|
|
152
160
|
|
|
153
161
|
Settlement is detached from your connection, so a run keeps going after a connection drops. When
|
package/dist/index.cjs
CHANGED
|
@@ -172,6 +172,13 @@ var NotFoundError = class extends AnyAPIError {
|
|
|
172
172
|
var ResultNotFoundError = class extends NotFoundError {
|
|
173
173
|
};
|
|
174
174
|
var RateLimitedError = class extends AnyAPIError {
|
|
175
|
+
retryAfterSeconds;
|
|
176
|
+
constructor(message, status, requestId, code, retryAfterSeconds) {
|
|
177
|
+
super(message, status, requestId, code);
|
|
178
|
+
if (retryAfterSeconds !== void 0) {
|
|
179
|
+
this.retryAfterSeconds = retryAfterSeconds;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
175
182
|
};
|
|
176
183
|
var UpstreamError = class extends AnyAPIError {
|
|
177
184
|
};
|
|
@@ -194,7 +201,7 @@ function requestIdOf(headers) {
|
|
|
194
201
|
}
|
|
195
202
|
return void 0;
|
|
196
203
|
}
|
|
197
|
-
function errorFromStatus(status, message, requestId, code) {
|
|
204
|
+
function errorFromStatus(status, message, requestId, code, retryAfterSeconds) {
|
|
198
205
|
switch (status) {
|
|
199
206
|
case 400:
|
|
200
207
|
return new BadRequestError(message, status, requestId, code);
|
|
@@ -205,7 +212,7 @@ function errorFromStatus(status, message, requestId, code) {
|
|
|
205
212
|
case 404:
|
|
206
213
|
return new NotFoundError(message, status, requestId, code);
|
|
207
214
|
case 429:
|
|
208
|
-
return new RateLimitedError(message, status, requestId, code);
|
|
215
|
+
return new RateLimitedError(message, status, requestId, code, retryAfterSeconds);
|
|
209
216
|
case 502:
|
|
210
217
|
return new UpstreamError(message, status, requestId, code);
|
|
211
218
|
default:
|
|
@@ -1036,9 +1043,8 @@ var AnyAPI = class {
|
|
|
1036
1043
|
const retryAfterMs = parseRetryAfterMs(
|
|
1037
1044
|
response.headers.get("retry-after")
|
|
1038
1045
|
);
|
|
1039
|
-
if (response.status === 429 && attempt < opts.maxRetries) {
|
|
1040
|
-
|
|
1041
|
-
await sleep(delay, opts.signal);
|
|
1046
|
+
if (response.status === 429 && attempt < opts.maxRetries && (retryAfterMs === void 0 || retryAfterMs <= RETRY_MAX_DELAY_MS)) {
|
|
1047
|
+
await sleep(retryAfterMs ?? backoffDelay(attempt), opts.signal);
|
|
1042
1048
|
attempt += 1;
|
|
1043
1049
|
continue;
|
|
1044
1050
|
}
|
|
@@ -1051,7 +1057,13 @@ var AnyAPI = class {
|
|
|
1051
1057
|
continue;
|
|
1052
1058
|
}
|
|
1053
1059
|
}
|
|
1054
|
-
throw errorFromStatus(
|
|
1060
|
+
throw errorFromStatus(
|
|
1061
|
+
response.status,
|
|
1062
|
+
message,
|
|
1063
|
+
requestId,
|
|
1064
|
+
code,
|
|
1065
|
+
retryAfterMs === void 0 ? void 0 : Math.ceil(retryAfterMs / 1e3)
|
|
1066
|
+
);
|
|
1055
1067
|
}
|
|
1056
1068
|
}
|
|
1057
1069
|
/** Internal accessor for GET helpers in account.ts (same base URL / machinery). */
|