File tree 4 files changed +49
-4
lines changed
4 files changed +49
-4
lines changed Original file line number Diff line number Diff line change @@ -116,6 +116,10 @@ If you’d like to test the crawl endpoint, you can run this:
116
116
117
117
This section provides solutions to common issues you might encounter while setting up or running your self-hosted instance of Firecrawl.
118
118
119
+ ### API Keys for SDK Usage
120
+
121
+ ** Note:** When using Firecrawl SDKs with a self-hosted instance, API keys are optional. API keys are only required when connecting to the cloud service (api.firecrawl.dev).
122
+
119
123
### Supabase client is not configured
120
124
121
125
** Symptom:**
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ use crate::crawl::CrawlStatus;
9
9
#[ derive( Debug , Deserialize , Serialize , Clone ) ]
10
10
pub struct FirecrawlAPIError {
11
11
/// Always false.
12
- success : bool ,
12
+ pub success : bool ,
13
13
14
14
/// Error message
15
15
pub error : String ,
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ pub mod map;
9
9
pub mod scrape;
10
10
11
11
pub use error:: FirecrawlError ;
12
+ use error:: FirecrawlAPIError ;
12
13
13
14
#[ derive( Clone , Debug ) ]
14
15
pub struct FirecrawlApp {
@@ -18,16 +19,30 @@ pub struct FirecrawlApp {
18
19
}
19
20
20
21
pub ( crate ) const API_VERSION : & str = "/v1" ;
22
+ const CLOUD_API_URL : & str = "https://api.firecrawl.dev" ;
21
23
22
24
impl FirecrawlApp {
23
25
pub fn new ( api_key : impl AsRef < str > ) -> Result < Self , FirecrawlError > {
24
- FirecrawlApp :: new_selfhosted ( "https://api.firecrawl.dev" , Some ( api_key) )
26
+ FirecrawlApp :: new_selfhosted ( CLOUD_API_URL , Some ( api_key) )
25
27
}
26
28
27
29
pub fn new_selfhosted ( api_url : impl AsRef < str > , api_key : Option < impl AsRef < str > > ) -> Result < Self , FirecrawlError > {
30
+ let url = api_url. as_ref ( ) . to_string ( ) ;
31
+
32
+ if url == CLOUD_API_URL && api_key. is_none ( ) {
33
+ return Err ( FirecrawlError :: APIError (
34
+ "Configuration" . to_string ( ) ,
35
+ FirecrawlAPIError {
36
+ success : false ,
37
+ error : "API key is required for cloud service" . to_string ( ) ,
38
+ details : None ,
39
+ }
40
+ ) ) ;
41
+ }
42
+
28
43
Ok ( FirecrawlApp {
29
44
api_key : api_key. map ( |x| x. as_ref ( ) . to_string ( ) ) ,
30
- api_url : api_url . as_ref ( ) . to_string ( ) ,
45
+ api_url : url ,
31
46
client : Client :: new ( ) ,
32
47
} )
33
48
}
Original file line number Diff line number Diff line change 1
1
use assert_matches:: assert_matches;
2
2
use dotenvy:: dotenv;
3
3
use firecrawl:: scrape:: { ExtractOptions , ScrapeFormats , ScrapeOptions } ;
4
- use firecrawl:: FirecrawlApp ;
4
+ use firecrawl:: { FirecrawlApp , FirecrawlError } ;
5
5
use serde_json:: json;
6
6
use std:: env;
7
7
@@ -155,3 +155,29 @@ async fn test_llm_extraction() {
155
155
assert ! ( llm_extraction[ "supports_sso" ] . is_boolean( ) ) ;
156
156
assert ! ( llm_extraction[ "is_open_source" ] . is_boolean( ) ) ;
157
157
}
158
+
159
+ #[ test]
160
+ fn test_api_key_requirements ( ) {
161
+ dotenv ( ) . ok ( ) ;
162
+
163
+ let api_url = env:: var ( "API_URL" ) . unwrap_or ( "http://localhost:3002" . to_string ( ) ) ;
164
+ let api_key = env:: var ( "TEST_API_KEY" ) . ok ( ) ;
165
+
166
+ match ( api_url. contains ( "api.firecrawl.dev" ) , api_key) {
167
+ ( false , _) => {
168
+ let result = FirecrawlApp :: new_selfhosted ( & api_url, None :: < String > ) ;
169
+ assert ! ( result. is_ok( ) , "Local setup failed: {:?}" , result. err( ) . unwrap( ) ) ;
170
+ }
171
+ ( true , None ) => {
172
+ let result = FirecrawlApp :: new_selfhosted ( & api_url, None :: < String > ) ;
173
+ assert ! ( matches!(
174
+ result,
175
+ Err ( FirecrawlError :: APIError ( msg, _) ) if msg == "Configuration"
176
+ ) ) ;
177
+ }
178
+ ( true , Some ( key) ) => {
179
+ let result = FirecrawlApp :: new_selfhosted ( & api_url, Some ( & key) ) ;
180
+ assert ! ( result. is_ok( ) ) ;
181
+ }
182
+ }
183
+ }
You can’t perform that action at this time.
0 commit comments