synthient 1.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2696f98934be28fdf82de9ebc74ef028b180b804eaf314ae4e58503ffcb11ae9
4
+ data.tar.gz: 5135ce3a26b57f2f3058ad23d271395fdb5386537e2f3766514bc2e0905dee78
5
+ SHA512:
6
+ metadata.gz: 473ce8cd208288961a5aa3cef6e49b8de98981281cb3962d4cd089eb41217f6847484f912850f328c0df248e898c64462ad4a6f22d2049864b3ee8f7a96c1222
7
+ data.tar.gz: f7cf2f3ec63a98f9c89adbf1fd4b2d799097bf18263934482a7bc4fc92bab15c7cd4b437b152bbf5c33f9011950cc2a838435f8011a40f609227088c58411641
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 Synthient
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,420 @@
1
+ <p align="center">
2
+ <a href="https://synthient.com">
3
+ <img src="https://raw.githubusercontent.com/synthient/synthient-ruby/main/assets/logo.svg" height="96" alt="Synthient logo">
4
+ </a>
5
+ </p>
6
+ <h3 align="center">Synthient</h3>
7
+ <p align="center">High-fidelity data on residential proxies, VPNs, and other anonymized IPs.</p>
8
+ <p align="center">
9
+ <a href="https://docs.synthient.com">Documentation</a> ·
10
+ <a href="https://rubydoc.info/gems/synthient">API reference</a> ·
11
+ <a href="https://docs.synthient.com/misc/support">Support</a>
12
+ </p>
13
+
14
+ # synthient-ruby
15
+
16
+ The `synthient` gem is the official Ruby SDK for the [Synthient API](https://docs.synthient.com): IP and domain intelligence, account details, and real-time and bulk data feeds.
17
+
18
+ [![Gem Version](https://img.shields.io/gem/v/synthient)](https://rubygems.org/gems/synthient)
19
+ [![test](https://github.com/synthient/synthient-ruby/actions/workflows/test.yml/badge.svg)](https://github.com/synthient/synthient-ruby/actions/workflows/test.yml)
20
+ [![lint](https://github.com/synthient/synthient-ruby/actions/workflows/lint.yml/badge.svg)](https://github.com/synthient/synthient-ruby/actions/workflows/lint.yml)
21
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://github.com/synthient/synthient-ruby/blob/main/LICENSE)
22
+
23
+ ## Table of Contents
24
+
25
+ - [synthient-ruby](#synthient-ruby)
26
+ - [SDK Installation](#sdk-installation)
27
+ - [Requirements](#requirements)
28
+ - [API Keys](#api-keys)
29
+ - [Authentication](#authentication)
30
+ - [SDK Example Usage](#sdk-example-usage)
31
+ - [Available Resources and Operations](#available-resources-and-operations)
32
+ - [Streaming](#streaming)
33
+ - [Pagination](#pagination)
34
+ - [Downloads](#downloads)
35
+ - [Retries](#retries)
36
+ - [Timeouts](#timeouts)
37
+ - [Error Handling](#error-handling)
38
+ - [Server Selection](#server-selection)
39
+ - [Custom HTTP Client](#custom-http-client)
40
+ - [Debugging](#debugging)
41
+ - [gRPC Schema](#grpc-schema)
42
+ - [Development](#development)
43
+ - [Maturity](#maturity)
44
+ - [Contributions](#contributions)
45
+ - [License](#license)
46
+
47
+ ## SDK Installation
48
+
49
+ ### Bundler
50
+
51
+ ```sh
52
+ bundle add synthient
53
+ ```
54
+
55
+ ### RubyGems
56
+
57
+ ```sh
58
+ gem install synthient
59
+ ```
60
+
61
+ ### gRPC schema fetcher
62
+
63
+ The [gRPC schema fetcher](#grpc-schema) is part of the gem but needs the `grpc` and `google-protobuf` gems:
64
+
65
+ ```sh
66
+ bundle add grpc google-protobuf
67
+ ```
68
+
69
+ ## Requirements
70
+
71
+ Ruby 3.3 or later. The gem uses only Ruby's standard library. It ships RBS signatures, so [Steep](https://github.com/soutaro/steep) can check your calls with `library "synthient"` in your Steepfile.
72
+
73
+ ## API Keys
74
+
75
+ Every request needs a Synthient API key. Keys are issued from the Synthient dashboard; if you don't have one, [contact us](mailto:contact@synthient.com). A key's scopes decide what it can call: `BASIC` covers the lookups and `account`, and each feed has its own scopes, listed under [Feeds](#feeds).
76
+
77
+ If a request fails even though you are sending a key:
78
+
79
+ - **401 Unauthorized**: the key is malformed, unknown, or revoked.
80
+ - **402 Payment Required**: the team is out of lookup credits.
81
+ - **403 Forbidden**: the key lacks the scope for that endpoint or feed.
82
+
83
+ `account` shows the key's scopes and the team's remaining credits.
84
+
85
+ ## Authentication
86
+
87
+ This SDK supports the following security scheme:
88
+
89
+ | Name | Type | Scheme | Environment Variable |
90
+ | --------- | ------- | ------------------ | -------------------- |
91
+ | `api_key` | API key | `x-api-key` header | `SYNTHIENT_API_KEY` |
92
+
93
+ `Synthient::Client.new` reads the key from `SYNTHIENT_API_KEY`. To read it from somewhere else, such as a secret manager, pass `api_key:`:
94
+
95
+ ```ruby
96
+ client = Synthient::Client.new(api_key: ENV.fetch("SYNTHIENT_PRODUCTION_KEY"))
97
+ ```
98
+
99
+ Creating a client makes no network calls. To check a key, call `account`, which costs no credits.
100
+
101
+ ## SDK Example Usage
102
+
103
+ ### Look up an IP address
104
+
105
+ Get the network, location, and risk intelligence for an IPv4 or IPv6 address, given as a `String` or an `IPAddr`. Each lookup costs one credit; failed lookups are free.
106
+
107
+ ```ruby
108
+ require "synthient"
109
+
110
+ client = Synthient::Client.new # reads SYNTHIENT_API_KEY
111
+
112
+ info = client.lookup_ip("8.8.8.8")
113
+ intelligence = info.intelligence
114
+ puts "#{intelligence.risk_score} #{intelligence.categories.join(", ")}" if intelligence
115
+
116
+ client.close
117
+ ```
118
+
119
+ `network`, `location`, and `intelligence` are nil when the API has no data for them. Responses are frozen `Data` objects that support `to_h` and pattern matching.
120
+
121
+ A client keeps its connections open and is safe to share between threads, so create one, reuse it, and call `close` when you are done. The examples below reuse `client`, and runnable programs are in [examples](https://github.com/synthient/synthient-ruby/tree/main/examples).
122
+
123
+ ### Look up many IP addresses
124
+
125
+ Look up as many as 1000 addresses in one request for `ceil(n * 0.9)` credits. Private and reserved addresses are skipped and duplicates are merged, so match results by `ip`.
126
+
127
+ ```ruby
128
+ results = client.lookup_ips(["8.8.8.8", "1.1.1.1"])
129
+ results.each do |result|
130
+ puts "#{result.ip} #{result.intelligence&.risk_score}"
131
+ end
132
+ ```
133
+
134
+ ### Look up a domain
135
+
136
+ Get the honeypot traffic observed for a domain and its most recent events. Each lookup costs one credit.
137
+
138
+ ```ruby
139
+ domain = client.lookup_domain("example.com", limit: 10)
140
+ puts "#{domain.status} #{domain.stats.events_24h}"
141
+ domain.recent_events.each do |event|
142
+ puts "#{event.timestamp.iso8601} #{event.target_subdomain} #{event.port}"
143
+ end
144
+ ```
145
+
146
+ ### Check your account
147
+
148
+ Get the key's account, scopes, and remaining lookup credits, at no cost.
149
+
150
+ ```ruby
151
+ account = client.account
152
+ puts "#{account.organization.name} #{account.scopes.join(", ")} #{account.lookup_quota.credits}"
153
+ ```
154
+
155
+ ## Available Resources and Operations
156
+
157
+ <details open>
158
+ <summary>Available methods</summary>
159
+
160
+ ### [Client](https://rubydoc.info/gems/synthient/Synthient/Client)
161
+
162
+ - [`lookup_ip`](https://rubydoc.info/gems/synthient/Synthient/Client#lookup_ip-instance_method) - Look up an IPv4 or IPv6 address
163
+ - [`lookup_ips`](https://rubydoc.info/gems/synthient/Synthient/Client#lookup_ips-instance_method) - Look up as many as 1000 addresses in one request
164
+ - [`lookup_domain`](https://rubydoc.info/gems/synthient/Synthient/Client#lookup_domain-instance_method) - Look up the honeypot traffic observed for a domain
165
+ - [`account`](https://rubydoc.info/gems/synthient/Synthient/Client#account-instance_method) - Get the key's account, scopes, and remaining lookup credits
166
+ - [`health`](https://rubydoc.info/gems/synthient/Synthient/Client#health-instance_method) - Check that the API and its dependencies are healthy
167
+
168
+ ### [Feeds](https://rubydoc.info/gems/synthient/Synthient/Feed)
169
+
170
+ Each feed is a method of the client, such as `client.proxies`, and has the same methods:
171
+
172
+ - [`stream`](https://rubydoc.info/gems/synthient/Synthient/Feed#stream-instance_method) - Yield the feed's real-time events
173
+ - [`list_exports`](https://rubydoc.info/gems/synthient/Synthient/Feed#list_exports-instance_method) - List one page of the feed's Parquet exports, newest first
174
+ - [`each_export`](https://rubydoc.info/gems/synthient/Synthient/Feed#each_export-instance_method) - Yield every export, fetching pages as needed
175
+ - [`export_meta`](https://rubydoc.info/gems/synthient/Synthient/Feed#export_meta-instance_method) - Get an export's checksum, size, row count, and Parquet schema
176
+ - [`download`](https://rubydoc.info/gems/synthient/Synthient/Feed#download-instance_method) - Download an export's Parquet file in chunks
177
+ - [`download_url`](https://rubydoc.info/gems/synthient/Synthient/Feed#download_url-instance_method) - Get a presigned URL for an export's Parquet file, valid for 24 hours
178
+
179
+ | Method | Data | Event type | Stream scope | Export scope |
180
+ | -------------- | --------------------------------------------- | ------------------ | ----------------------- | --------------------- |
181
+ | `proxies` | Residential, mobile, and datacenter proxies | `ProxyEvent` | `PROXY_FIREHOSE` | `PROXY_FEEDS` |
182
+ | `anonymizers` | VPN and anonymizer IP ranges | `AnonymizerEvent` | `ANONYMIZERS_STREAM` | `ANONYMIZERS_FEED` |
183
+ | `torrents` | BitTorrent DHT and tracker peers | `TorrentEvent` | `TORRENTS_STREAM` | `TORRENTS_FEED` |
184
+ | `ja4t` | JA4T TCP fingerprints | `JA4TEvent` | `JA4T_STREAM` | `JA4T_FEED` |
185
+ | `helios_http` | Helios honeypot HTTP requests | `HeliosHTTPEvent` | `HONEYPOT_HTTP_STREAM` | `HONEYPOT_HTTP_FEED` |
186
+ | `helios_https` | Helios honeypot TLS ClientHellos | `HeliosHTTPSEvent` | `HONEYPOT_HTTPS_STREAM` | `HONEYPOT_HTTPS_FEED` |
187
+ | `helios_dns` | Helios honeypot tunnel destinations | `HeliosDNSEvent` | `HONEYPOT_DNS_STREAM` | `HONEYPOT_DNS_FEED` |
188
+ | `helios_adb` | Helios honeypot Android Debug Bridge commands | `HeliosADBEvent` | `HONEYPOT_ADB_STREAM` | `HONEYPOT_ADB_FEED` |
189
+
190
+ </details>
191
+
192
+ ## Streaming
193
+
194
+ `stream` yields a feed's real-time events. Each call opens a connection, and breaking out of the block closes it:
195
+
196
+ ```ruby
197
+ loop do
198
+ client.proxies.stream do |event|
199
+ puts "#{event.ip} #{event.provider} #{event.type}"
200
+ end
201
+ rescue Synthient::APIError => e
202
+ raise if [401, 403].include?(e.status)
203
+
204
+ warn "proxy stream: #{e.message}"
205
+ # Avoid reconnecting in a tight loop.
206
+ sleep 2
207
+ rescue Synthient::Error => e
208
+ warn "proxy stream: #{e.message}"
209
+ sleep 2
210
+ end
211
+ ```
212
+
213
+ - The server closes each stream after up to 30 minutes. `stream` then returns normally, and the loop reconnects at once.
214
+ - A 401 or 403 stops the loop, because reconnecting can't fix a rejected key or a missing scope.
215
+ - Any other failure raises a `Synthient::Error`, and the loop waits 2 seconds before reconnecting.
216
+ - Events sent while disconnected are missed. The API has no resume cursor.
217
+
218
+ Without a block, `stream` returns an `Enumerator` that connects when you iterate it.
219
+
220
+ ## Pagination
221
+
222
+ `list_exports` returns one page of a feed's exports, newest first. Pass `page.next_cursor` as `cursor:` to get the next page; it is nil on the last one.
223
+
224
+ ```ruby
225
+ page = client.proxies.list_exports(limit: 50)
226
+ page.exports.each do |export|
227
+ puts "#{export.id} #{export.kind} #{export.row_count}"
228
+ end
229
+ ```
230
+
231
+ `each_export` fetches the pages for you as the block needs them:
232
+
233
+ ```ruby
234
+ client.proxies.each_export do |export|
235
+ puts "#{export.id} #{export.kind} #{export.row_count}"
236
+ end
237
+ ```
238
+
239
+ Without a block, it returns an `Enumerator`, so `client.proxies.each_export.first(10)` fetches only the pages it needs.
240
+
241
+ On the first page, the newest hourly export has the ID `"latest"`, a moving alias for the freshest export. Its `date` and `hour` give its stable ID, such as `"2026-10-14/21"`.
242
+
243
+ ## Downloads
244
+
245
+ Exports are Parquet files. `download` yields a file's bytes in chunks as they arrive:
246
+
247
+ ```ruby
248
+ File.open("proxies.parquet", "wb") do |file|
249
+ client.proxies.download("latest") { |chunk| file.write(chunk) }
250
+ end
251
+ ```
252
+
253
+ - Name an export by its `id` from a listing, by `"latest"`, or by a `Date` or `Time` for a UTC day or hour.
254
+ - `export_meta` returns the file's SHA-256 `checksum`. Use a fixed ID for both calls, because `"latest"` can move between them.
255
+ - `download_url` returns a presigned URL that works without a key for 24 hours, so treat it as a secret. Your API key is never sent to the storage host.
256
+ - Hourly exports roll into the daily export shortly after 00:30 UTC the next day. After that, a request for the hour raises a 400.
257
+
258
+ ## Retries
259
+
260
+ The client retries a failed request up to twice, backing off exponentially with jitter and honoring `Retry-After`:
261
+
262
+ | Requests | Retried on |
263
+ | --------------------------- | -------------------------------------------------------------------------------------------- |
264
+ | Account and feed requests | 500, 502, 503, and 504, most network failures, and 429 with `Retry-After` |
265
+ | Billed lookups and `health` | Only 429 with `Retry-After`, which comes before any work, so a lookup is never charged twice |
266
+
267
+ A 429 without `Retry-After` means the monthly request budget is spent or too many streams are open, so it is raised at once. Downloads from the storage host are never retried.
268
+
269
+ Set the number of retries with `max_retries:`. Zero disables them:
270
+
271
+ ```ruby
272
+ client = Synthient::Client.new(max_retries: 4)
273
+ ```
274
+
275
+ ## Timeouts
276
+
277
+ The client sets no overall timeout, because streams and downloads are long-lived. Instead, `timeout:` limits each read or write, 60 seconds by default, and `open_timeout:` limits connecting, 10 seconds by default:
278
+
279
+ ```ruby
280
+ client = Synthient::Client.new(timeout: 30, open_timeout: 5)
281
+ ```
282
+
283
+ The server sends a blank keepalive line on a quiet stream about every 15 seconds, so keep `timeout:` above that. Running out of time raises `Synthient::TimeoutError`.
284
+
285
+ ## Error Handling
286
+
287
+ A request that fails with an error status raises a [`Synthient::APIError`](https://rubydoc.info/gems/synthient/Synthient/APIError):
288
+
289
+ | Attribute | Type | Description |
290
+ | ------------- | ----------------------------- | -------------------------------------------- |
291
+ | `status` | `Integer` | HTTP status code, such as `404` |
292
+ | `type` | `String?` | URI identifying the problem type |
293
+ | `title` | `String?` | Short summary of the problem type |
294
+ | `detail` | `String?` | Explanation of this occurrence |
295
+ | `errors` | `Hash[String, Array[String]]` | Validation messages by request field |
296
+ | `request_id` | `String?` | Request ID to give Synthient support |
297
+ | `retry_after` | `Numeric?` | Seconds the server asked you to wait, or nil |
298
+
299
+ Its `message` holds only the HTTP status, so it is safe to log. The attributes hold untrusted server data.
300
+
301
+ ### Example
302
+
303
+ ```ruby
304
+ begin
305
+ client.lookup_ip("8.8.8.8")
306
+ rescue Synthient::APIError => e
307
+ case e.status
308
+ when 402
309
+ puts "out of lookup credits"
310
+ when 429
311
+ puts e.retry_after ? "rate limited, retry after #{e.retry_after}s" : "monthly request budget spent"
312
+ else
313
+ puts "request #{e.request_id} failed: #{e.detail || e.title}"
314
+ end
315
+ end
316
+ ```
317
+
318
+ ### Error Types
319
+
320
+ - [`Synthient::Error`](https://rubydoc.info/gems/synthient/Synthient/Error): the base class of every error the SDK raises for a failed request.
321
+ - [`Synthient::APIError`](https://rubydoc.info/gems/synthient/Synthient/APIError): the API, or the storage host during `download`, returned an error status.
322
+ - [`Synthient::ConnectionError`](https://rubydoc.info/gems/synthient/Synthient/ConnectionError): the request couldn't be sent or the response couldn't be read.
323
+ - [`Synthient::TimeoutError`](https://rubydoc.info/gems/synthient/Synthient/TimeoutError): a `ConnectionError` for a connect, read, or write that ran out of time.
324
+ - [`Synthient::DecodeError`](https://rubydoc.info/gems/synthient/Synthient/DecodeError): a successful response didn't match the API schema.
325
+ - `ArgumentError` and `TypeError`: invalid arguments, such as a missing API key, raised before any request is sent.
326
+ - `IOError`: the client was used after `close`.
327
+
328
+ <details><summary>Status codes</summary>
329
+
330
+ <br />
331
+
332
+ | Status | Meaning |
333
+ | ------ | ------------------------------------------------------------------------------------------------ |
334
+ | 400 | The request is invalid, such as an hourly export that was rolled up |
335
+ | 401 | The API key is malformed, unknown, or revoked |
336
+ | 402 | The team is out of lookup credits |
337
+ | 403 | The key lacks the scope for the endpoint or feed |
338
+ | 404 | The export doesn't exist, or a daily export is still rolling up (`retry_after` is set) |
339
+ | 422 | The input is invalid, such as a private address or a malformed domain |
340
+ | 429 | Rate limited if `retry_after` is set; otherwise the budget is spent or too many streams are open |
341
+ | 5xx | The server failed |
342
+
343
+ </details>
344
+
345
+ ## Server Selection
346
+
347
+ ### Override Server URL Per-Client
348
+
349
+ The default server is `https://api.synthient.com/api/v4`. Use `base_url:` to send requests elsewhere, such as a mock server in tests:
350
+
351
+ ```ruby
352
+ client = Synthient::Client.new(base_url: "http://localhost:8080/api/v4")
353
+ ```
354
+
355
+ ## Custom HTTP Client
356
+
357
+ The client uses Ruby's `Net::HTTP` and doesn't accept a replacement. To use a proxy, set `http_proxy`:
358
+
359
+ ```sh
360
+ export http_proxy=http://proxy.example.com:8080
361
+ ```
362
+
363
+ - `Net::HTTP` uses `http_proxy` for HTTPS requests too and ignores `https_proxy`. `no_proxy` exempts hosts.
364
+ - Export downloads from storage go through the same proxy.
365
+ - `Net::HTTP`'s own retry is off, so a stale keep-alive connection never resends a billed lookup.
366
+
367
+ `user_agent: "my-app/1.2"` adds your product token to the `User-Agent` header.
368
+
369
+ ## Debugging
370
+
371
+ `response_hook:` takes any callable and calls it after every API response, including retries, pages, and stream handshakes, with a `Synthient::ResponseMetadata` holding the status, request ID, rate limit, and headers:
372
+
373
+ ```ruby
374
+ client = Synthient::Client.new(
375
+ response_hook: lambda do |meta|
376
+ warn "status=#{meta.status} request_id=#{meta.request_id}"
377
+ limit = meta.rate_limit
378
+ warn "rate limit: #{limit.remaining} of #{limit.limit} left" if limit
379
+ end
380
+ )
381
+ ```
382
+
383
+ The hook runs on the thread that made the request, and exceptions it raises propagate to that call.
384
+
385
+ > [!WARNING]
386
+ > Response headers can contain secrets, such as presigned download URLs. Avoid logging `meta.headers` in production.
387
+
388
+ ## gRPC Schema
389
+
390
+ [`Synthient::GRPCSchema`](https://rubydoc.info/gems/synthient/Synthient/GRPCSchema) fetches the protobuf schema of the [Synthient gRPC API](https://docs.synthient.com/grpc) through server reflection:
391
+
392
+ ```ruby
393
+ require "synthient/grpcschema"
394
+
395
+ begin
396
+ schema = Synthient::GRPCSchema.fetch # reads SYNTHIENT_API_KEY
397
+ rescue Synthient::GRPCSchema::SchemaError => e
398
+ explanation = Synthient::GRPCSchema.explain(e)
399
+ abort explanation ? "#{explanation} #{e.message}" : e.message
400
+ end
401
+ schema.descriptor_set.file.each do |file|
402
+ puts "#{file.name} #{file.package}"
403
+ end
404
+ ```
405
+
406
+ `schema.descriptor_set` is a `Google::Protobuf::FileDescriptorSet`. `explain` describes common gRPC errors in plain language.
407
+
408
+ # Development
409
+
410
+ ## Maturity
411
+
412
+ This SDK follows [Semantic Versioning](https://semver.org). Breaking changes ship only in a new major version, so a constraint such as `gem "synthient", "~> 1.0"` never picks them up.
413
+
414
+ ## Contributions
415
+
416
+ Bug reports and feature requests are welcome as [GitHub issues](https://github.com/synthient/synthient-ruby/issues). For questions about the API or your account, contact [Synthient support](https://docs.synthient.com/misc/support).
417
+
418
+ ## License
419
+
420
+ [Apache 2.0](https://github.com/synthient/synthient-ruby/blob/main/LICENSE)