@getanyapi/sdk 0.178.19 → 0.179.1

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/dist/index.d.cts CHANGED
@@ -485,8 +485,14 @@ declare class NotFoundError extends AnyAPIError {
485
485
  */
486
486
  declare class ResultNotFoundError extends NotFoundError {
487
487
  }
488
- /** HTTP 429. */
488
+ /**
489
+ * HTTP 429. `retryAfterSeconds` is the response's Retry-After when it carried one: wait that
490
+ * long before sending again. Code `rate_limited` on a run means the account reached its limit
491
+ * of new requests a minute to that API; nothing was run or charged.
492
+ */
489
493
  declare class RateLimitedError extends AnyAPIError {
494
+ readonly retryAfterSeconds?: number;
495
+ constructor(message: string, status: number, requestId?: string, code?: string, retryAfterSeconds?: number);
490
496
  }
491
497
  /** HTTP 502. */
492
498
  declare class UpstreamError extends AnyAPIError {
@@ -24764,7 +24770,7 @@ declare class GoogleNamespace {
24764
24770
  *
24765
24771
  * Ask Google Search a prompt and receive the AI Overview it generated for that scrape, with every source Google listed. Google regenerates the overview per search, so the same prompt can return different wording and a different source list.
24766
24772
  *
24767
- * Price: $0.0048 per request.
24773
+ * Price: $0.0018 per request.
24768
24774
  *
24769
24775
  * @example
24770
24776
  * const res = await client.google.aiOverview({ prompt: "How does photosynthesis work?" });
package/dist/index.d.ts CHANGED
@@ -485,8 +485,14 @@ declare class NotFoundError extends AnyAPIError {
485
485
  */
486
486
  declare class ResultNotFoundError extends NotFoundError {
487
487
  }
488
- /** HTTP 429. */
488
+ /**
489
+ * HTTP 429. `retryAfterSeconds` is the response's Retry-After when it carried one: wait that
490
+ * long before sending again. Code `rate_limited` on a run means the account reached its limit
491
+ * of new requests a minute to that API; nothing was run or charged.
492
+ */
489
493
  declare class RateLimitedError extends AnyAPIError {
494
+ readonly retryAfterSeconds?: number;
495
+ constructor(message: string, status: number, requestId?: string, code?: string, retryAfterSeconds?: number);
490
496
  }
491
497
  /** HTTP 502. */
492
498
  declare class UpstreamError extends AnyAPIError {
@@ -24764,7 +24770,7 @@ declare class GoogleNamespace {
24764
24770
  *
24765
24771
  * Ask Google Search a prompt and receive the AI Overview it generated for that scrape, with every source Google listed. Google regenerates the overview per search, so the same prompt can return different wording and a different source list.
24766
24772
  *
24767
- * Price: $0.0048 per request.
24773
+ * Price: $0.0018 per request.
24768
24774
  *
24769
24775
  * @example
24770
24776
  * const res = await client.google.aiOverview({ prompt: "How does photosynthesis work?" });
package/dist/index.js CHANGED
@@ -33,6 +33,13 @@ var NotFoundError = class extends AnyAPIError {
33
33
  var ResultNotFoundError = class extends NotFoundError {
34
34
  };
35
35
  var RateLimitedError = class extends AnyAPIError {
36
+ retryAfterSeconds;
37
+ constructor(message, status, requestId, code, retryAfterSeconds) {
38
+ super(message, status, requestId, code);
39
+ if (retryAfterSeconds !== void 0) {
40
+ this.retryAfterSeconds = retryAfterSeconds;
41
+ }
42
+ }
36
43
  };
37
44
  var UpstreamError = class extends AnyAPIError {
38
45
  };
@@ -55,7 +62,7 @@ function requestIdOf(headers) {
55
62
  }
56
63
  return void 0;
57
64
  }
58
- function errorFromStatus(status, message, requestId, code) {
65
+ function errorFromStatus(status, message, requestId, code, retryAfterSeconds) {
59
66
  switch (status) {
60
67
  case 400:
61
68
  return new BadRequestError(message, status, requestId, code);
@@ -66,7 +73,7 @@ function errorFromStatus(status, message, requestId, code) {
66
73
  case 404:
67
74
  return new NotFoundError(message, status, requestId, code);
68
75
  case 429:
69
- return new RateLimitedError(message, status, requestId, code);
76
+ return new RateLimitedError(message, status, requestId, code, retryAfterSeconds);
70
77
  case 502:
71
78
  return new UpstreamError(message, status, requestId, code);
72
79
  default:
@@ -897,9 +904,8 @@ var AnyAPI = class {
897
904
  const retryAfterMs = parseRetryAfterMs(
898
905
  response.headers.get("retry-after")
899
906
  );
900
- if (response.status === 429 && attempt < opts.maxRetries) {
901
- const delay = retryAfterMs !== void 0 ? Math.min(retryAfterMs, RETRY_MAX_DELAY_MS) : backoffDelay(attempt);
902
- await sleep(delay, opts.signal);
907
+ if (response.status === 429 && attempt < opts.maxRetries && (retryAfterMs === void 0 || retryAfterMs <= RETRY_MAX_DELAY_MS)) {
908
+ await sleep(retryAfterMs ?? backoffDelay(attempt), opts.signal);
903
909
  attempt += 1;
904
910
  continue;
905
911
  }
@@ -912,7 +918,13 @@ var AnyAPI = class {
912
918
  continue;
913
919
  }
914
920
  }
915
- throw errorFromStatus(response.status, message, requestId, code);
921
+ throw errorFromStatus(
922
+ response.status,
923
+ message,
924
+ requestId,
925
+ code,
926
+ retryAfterMs === void 0 ? void 0 : Math.ceil(retryAfterMs / 1e3)
927
+ );
916
928
  }
917
929
  }
918
930
  /** Internal accessor for GET helpers in account.ts (same base URL / machinery). */
@@ -3545,7 +3557,7 @@ var GoogleNamespace = class {
3545
3557
  *
3546
3558
  * Ask Google Search a prompt and receive the AI Overview it generated for that scrape, with every source Google listed. Google regenerates the overview per search, so the same prompt can return different wording and a different source list.
3547
3559
  *
3548
- * Price: $0.0048 per request.
3560
+ * Price: $0.0018 per request.
3549
3561
  *
3550
3562
  * @example
3551
3563
  * const res = await client.google.aiOverview({ prompt: "How does photosynthesis work?" });