Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

js-sdk: require API key only for cloud API (not self-hosted) (#2237)

Abimael Martell198602a09265
diff --git a/apps/js-sdk/firecrawl/package.json b/apps/js-sdk/firecrawl/package.json
index 866315f5f..f6a3fc6f7 100644
--- a/apps/js-sdk/firecrawl/package.json
+++ b/apps/js-sdk/firecrawl/package.json
@@ -1,6 +1,6 @@
{
"name": "@mendable/firecrawl-js",
- "version": "4.4.0",
+ "version": "4.4.1",
"description": "JavaScript SDK for Firecrawl API",
"main": "dist/index.js",
"types": "dist/index.d.ts",
diff --git a/apps/js-sdk/firecrawl/src/v2/client.ts b/apps/js-sdk/firecrawl/src/v2/client.ts
index 840c38be6..15bd6f78c 100644
--- a/apps/js-sdk/firecrawl/src/v2/client.ts
+++ b/apps/js-sdk/firecrawl/src/v2/client.ts
@@ -72,9 +72,14 @@ export interface FirecrawlClientOptions {
/**
* Firecrawl v2 client. Provides typed access to all v2 endpoints and utilities.
*/
+
export class FirecrawlClient {
private readonly http: HttpClient;
+ private isCloudService(url: string): boolean {
+ return url.includes('api.firecrawl.dev');
+ }
+
/**
* Create a v2 client.
* @param options Transport configuration (API key, base URL, timeouts, retries).
@@ -82,9 +87,11 @@ export class FirecrawlClient {
constructor(options: FirecrawlClientOptions = {}) {
const apiKey = options.apiKey ?? process.env.FIRECRAWL_API_KEY ?? "";
const apiUrl = (options.apiUrl ?? process.env.FIRECRAWL_API_URL ?? "https://api.firecrawl.dev").replace(/\/$/, "");
- if (!apiKey) {
- throw new Error("API key is required. Set FIRECRAWL_API_KEY env or pass apiKey.");
+
+ if (this.isCloudService(apiUrl) && !apiKey) {
+ throw new Error("API key is required for the cloud API. Set FIRECRAWL_API_KEY env or pass apiKey.");
}
+
this.http = new HttpClient({
apiKey,
apiUrl,