stophy 1.0.7 → 1.2.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
@@ -1,6 +1,6 @@
1
1
  # Stophy for TypeScript
2
2
 
3
- The web data layer for AI agents, in TypeScript. Live web data as typed JSON. Search, video, social, jobs, places, property and ads behind one key, with a price shown before every call. You pay only for answers that come back. Every method and result is typed.
3
+ Web scraping API for AI agents, in TypeScript. One API to search the web, read what people say, and look up products, places, jobs and homes. Pay only for answers. Every method and result is typed.
4
4
 
5
5
  ## Install
6
6
 
@@ -17,7 +17,7 @@ const result = await new Stophy().google.search({ query: "bun runtime" });
17
17
  console.log(result.data.results);
18
18
  ```
19
19
 
20
- Google search, Google News, YouTube search, YouTube video details and YouTube transcripts work without a key, with a small free allowance. Every other method throws a `StophyError` with the code `unauthorized`.
20
+ Some searches and lookups work without a key, within a small free allowance. The [endpoint list](https://api.stophy.dev/v1/endpoints) marks them with `keyless: true`. Every other method throws a `StophyError` with the code `unauthorized`.
21
21
 
22
22
  ## Use an API key
23
23
 
@@ -32,50 +32,51 @@ console.log(videos.data.results);
32
32
 
33
33
  `new Stophy("st_...")` works too.
34
34
 
35
- Methods follow the source and the command: `stophy.maps.search(...)`, `stophy.reddit.subreddit(...)`, `stophy.ads.search({ network: "meta", ... })`. Endpoints with a single name are methods on the client, like `stophy.transcript(...)`.
35
+ Methods follow the source and the command: `stophy.google.maps.search(...)`, `stophy.reddit.subreddit(...)`, `stophy.meta.ads.search(...)`.
36
+
37
+ To point at one thing, send its link or its id, never both: `stophy.youtube.video({ videoUrl })` or `stophy.youtube.video({ videoId })`. Methods that take a person send `userUrl` or `username`.
36
38
 
37
39
  Every response is `{ success, data, creditsUsed, requestId }`. `data` is one flat object. Lists are in `data.results`.
38
40
 
39
41
  ## More data
40
42
 
41
- A transcript, Reddit posts, Google Maps reviews, a TikTok profile and Meta ads:
43
+ A YouTube transcript, Reddit posts, Google Maps reviews, a TikTok profile and Meta ads:
42
44
 
43
45
  ```ts
44
46
  const stophy = new Stophy({ apiKey: "st_..." });
45
47
 
46
- const transcript = await stophy.transcript({ video: "https://youtu.be/dQw4w9WgXcQ", includeTimestamps: true });
48
+ const transcript = await stophy.youtube.transcript({
49
+ videoUrl: "https://youtu.be/dQw4w9WgXcQ",
50
+ includeTimestamps: true,
51
+ });
47
52
  console.log(transcript.data.text, transcript.data.segments);
48
53
 
49
54
  const posts = await stophy.reddit.search({ query: "bun runtime", sort: "top", within: "month" });
50
55
  console.log(posts.data.results);
51
56
 
52
- const places = await stophy.maps.search({ query: "coffee", location: "Austin, TX" });
57
+ const places = await stophy.google.maps.search({ query: "coffee", location: "Austin, TX" });
53
58
  const placeId = places.data.results[0]?.placeId;
54
59
  if (placeId) {
55
- const reviews = await stophy.maps.reviews({ place: placeId });
60
+ const reviews = await stophy.google.maps.reviews({ placeId });
56
61
  console.log(reviews.data.results);
57
62
  }
58
63
 
59
- const profile = await stophy.tiktok.profile({ profile: "tiktok" });
64
+ const profile = await stophy.tiktok.profile({ username: "tiktok" });
60
65
  console.log(profile.data.followers, profile.data.results);
61
66
 
62
- const ads = await stophy.ads.search({ network: "meta", query: "running shoes" });
67
+ const ads = await stophy.meta.ads.search({ query: "running shoes" });
63
68
  console.log(ads.data.results);
64
69
  ```
65
70
 
66
- `ads.search` covers several ad networks. Pick one with `network`. The types follow the choice.
67
-
68
71
  ## Get the next page
69
72
 
70
73
  Each call returns one page of results, as the site shows it. List methods page in one of two ways.
71
74
 
72
- Some take a page number. They return `data.page` and `data.hasMore`. Ask for the next number while `hasMore` is true:
75
+ Some take a page number. They return `data.page`. Ask for the next number to continue, and stop when `results` comes back empty:
73
76
 
74
77
  ```ts
75
78
  const first = await stophy.google.search({ query: "bun runtime" });
76
- if (first.data.hasMore) {
77
- const second = await stophy.google.search({ query: "bun runtime", page: 2 });
78
- }
79
+ const second = await stophy.google.search({ query: "bun runtime", page: first.data.page + 1 });
79
80
  ```
80
81
 
81
82
  Others return `data.cursor` when there is more. Pass it back as is:
@@ -107,12 +108,12 @@ The SDK retries network errors and the HTTP statuses 429, 500, 502, 503, and 504
107
108
 
108
109
  ## Options
109
110
 
110
- | Option | Default | What it does |
111
- | --- | --- | --- |
112
- | `apiKey` | `STOPHY_API_KEY` | Your API key |
113
- | `baseUrl` | `STOPHY_BASE_URL`, or the Stophy API | The server to call |
114
- | `maxRetries` | `2` | Retries per request. `0` turns retries off. |
115
- | `timeoutMs` | `30000` | Time limit for each attempt. A timed-out attempt is not retried. |
111
+ | Option | Default | What it does |
112
+ | ------------ | ------------------------------------ | ---------------------------------------------------------------- |
113
+ | `apiKey` | `STOPHY_API_KEY` | Your API key |
114
+ | `baseUrl` | `STOPHY_BASE_URL`, or the Stophy API | The server to call |
115
+ | `maxRetries` | `2` | Retries per request. `0` turns retries off. |
116
+ | `timeoutMs` | `70000` | Time limit for each attempt. A timed-out attempt is not retried. |
116
117
 
117
118
  Each method also takes `signal` to cancel the request.
118
119