Skip to content

Commit 2eba148

Browse files
fix: update API base URL and rename timeout env var
- Change base URL to https://api.scrapegraphai.com/api/v2 - Rename SGAI_TIMEOUT_S to SGAI_TIMEOUT - Simplify health endpoint to use BASE_URL Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent bebf149 commit 2eba148

4 files changed

Lines changed: 8 additions & 20 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@ const health = await sgai.healthy();
218218
| Variable | Description | Default |
219219
|----------|-------------|---------|
220220
| `SGAI_API_KEY` | Your ScrapeGraphAI API key ||
221-
| `SGAI_API_URL` | Override API base URL | `https://api.scrapegraphai.com/v2` |
221+
| `SGAI_API_URL` | Override API base URL | `https://api.scrapegraphai.com/api/v2` |
222222
| `SGAI_DEBUG` | Enable debug logging (`"1"`) | off |
223-
| `SGAI_TIMEOUT_S` | Request timeout in seconds | `120` |
223+
| `SGAI_TIMEOUT` | Request timeout in seconds | `120` |
224224

225225
## Development
226226

src/env.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export const env = {
22
debug: process.env.SGAI_DEBUG === "1",
3-
timeoutS: process.env.SGAI_TIMEOUT_S ? Number(process.env.SGAI_TIMEOUT_S) : 120,
3+
timeout: process.env.SGAI_TIMEOUT ? Number(process.env.SGAI_TIMEOUT) : 120,
44
};

src/scrapegraphai.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ import type {
1919
ApiSearchResponse,
2020
} from "./types.js";
2121

22-
const BASE_URL = process.env.SGAI_API_URL || "https://api.scrapegraphai.com/v2";
23-
const HEALTH_URL = process.env.SGAI_API_URL
24-
? `${process.env.SGAI_API_URL.replace(/\/v\d+$/, "")}`
25-
: "https://api.scrapegraphai.com";
22+
const BASE_URL = process.env.SGAI_API_URL || "https://api.scrapegraphai.com/api/v2";
2623

2724
function debug(label: string, data?: unknown) {
2825
if (!env.debug) return;
@@ -86,7 +83,7 @@ async function request<T>(
8683
...(body ? { "Content-Type": "application/json" } : {}),
8784
},
8885
body: body ? JSON.stringify(body) : undefined,
89-
signal: AbortSignal.timeout(env.timeoutS * 1000),
86+
signal: AbortSignal.timeout(env.timeout * 1000),
9087
});
9188

9289
if (!res.ok) {
@@ -161,13 +158,7 @@ export async function getCredits(apiKey: string): Promise<ApiResult<ApiCreditsRe
161158

162159
export async function checkHealth(apiKey: string): Promise<ApiResult<ApiHealthResponse>> {
163160
try {
164-
const { data, elapsedMs } = await request<ApiHealthResponse>(
165-
"GET",
166-
"/api/v2/health",
167-
apiKey,
168-
undefined,
169-
HEALTH_URL,
170-
);
161+
const { data, elapsedMs } = await request<ApiHealthResponse>("GET", "/health", apiKey);
171162
return ok(data, elapsedMs);
172163
} catch (err) {
173164
return fail(err);

tests/scrapegraphai.test.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ import { afterEach, describe, expect, spyOn, test } from "bun:test";
22
import * as sdk from "../src/scrapegraphai.js";
33

44
const API_KEY = "test-sgai-key";
5-
const BASE = process.env.SGAI_API_URL || "https://api.scrapegraphai.com/v2";
6-
const HEALTH_BASE = process.env.SGAI_API_URL
7-
? process.env.SGAI_API_URL.replace(/\/v\d+$/, "")
8-
: "https://api.scrapegraphai.com";
5+
const BASE = process.env.SGAI_API_URL || "https://api.scrapegraphai.com/api/v2";
96

107
function json(body: unknown, status = 200): Response {
118
return new Response(JSON.stringify(body), {
@@ -742,7 +739,7 @@ describe("checkHealth", () => {
742739

743740
expect(res.status).toBe("success");
744741
expect(res.data).toEqual(body);
745-
expectRequest(0, "GET", "/api/v2/health", undefined, HEALTH_BASE);
742+
expectRequest(0, "GET", "/health");
746743
});
747744
});
748745

0 commit comments

Comments
 (0)