Pass the key in the SGAI-APIKEY header for direct API calls. The v2 SDKs read it automatically from the SGAI_API_KEY environment variable — you can also pass it explicitly to the factory.
from scrapegraph_py import ScrapeGraphAI# Reads SGAI_API_KEY from env, or pass explicitly:sgai = ScrapeGraphAI(api_key="your-api-key")res = sgai.extract("Extract the title", url="https://example.com")
import { ScrapeGraphAI } from "scrapegraph-js";// Reads SGAI_API_KEY from env, or pass explicitly:const sgai = ScrapeGraphAI({ apiKey: "your-api-key" });const res = await sgai.extract({ url: "https://example.com", prompt: "Extract the title",});
curl -X POST https://v2-api.scrapegraphai.com/api/extract \ -H "SGAI-APIKEY: your-api-key" \ -H "Content-Type: application/json" \ -d '{"url": "https://example.com", "prompt": "Extract the title"}'
Keeping your key secure
Never commit your API key to a public repository. Use environment variables instead:
# .envSGAI_API_KEY=your-api-key-here
from scrapegraph_py import ScrapeGraphAI# Picks up SGAI_API_KEY from the environment automaticallysgai = ScrapeGraphAI()
Never expose your key in frontend code. Make API calls from a server or backend function.
Add .env to your .gitignore to avoid accidentally committing secrets.
Rotating your API key
If your key has been exposed or you want to rotate it for security: