1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//! Official Rust SDK for the [webscrape.ai](https://webscrape.ai) API.
//!
//! Covers the public API-key surface: [`Client::scrape`], [`Client::smartscraper`],
//! and the [`SmartBrowse`] namespace (dispatch a recipe run, poll it, wait for
//! completion, read usage). See <https://webscrape.ai/docs> for API docs.
//!
//! # Quick start
//!
//! ```no_run
//! # async fn run() -> Result<(), webscrape_ai::Error> {
//! use webscrape_ai::{Client, ScrapeRequest};
//!
//! // Reads WEBSCRAPE_API_KEY from the environment.
//! let client = Client::from_env()?;
//!
//! let resp = client
//! .scrape(ScrapeRequest::new("https://example.com").clean(true))
//! .await?;
//!
//! println!("credits used: {:?}", resp.credits_used);
//! println!("markdown: {:?}", resp.data.html);
//! # Ok(()) }
//! ```
//!
//! # Structured extraction
//!
//! ```no_run
//! # async fn run() -> Result<(), webscrape_ai::Error> {
//! use webscrape_ai::{Client, SmartScraperRequest};
//! use serde_json::json;
//!
//! let client = Client::new("wsg_live_...")?;
//! let resp = client
//! .smartscraper(
//! SmartScraperRequest::new(
//! "https://news.ycombinator.com",
//! "Extract the front-page stories with title, url, and score.",
//! )
//! .output_schema(json!({
//! "type": "object",
//! "properties": { "stories": { "type": "array" } }
//! })),
//! )
//! .await?;
//!
//! // `data.result` is a serde_json::Value; decode it into your own type.
//! let value = resp.data.result;
//! println!("{value:?}");
//! # Ok(()) }
//! ```
//!
//! # Error handling
//!
//! Every method returns [`Result<T>`](crate::Result). Failures surface as
//! [`Error`], which distinguishes API errors ([`Error::Api`] carrying an
//! [`ApiError`] you branch on via [`ApiError::kind`]) from transport, timeout,
//! and wait-helper failures.
// `Error` intentionally carries rich payloads (`ApiError`, and a full
// `SmartBrowseRun` in `RunFailed`/`WaitTimeout`) so callers can inspect the
// terminal run without a second request. That makes the enum large; boxing would
// change the public contract, so we accept the size rather than deviate.
pub use ;
pub use ;
pub use ;
pub use ;
/// Default production base URL (`https://api.webscrape.ai/v1`).
pub const DEFAULT_BASE_URL: &str = "https://api.webscrape.ai/v1";
/// Environment variable consulted for the API key when none is passed explicitly.
pub const API_KEY_ENV: &str = "WEBSCRAPE_API_KEY";
/// SDK version, sourced from `CARGO_PKG_VERSION` and used in the `User-Agent`.
pub const VERSION: &str = env!;
/// `User-Agent` sent on every request, e.g. `webscrape-ai-rust/0.1.0`.
pub