Skip to main content
Some websites require specific HTTP headers to return content — authentication tokens, cookies, custom user agents, or API keys embedded in headers.

How to pass headers

In v2 all fetch behaviour — including custom headers and cookies — is configured through FetchConfig. It’s accepted by sgai.extract(), sgai.scrape(), sgai.search(), and sgai.crawl.start().
See the proxy & fetch configuration guide for all FetchConfig options.

Common use cases

Export cookies from your browser (e.g., using a browser extension like EditThisCookie) and pass them via cookies:

Mimicking a real browser

Some sites block requests without a browser-like User-Agent:
For stronger anti-bot protection, combine with stealth=True and mode="js" — see the proxy guide.

Bearer token authentication

For APIs or protected dashboards:

Tips

  • Headers and cookies are sent to the target website, not to the ScrapeGraphAI API.
  • Keep sensitive tokens out of your source code — load them from environment variables.
  • If you are unsure which headers to pass, open the target URL in your browser, go to DevTools → Network, and inspect the request headers of a successful page load.