@getanyapi/sdk 0.1.0 → 0.7.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/README.md CHANGED
@@ -18,8 +18,8 @@ import { AnyAPI } from "@getanyapi/sdk";
18
18
  const client = new AnyAPI({ apiKey: process.env.ANYAPI_API_KEY });
19
19
 
20
20
  const res = await client.reddit.search({ query: "mechanical keyboard" });
21
- for (const post of res.output.posts) {
22
- console.log(post.title, post.score);
21
+ if (res.output.found) {
22
+ for (const post of res.output.data.posts) console.log(post.title, post.score);
23
23
  }
24
24
  console.log("charged", res.costUsd, "USD");
25
25
  ```
@@ -28,7 +28,10 @@ Every SKU is a typed method under its platform namespace (`client.amazon.reviews
28
28
  `client.google.search(...)`). You can also call any SKU generically by slug with full typing:
29
29
 
30
30
  ```ts
31
- const rev = await client.run("amazon.reviews", { product: "B07FZ8S74R", limit: 3 });
31
+ const rev = await client.run("amazon.reviews", {
32
+ product: "B07FZ8S74R",
33
+ limit: 3,
34
+ });
32
35
  ```
33
36
 
34
37
  ## Not found vs error
@@ -51,9 +54,26 @@ try {
51
54
  ```
52
55
 
53
56
  `ResultNotFoundError` extends `NotFoundError`, so `catch (NotFoundError)` catches both an
54
- HTTP 404 and an empty result; catch `ResultNotFoundError` to handle only empty results. A few
55
- SKUs (e.g. `reddit.search`) return their data object directly as `output` with no `found`
56
- wrapper; `unwrap` returns it as-is and never throws for those.
57
+ HTTP 404 and an empty result; catch `ResultNotFoundError` to handle only empty results. If a
58
+ future committed schema uses a bare output, generated typing returns its data object directly
59
+ rather than relying on a hard-coded SKU list.
60
+
61
+ ## Discovery
62
+
63
+ ```ts
64
+ const apis = await client.catalog({ category: "search" });
65
+ const matches = await client.search({
66
+ query: "web search",
67
+ platform: "google",
68
+ limit: 10,
69
+ });
70
+ const api = await client.describe(matches.results[0]!.slug);
71
+ console.log(api.pricing.from, api.pricing.failoverMaxUsd, api.inputSchema);
72
+ ```
73
+
74
+ `catalog` is category-only browsing. Ranked queries always use `search`, which returns
75
+ `results`, `total`, and `ranking`; `describe` includes schemas. Discovery prices are nested
76
+ USD flat/linear offers, lanes are anonymous, and provider is always `"AnyAPI"`.
57
77
 
58
78
  ## Pagination
59
79
 
@@ -62,12 +82,17 @@ you. Call `.pages()` on it to walk whole results instead (each carries its own `
62
82
 
63
83
  ```ts
64
84
  // Flatten items across pages, capped at 100 total.
65
- for await (const post of client.reddit.iterSearch({ query: "coffee" }, { maxItems: 100 })) {
85
+ for await (const post of client.reddit.iterSearch(
86
+ { query: "coffee" },
87
+ { maxItems: 100 },
88
+ )) {
66
89
  console.log(post.title);
67
90
  }
68
91
 
69
92
  // Or walk pages to read per-page cost.
70
- for await (const page of client.reddit.iterSearch({ query: "coffee" }).pages()) {
93
+ for await (const page of client.reddit
94
+ .iterSearch({ query: "coffee" })
95
+ .pages()) {
71
96
  console.log(page.costUsd);
72
97
  }
73
98
  ```
@@ -82,8 +107,8 @@ await client.google.search(
82
107
  { query: "coffee" },
83
108
  {
84
109
  fields: ["title", "link"], // keep only these keys on each item
85
- maxItems: 5, // cap result rows returned
86
- summary: true, // structural outline instead of full data
110
+ maxItems: 5, // cap result rows returned
111
+ summary: true, // structural outline instead of full data
87
112
  },
88
113
  );
89
114
  ```
@@ -92,17 +117,17 @@ Per-call transport overrides: `timeoutMs`, `maxRetries`, and an `AbortSignal` vi
92
117
 
93
118
  ## Errors and retries
94
119
 
95
- | Class | HTTP | Meaning |
96
- | --- | --- | --- |
97
- | `BadRequestError` | 400 | Input failed validation |
98
- | `AuthenticationError` | 401 | Missing or invalid API key |
99
- | `InsufficientBalanceError` | 402 | Wallet balance or per-key cap exceeded |
100
- | `NotFoundError` | 404 | Slug or resource does not exist |
101
- | `ResultNotFoundError` | - | `unwrap` on an empty found-data result |
102
- | `RateLimitedError` | 429 | Too many requests (retried automatically) |
103
- | `UpstreamError` | 502 | An upstream backend failed |
104
- | `ConnectionError` | 0 | Network or transport failure (retried) |
105
- | `TimeoutError` | 0 | Request exceeded its timeout (not retried) |
120
+ | Class | HTTP | Meaning |
121
+ | -------------------------- | ---- | ------------------------------------------ |
122
+ | `BadRequestError` | 400 | Input failed validation |
123
+ | `AuthenticationError` | 401 | Missing or invalid API key |
124
+ | `InsufficientBalanceError` | 402 | Wallet balance or per-key cap exceeded |
125
+ | `NotFoundError` | 404 | Slug or resource does not exist |
126
+ | `ResultNotFoundError` | - | `unwrap` on an empty found-data result |
127
+ | `RateLimitedError` | 429 | Too many requests (retried automatically) |
128
+ | `UpstreamError` | 502 | An upstream backend failed |
129
+ | `ConnectionError` | 0 | Network or transport failure (retried) |
130
+ | `TimeoutError` | 0 | Request exceeded its timeout (not retried) |
106
131
 
107
132
  All extend `AnyAPIError` (with `status` and `requestId`). Retries cover only 429 and network
108
133
  failures, with jittered exponential backoff honoring `Retry-After`. Default `maxRetries` is 2
@@ -120,7 +145,7 @@ const { secret, capUsd, claimUrl } = await agentSignup({ label: "my-agent" });
120
145
  const client = new AnyAPI({ apiKey: secret });
121
146
  ```
122
147
 
123
- The key ships with a small starter credit and a per-key spend cap; a human funds it by
148
+ The key ships with a small starter balance and a per-key spend cap; a human funds it by
124
149
  claiming it at `claimUrl`.
125
150
 
126
151
  ## Docs