From 873635d6f1acd44a48868f4a769eb97544ab011f Mon Sep 17 00:00:00 2001 From: Babyy-dev Date: Fri, 20 Nov 2026 09:29:16 +0530 Subject: [PATCH] Raise default timeout above the 90s server-side timeout --- CHANGELOG.md | 2 ++ README.md | 7 ++++--- src/config.ts | 2 +- tests/validators_test.ts | 11 ++++++++++- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81122eb..d11e239 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,8 @@ and this project adheres to - Remove `settings.json`, update CONTRIBUTING.md. - Make types more lenient so newly supported engines/parameters whose types have not yet been updated do not throw warnings. +- Raise the default `timeout` from 60 to 95 seconds, so slow searches are not + cut off before SerpApi's 90 second server-side timeout. ### Fixed diff --git a/README.md b/README.md index d78da2b..c359a9e 100644 --- a/README.md +++ b/README.md @@ -187,14 +187,15 @@ request to SerpApi includes fetching the page: const page = await extract({ url: "https://example.com/", fetch_timeout: 10000, // sent to the Extract API as `timeout` - timeout: 60000, // request timeout of this library + timeout: 95000, // request timeout of this library }); ``` ## Configuration You can declare a global `api_key` and `timeout` value by modifying the `config` -object. `timeout` is defined in milliseconds and defaults to 60 seconds. +object. `timeout` is defined in milliseconds and defaults to 95 seconds, a bit +longer than SerpApi's 90 second server-side timeout. All functions, other than `getLocations`, accepts an optional `api_key` and `timeout` that will take precedence over the values defined in `config`. @@ -205,7 +206,7 @@ All functions, other than `getLocations`, accepts an optional `api_key` and import { config, getJson } from "serpapi"; config.api_key = API_KEY; -config.timeout = 60000; +config.timeout = 95000; await getJson({ engine: "google", q: "coffee" }); // uses the API key defined in the config await getJson({ engine: "google", api_key: API_KEY_2, q: "coffee" }); // API_KEY_2 will be used diff --git a/src/config.ts b/src/config.ts index 386b7ea..66ceca8 100644 --- a/src/config.ts +++ b/src/config.ts @@ -8,5 +8,5 @@ export type Config = { export const config: Config = { api_key: null, - timeout: 60000, + timeout: 95000, }; diff --git a/tests/validators_test.ts b/tests/validators_test.ts index 770ebfa..84ca6c7 100644 --- a/tests/validators_test.ts +++ b/tests/validators_test.ts @@ -63,8 +63,17 @@ describe("validateApiKey", () => { }); describe("validateTimeout", () => { + const defaultTimeout = config.timeout; + afterEach(() => { - config.timeout = 60000; + config.timeout = defaultTimeout; + }); + + it("with default timeout", () => { + // SerpApi times out searches after 90 seconds on its side, so the + // default must wait longer than that. + assertEquals(defaultTimeout > 90000, true); + assertEquals(validateTimeout(undefined), defaultTimeout); }); it("with invalid timeout", () => {