Your API key authenticates every request you make to the ScrapeGraphAI API. Keep it secure and rotate it if you suspect it has been compromised.
Finding your API key
- Log in to the ScrapeGraphAI dashboard.
- Navigate to Settings.
- Your API key is displayed in the API Key section.
Using your API key
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")
Keeping your key secure
- Never commit your API key to a public repository. Use environment variables instead:
# .env
SGAI_API_KEY=your-api-key-here
from scrapegraph_py import ScrapeGraphAI
# Picks up SGAI_API_KEY from the environment automatically
sgai = 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:
- Go to Settings in the dashboard.
- Click Regenerate API Key.
- Copy the new key immediately — it will only be shown once.
- Update all services and environment variables that use the old key.
- The old key will be invalidated immediately.
Rotating your key will invalidate the old one. Any service still using the old key will start receiving 401 Unauthorized errors.