diff --git a/src/scrapegraphai.ts b/src/scrapegraphai.ts index b91fa3b..93a16ff 100644 --- a/src/scrapegraphai.ts +++ b/src/scrapegraphai.ts @@ -24,7 +24,7 @@ import type { } from "./types/index.js"; const BASE_URL = process.env.SGAI_API_URL || "https://api.scrapegraphai.com/v1"; -const HEALTH_URL = process.env.SGAI_API_URL +const ROOT_URL = process.env.SGAI_API_URL ? `${process.env.SGAI_API_URL.replace(/\/v\d+$/, "")}` : "https://api.scrapegraphai.com"; const POLL_INTERVAL_MS = 3000; @@ -298,7 +298,13 @@ export async function sitemap( export async function getCredits(apiKey: string): Promise> { try { - const { data, elapsedMs } = await request("GET", "/credits", apiKey); + const { data, elapsedMs } = await request( + "GET", + "/v2/credits", + apiKey, + undefined, + ROOT_URL, + ); return ok(data, elapsedMs); } catch (err) { return fail(err); @@ -312,7 +318,7 @@ export async function checkHealth(apiKey: string): Promise)["SGAI-APIKEY"]).toBe(API_KEY); } @@ -315,7 +316,7 @@ describe("getCredits", () => { expect(res.status).toBe("success"); expect(res.data).toEqual(body); - expectGet(0, "/credits"); + expectGet(0, "/v2/credits", ROOT); }); }); @@ -328,8 +329,6 @@ describe("checkHealth", () => { expect(res.status).toBe("success"); expect(res.data).toEqual(body); - const [url, init] = fetchSpy.mock.calls[0] as [string, RequestInit]; - expect(url).toBe("https://api.scrapegraphai.com/healthz"); - expect(init.method).toBe("GET"); + expectGet(0, "/healthz", ROOT); }); });