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, or provide it when initialising the SDK:
from scrapegraph_py import Client
client = Client(api_key="your-api-key")
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
import os
from scrapegraph_py import Client
client = Client(api_key=os.getenv("SGAI_API_KEY"))
- 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.