Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥
TypeScript aiai-agentsai-crawlerai-scrapingai-searchcrawlerdata-extractionhtml-to-markdownllmmarkdownscraperscrapingweb-crawlerweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
fix(sdks): match the Alexandria client timeout to the API's 120 s cap (#4995)
claude[bot]9ae2451b39dd
diff --git a/apps/go-sdk/tools.go b/apps/go-sdk/tools.goindex 632349ff9..c3b03d1ad 100644--- a/apps/go-sdk/tools.go+++ b/apps/go-sdk/tools.go@@ -22,6 +22,22 @@ func (e *AlexandriaExecutionError) Error() string {}func (e *AlexandriaExecutionError) Unwrap() error { return e.Err }+const (+ // alexandriaMaxTimeoutMs matches the API's default and maximum execution timeout.+ alexandriaMaxTimeoutMs = 120_000+ // alexandriaResponseMarginMs gives the API time to deliver a response after its execution deadline.+ alexandriaResponseMarginMs = 30_000+)++// alexandriaTransportTimeout returns how long the client waits for an Alexandria response.+func alexandriaTransportTimeout(timeout *int) time.Duration {+ executionMs := alexandriaMaxTimeoutMs+ if timeout != nil && *timeout < alexandriaMaxTimeoutMs {+ executionMs = *timeout+ }+ return time.Duration(executionMs+alexandriaResponseMarginMs) * time.Millisecond+}+func (c *Client) ScrapeAlexandria(ctx context.Context, calls []AlexandriaCall, opts *AlexandriaOptions) (*AlexandriaScrapeData, error) {if len(calls) == 0 {return nil, &FirecrawlError{Message: "at least one alexandria call is required"}@@ -37,14 +53,16 @@ func (c *Client) ScrapeAlexandria(ctx context.Context, calls []AlexandriaCall, oreturn nil, &FirecrawlError{Message: fmt.Sprintf("alexandria call %d: capability is required", i)}}}+ var timeout *intif opts != nil && opts.Timeout != nil {if *opts.Timeout <= 0 {return nil, &FirecrawlError{Message: "timeout must be positive"}}- var cancel context.CancelFunc- ctx, cancel = context.WithTimeout(ctx, time.Duration(*opts.Timeout+5000)*time.Millisecond)- defer cancel()+ timeout = opts.Timeout}+ // Allow response delivery after the API's capped execution deadline.+ ctx, cancel := context.WithTimeout(ctx, alexandriaTransportTimeout(timeout))+ defer cancel()body := map[string]interface{}{"alexandria": calls}mergeOptions(body, opts)diff --git a/apps/go-sdk/tools_test.go b/apps/go-sdk/tools_test.goindex b7a2a4df1..ef4456e1d 100644--- a/apps/go-sdk/tools_test.go+++ b/apps/go-sdk/tools_test.go@@ -8,6 +8,7 @@ import ("net/http/httptest""sync/atomic""testing"+ "time""github.com/firecrawl/firecrawl/apps/go-sdk/option")@@ -97,3 +98,23 @@ func TestToolDiscoveryAndExecution(t *testing.T) {t.Fatal("requestId leaked into body")}}++func TestAlexandriaTransportTimeout(t *testing.T) {+ ms := func(v int) *int { return &v }+ cases := []struct {+ name string+ timeout *int+ want time.Duration+ }{+ {"default", nil, 150 * time.Second},+ {"1000", ms(1000), 31 * time.Second},+ {"100000", ms(100000), 130 * time.Second},+ {"120000", ms(120000), 150 * time.Second},+ {"300000", ms(300000), 150 * time.Second},+ }+ for _, tc := range cases {+ if got := alexandriaTransportTimeout(tc.timeout); got != tc.want {+ t.Errorf("timeout %s: got %v, want %v", tc.name, got, tc.want)+ }+ }+}diff --git a/apps/go-sdk/version.go b/apps/go-sdk/version.goindex 658df228e..055066e76 100644--- a/apps/go-sdk/version.go+++ b/apps/go-sdk/version.go@@ -9,4 +9,4 @@ package firecrawl// Bump this when preparing a new release. The publish-go-sdk GitHub workflow// reads this value and creates the corresponding monorepo-prefixed tag on// merge to main.-const Version = "1.16.3"+const Version = "1.16.4"diff --git a/apps/js-sdk/firecrawl/package.json b/apps/js-sdk/firecrawl/package.jsonindex ad0224835..ba1780a84 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.44.0",+ "version": "4.44.1","description": "JavaScript SDK for the Firecrawl API: web scraping, crawling, web search, and scientific literature search over a research paper index of PubMed, bioRxiv, medRxiv and arXiv abstracts","main": "dist/index.js","types": "dist/index.d.ts",diff --git a/apps/js-sdk/firecrawl/src/__tests__/unit/v2/tools.unit.test.ts b/apps/js-sdk/firecrawl/src/__tests__/unit/v2/tools.unit.test.tsindex 9daed1b64..75c883a95 100644--- a/apps/js-sdk/firecrawl/src/__tests__/unit/v2/tools.unit.test.ts+++ b/apps/js-sdk/firecrawl/src/__tests__/unit/v2/tools.unit.test.ts@@ -272,9 +272,11 @@ describe("Alexandria contracts and execution", () => {});test.each([- [undefined, 80000],+ [undefined, 150000],[1000, 31000],- [100000, 80000],+ [100000, 130000],+ [120000, 150000],+ [300000, 150000],])("Alexandria timeout %s allows response delivery (%s ms)",async (timeout, timeoutMs) => {diff --git a/apps/js-sdk/firecrawl/src/v2/methods/tools.ts b/apps/js-sdk/firecrawl/src/v2/methods/tools.tsindex 1ec3c0517..2b8db534c 100644--- a/apps/js-sdk/firecrawl/src/v2/methods/tools.ts+++ b/apps/js-sdk/firecrawl/src/v2/methods/tools.ts@@ -14,6 +14,10 @@ import {} from "../utils/errorHandler";const ALEXANDRIA_MAX_CALLS = 10;+// Matches the API's default and maximum execution timeout for Alexandria calls.+const ALEXANDRIA_MAX_TIMEOUT_MS = 120_000;+// Extra time for the API to deliver a response after its execution deadline.+const ALEXANDRIA_RESPONSE_MARGIN_MS = 30_000;function prepareAlexandriaPayload(calls: AlexandriaCall[],@@ -82,7 +86,11 @@ export async function scrapeAlexandria(}>("/v2/scrape", payload, {headers: { "x-request-id": requestId },// Allow response delivery after the API's capped execution deadline.- timeoutMs: Math.min(opts.timeout ?? 50000, 50000) + 30000,+ timeoutMs:+ Math.min(+ opts.timeout ?? ALEXANDRIA_MAX_TIMEOUT_MS,+ ALEXANDRIA_MAX_TIMEOUT_MS,+ ) + ALEXANDRIA_RESPONSE_MARGIN_MS,});if (res.status !== 200 || !res.data?.success) {throwForBadResponse(res, "alexandria");diff --git a/apps/python-sdk/firecrawl/__init__.py b/apps/python-sdk/firecrawl/__init__.pyindex 2f84e0dab..e8afdf168 100644--- a/apps/python-sdk/firecrawl/__init__.py+++ b/apps/python-sdk/firecrawl/__init__.py@@ -41,7 +41,7 @@ from .v1 import (V1ChangeTrackingOptions,)-__version__ = "4.49.1"+__version__ = "4.49.2"# Define the logger for the Firecrawl projectlogger: logging.Logger = logging.getLogger("firecrawl")diff --git a/apps/python-sdk/firecrawl/__tests__/unit/v2/methods/test_tools.py b/apps/python-sdk/firecrawl/__tests__/unit/v2/methods/test_tools.pyindex 2627a05f3..9ee463949 100644--- a/apps/python-sdk/firecrawl/__tests__/unit/v2/methods/test_tools.py+++ b/apps/python-sdk/firecrawl/__tests__/unit/v2/methods/test_tools.py@@ -194,7 +194,10 @@ def test_alexandria_call_boundaries_and_result_errors(count):@pytest.mark.parametrize("async_client", [False, True])[email protected]("timeout, expected", [(None, 80), (1000, 31), (100000, 80)])+ "timeout, expected",+ [(None, 150), (1000, 31), (100000, 130), (120000, 150), (300000, 150)],+)@pytest.mark.asyncioasync def test_alexandria_transport_timeout(async_client, timeout, expected):from unittest.mock import AsyncMockdiff --git a/apps/python-sdk/firecrawl/v2/methods/aio/scrape.py b/apps/python-sdk/firecrawl/v2/methods/aio/scrape.pyindex 93ce9fcde..f904b9817 100644--- a/apps/python-sdk/firecrawl/v2/methods/aio/scrape.py+++ b/apps/python-sdk/firecrawl/v2/methods/aio/scrape.py@@ -8,7 +8,12 @@ from ...types import (AlexandriaCall,AlexandriaScrapeData,)-from ..scrape import _alexandria_request_id, _prepare_scrape_alexandria_request, _parse_scrape_alexandria_response+from ..scrape import (+ _alexandria_request_id,+ _alexandria_transport_timeout,+ _prepare_scrape_alexandria_request,+ _parse_scrape_alexandria_response,+)from ...utils.agent_hints import agent_hint_metadatafrom ...utils.normalize import normalize_document_inputfrom ...utils.error_handler import FirecrawlError, handle_response_error@@ -66,7 +71,7 @@ async def scrape_alexandria(client: AsyncHttpClient, calls, *, timeout: Optionalheaders = {"x-request-id": request_id}try:response = await client.post("/v2/scrape", payload, headers=headers,- timeout=(min(timeout if timeout is not None else 50000, 50000) + 30000) / 1000)+ timeout=_alexandria_transport_timeout(timeout))if response.status_code != 200 or not response.json().get("success"):handle_response_error(response, "scrape alexandria")return _parse_scrape_alexandria_response(response.json(), request_id)diff --git a/apps/python-sdk/firecrawl/v2/methods/scrape.py b/apps/python-sdk/firecrawl/v2/methods/scrape.pyindex 3ab83a66b..ecd7e9261 100644--- a/apps/python-sdk/firecrawl/v2/methods/scrape.py+++ b/apps/python-sdk/firecrawl/v2/methods/scrape.py@@ -95,6 +95,10 @@ def scrape(MAX_ALEXANDRIA_CALLS = 10+# Matches the API's default and maximum execution timeout for Alexandria calls.+MAX_ALEXANDRIA_TIMEOUT_MS = 120_000+# Extra time for the API to deliver a response after its execution deadline.+ALEXANDRIA_RESPONSE_MARGIN_MS = 30_000def _prepare_scrape_alexandria_request(@@ -153,6 +157,12 @@ def _alexandria_request_id(request_id: Optional[str]) -> str:return value+def _alexandria_transport_timeout(timeout: Optional[int]) -> float:+ """Return the HTTP timeout in seconds for an Alexandria request."""+ execution_ms = min(timeout if timeout is not None else MAX_ALEXANDRIA_TIMEOUT_MS, MAX_ALEXANDRIA_TIMEOUT_MS)+ return (execution_ms + ALEXANDRIA_RESPONSE_MARGIN_MS) / 1000++def scrape_alexandria(client: HttpClient, calls, *, timeout: Optional[int] = None,integration: Optional[str] = None, request_id: Optional[str] = None) -> AlexandriaScrapeData:payload = _prepare_scrape_alexandria_request(calls, timeout=timeout, integration=integration)@@ -160,7 +170,7 @@ def scrape_alexandria(client: HttpClient, calls, *, timeout: Optional[int] = Nonheaders = {**client._prepare_headers(), "x-request-id": request_id}try:response = client.post("/v2/scrape", payload, headers=headers,- timeout=(min(timeout if timeout is not None else 50000, 50000) + 30000) / 1000)+ timeout=_alexandria_transport_timeout(timeout))if response.status_code != 200 or not response.json().get("success"):handle_response_error(response, "scrape alexandria")return _parse_scrape_alexandria_response(response.json(), request_id)diff --git a/apps/rust-sdk/CHANGELOG.md b/apps/rust-sdk/CHANGELOG.mdindex 9d1d84931..abf5e2a47 100644--- a/apps/rust-sdk/CHANGELOG.md+++ b/apps/rust-sdk/CHANGELOG.md@@ -1,5 +1,14 @@## CHANGELOG+## [2.21.4] - 2026-10-07++### Fixed++- `scrape_alexandria` now waits for the API's full execution deadline. The+ execution timeout defaults to and is capped at 120 s, the same as the API,+ plus a 30 s margin for response delivery (150 s when no `timeout` is given).+ Before, it used no timeout by default, or the caller's `timeout` plus 5 s.+## [2.21.3] - 2026-10-06### Addeddiff --git a/apps/rust-sdk/Cargo.lock b/apps/rust-sdk/Cargo.lockindex 06631529b..29328766e 100644--- a/apps/rust-sdk/Cargo.lock+++ b/apps/rust-sdk/Cargo.lock@@ -250,7 +250,7 @@ checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"[[package]]name = "firecrawl"-version = "2.21.3"+version = "2.21.4"dependencies = ["mockito","reqwest",diff --git a/apps/rust-sdk/Cargo.toml b/apps/rust-sdk/Cargo.tomlindex abb196d44..ef8b27f3f 100644--- a/apps/rust-sdk/Cargo.toml+++ b/apps/rust-sdk/Cargo.toml@@ -1,6 +1,6 @@[package]name = "firecrawl"-version = "2.21.3"+version = "2.21.4"edition = "2021"license = "MIT"homepage = "https://www.firecrawl.dev/"diff --git a/apps/rust-sdk/src/scrape.rs b/apps/rust-sdk/src/scrape.rsindex 05891a660..a467db2f6 100644--- a/apps/rust-sdk/src/scrape.rs+++ b/apps/rust-sdk/src/scrape.rs@@ -174,6 +174,19 @@ pub struct AlexandriaOptions {pub origin: Option<String>,}+/// Matches the API's default and maximum execution timeout for Alexandria calls.+const ALEXANDRIA_MAX_TIMEOUT_MS: u32 = 120_000;+/// Extra time for the API to deliver a response after its execution deadline.+const ALEXANDRIA_RESPONSE_MARGIN_MS: u64 = 30_000;++/// Returns how long the client waits for an Alexandria response.+fn alexandria_transport_timeout(timeout: Option<u32>) -> std::time::Duration {+ let execution_ms = timeout+ .unwrap_or(ALEXANDRIA_MAX_TIMEOUT_MS)+ .min(ALEXANDRIA_MAX_TIMEOUT_MS);+ std::time::Duration::from_millis(u64::from(execution_ms) + ALEXANDRIA_RESPONSE_MARGIN_MS)+}+#[derive(Serialize, Debug)]#[serde(rename_all = "camelCase")]struct AlexandriaRequest {@@ -409,9 +422,8 @@ impl Client {if options.origin.is_none() {options.origin = Some(format!("rust-sdk@{}", env!("CARGO_PKG_VERSION")));}- let request_timeout = options- .timeout- .map(|ms| std::time::Duration::from_millis(u64::from(ms) + 5000));+ // Allow response delivery after the API's capped execution deadline.+ let request_timeout = alexandria_transport_timeout(options.timeout);let request_id = options.request_id.clone()@@ -431,16 +443,13 @@ impl Client {let headers = self.prepare_headers(None);- let mut request = self+ let response = self.client.post(self.url("/scrape")).headers(headers).header("x-request-id", &request_id)- .json(&body);- if let Some(timeout) = request_timeout {- request = request.timeout(timeout);- }- let response = request+ .json(&body)+ .timeout(request_timeout).send().await.map_err(|e| FirecrawlError::AlexandriaExecution {@@ -645,6 +654,23 @@ mod tests {use crate::{HighlightsFormat, QueryFormat, QueryFormatMode, QuestionFormat};use serde_json::json;+ #[test]+ fn test_alexandria_transport_timeout() {+ for (timeout, expected_secs) in [+ (None, 150),+ (Some(1_000), 31),+ (Some(100_000), 130),+ (Some(120_000), 150),+ (Some(300_000), 150),+ ] {+ assert_eq!(+ alexandria_transport_timeout(timeout),+ std::time::Duration::from_secs(expected_secs),+ "timeout {timeout:?}"+ );+ }+ }+#[test]fn test_query_format_serializes_mode() {let options = ScrapeOptions {