ScraperFlyAI-ready Web Data API

request control

Custom Headers Scraping API with cookies support

ScraperFly lets teams forward selected headers and cookies for public pages when request context changes the response, while keeping header profiles small, testable, and easy to debug.

Request context

Send only the headers that make the public response clearer

ScraperFly helps teams add request context without turning every scrape into a copied browser session. Start from a clean baseline, then forward the headers or cookies that genuinely change the public response: language, accepted content type, consent state, referer path, device behavior, or authenticated-by-the-site preferences that are already available to your workflow.

That keeps custom header scraping understandable. Developers can compare before and after responses, see what changed, and pair headers with rendering, sessions, country targeting, or stronger routing only when the evidence supports the added control.

selected headerscookiesbaseline comparison
Developers comparing custom header and cookie response profiles in a scraping API request builder

What is a custom headers scraping API?

A custom headers scraping API is a hosted request layer that can fetch a public page while sending selected HTTP headers or cookies with the request. Instead of building a separate fetch stack for every target, your application sends the target URL, chooses output format and delivery controls, and adds request context only when the target response proves it matters.

Headers are not a magic bypass. They are context signals. A public page may respond differently to language preferences, accepted content types, user-agent families, referer context, cache directives, or cookies. The goal is to make that context explicit and testable, so the scraper can reproduce the useful response without carrying unnecessary browser clutter.

Practical takeaway: use custom headers to explain a required request context, not to disguise an unclear scrape profile.

When should a scraping request forward headers?

Forward headers when they change the response your product can use. A language header may return translated copy. A content negotiation header may affect whether the target sends HTML, JSON-like data, or compressed output. A referer can matter for public flows that depend on a previous page. Cookies can preserve consent, currency, region, or lightweight state. User-agent style behavior can change the layout or markup family a site returns.

The right workflow is simple: send a baseline request, inspect the response, add one kind of context, then compare. If the useful fields appear, the header profile earned its place. If nothing important changes, remove it and keep the request smaller.

Header or context What it can affect Use it when
Accept-LanguageLanguage, regional copy, currency hints, localized labelsThe target returns a different useful page by locale or language.
User-agent contextMarkup family, responsive layout, bot-sensitive behaviorThe same URL returns different HTML for different client profiles.
Accept and content headersReturned content type, compression, response shapeThe target negotiates output based on accepted formats.
RefererPublic navigation context, redirect path, campaign or listing flowThe target response depends on the public page path that led to it.
CookiesConsent state, preferences, currency, region, session continuityThe workflow needs state that is stable, legitimate, and reproducible.
Content-TypePOST body handling and API-style target behaviorYou send a body and the target expects a specific request format.

Why should teams avoid copying every browser header?

Copying every browser header feels thorough, but it usually makes scraping harder to operate. A real browser request can include volatile values, device hints, cache state, experiments, tracking context, and headers that are irrelevant to the data you need. When all of that is forwarded by default, failures become harder to explain because the request no longer has a clean cause-and-effect relationship.

A smaller header profile is easier to test, reproduce, monitor, and move into code. It also makes cost decisions clearer. If a page works with source HTML plus one language header, there is no reason to pay the complexity cost of rendering, session continuity, and premium routing. If a page still fails after the right context is present, the team has stronger evidence for the next escalation step.

Use the API Builder to compare a baseline request with a header-aware request before writing parser code around the result.

How are headers different from cookies and sessions?

Headers describe the request. Cookies carry state. Sessions preserve continuity across related requests. They often work together, but they solve different problems. A language header can ask for a regional version of a page. A cookie can keep a consent choice or currency preference. A session can keep that state consistent while the workflow moves across related public pages.

That difference matters because each control should have a clear job. If a single public page needs one language signal, a header may be enough. If a workflow must keep state across a search page, listing page, and detail page, sessions are more appropriate. If useful content appears only after frontend code runs, headers alone will not replace JavaScript rendering.

Control Keeps or changes Best use Common mistake
HeadersRequest context for one requestLanguage, accepted output, user-agent family, referer contextForwarding noisy browser headers with no evidence.
CookiesTarget-provided stateConsent, preferences, regional state, lightweight continuityUsing stale or unrelated cookies across different targets.
SessionsContinuity across related requestsMulti-step public flows that depend on shared stateUsing sessions for isolated pages with no dependency.
RenderingBrowser-built page stateSPAs, frontend-loaded content, waits, screenshots, PDFsRendering pages where source HTML already contains the data.
Country targetingGeographic request perspectivePages that vary by region, currency, availability, or redirectUsing geography when a simple language or cookie signal was enough.

What response evidence proves a header profile works?

The useful proof is in the response, not in the header list. Compare final URL, status code, content type, response size, language, visible fields, extracted links, redirect behavior, and parser results across samples. If the only change is cosmetic, the header may not be worth keeping. If the target fields become available or stabilize across pages, the profile is useful.

Choose the output that makes the comparison easy. HTML is useful when selectors and DOM relationships matter. Text or Markdown can make content differences easier to read. JSON metadata helps with diagnostics such as final URL, status, response size, and content type. Screenshots and PDFs help when a human needs visual proof. The response formats guide explains when each output shape is worth using.

Practical takeaway: keep a header only when it changes the response in a way your product can use or your team can explain.

How do headers work with rendering and routing?

Headers can be part of a broader request profile. A target may need a language header and raw HTML. Another may need cookies and a persistent session. A JavaScript-heavy page may need rendering plus a wait. A region-sensitive page may need country targeting. A stricter target may need stronger delivery through a rotating proxy scraping API or premium routing.

The mistake is enabling every control at once. That hides which control solved the problem and makes production behavior difficult to tune. Start with headers when request context is the suspected gap, then escalate only when response evidence points to rendering, sessions, geography, or routing.

How can custom header scraping stay predictable?

Keep each request profile small, named, and repeatable. Document which headers are forwarded and why. Test representative URLs before scaling. Separate page templates that need different context. Track status, final URL, response size, content type, and extracted field quality so bad responses do not silently enter the pipeline.

Cost control follows the same logic. Headers and cookies are often lighter than browser rendering or premium routing, but a noisy profile can still create debugging overhead. Keep simple pages simple, reserve heavier controls for pages that prove they need them, and review pricing before scaling a new target class.

Where should a team start?

Start with a baseline ScraperFly request for the public target URL. Capture HTML or the response format your parser needs. Add the smallest header or cookie context that could explain the missing or unstable result. Compare outputs. If the response improves, keep the profile. If it does not, remove the header and investigate rendering, sessions, routing, or target-specific errors instead.

For focused header pages, use the dedicated guides for user-agent behavior, Accept-Language, and Referer context. For practical testing, open the API Builder and compare the request profiles before writing production parser code.

Custom headers

Send request context the target understands without hiding the scrape profile

Headers can affect language, content type, device behavior, cache handling, and access to public pages. ScraperFly lets teams add header context deliberately, compare the response, and keep the final request shape easy to reproduce.

Raw HTML response mapped to visible page data
01

Raw HTML availability

Check whether the fields you need are already present in the first HTML response.

Best first test for simple pages, articles, docs, listings, and product details.

Before and after JavaScript rendering comparison
02

JavaScript dependency

Compare raw HTML with the rendered DOM or screenshot before turning on browser rendering.

Use rendering when raw HTML is only a shell and scripts create the useful content.

Cookies, consent, session and access context for scraping
03

State & access context

Identify whether cookies, consent, login boundaries, pagination, or the same visitor state affect the response.

Use sessions and headers when continuity changes the data you receive.

Regional content variations across countries and routes
04

Geo/content variation

Test whether country, language, currency, inventory, SERP, ads, or route reputation changes the result.

Use geo or premium routing only when the target proves the response varies by route.

Checks before custom header scraping

Where is the target field?

Find whether the field exists in raw HTML, rendered DOM, an API call, structured data, a file, or a later interaction state.

What changes the response?

Sample a few URLs and compare status, final URL, content length, redirects, empty states, and visible result differences.

What context is required?

Mark any dependency on consent, locale, cookies, headers, authentication boundary, pagination, filters, or previous requests.

What does failure look like?

Define the signals for blocked, partial, stale, redirected, empty, timed-out, or region-mismatched responses before scaling.

How headers change scraping setup

Fetch mode

Raw HTML availability decides whether the first request can stay simple or needs rendering, waits, screenshots, or extraction.

Request context

State requirements decide whether to add headers, cookies, sessions, consent handling, or a stable visitor profile.

Routing choice

Geo and reputation findings decide whether standard routing is enough or a country/premium route is justified.

Validation rules

Known failure states become checks for retries, escalation, QA review, and deciding when a lighter profile is still complete.

Header request builder

Build scraping requests with headers, output format, and delivery controls in one place

Custom headers are useful when the target varies by client signal or needs a specific public request context. Start with the smallest header set, then add rendering, sessions, country targeting, or stronger routing when samples justify the added complexity.

01
01

Add only the headers that change the response

Keep the request profile clean so the team can explain why each header exists.

02
02

Verify header impact against a baseline

Compare status, final URL, content type, size, and extracted fields before scaling.

03
03

Move the proven header profile into code

Copy a reproducible request into cURL, Python, Node.js, Postman, or a backend job.

Controls that keep requests predictable

cURL example

Generate Markdown with the same request shape you can move into production

curl "https://scraperfly.com/api/v1?url=https%3A%2F%2Fexample.com&format=markdown" \
  -H "apikey: YOUR_API_KEY"

Error handling

Turn scraping failures into fixes

Every web data workflow eventually meets a bad response: a missing URL, an invalid key, an empty HTML shell, a target 403, a rate limit, a render timeout, a broken PDF capture, or a JSON payload that does not contain the fields your product expected. ScraperFly is built to make those moments diagnosable. You inspect the HTTP status, the stable error code, the request profile, and the returned artifact, then choose the cheapest useful next move: fix the request, add credits, slow down, retry with backoff, enable rendering, change country, use premium routing, preserve headers, or validate the output before scaling.

Stable error shapeRetry decisionsCost-aware escalationOutput validation
Developer reviewing code and API request parameters on a laptop

01 / Request setup and access

Fix request mistakes first

Some failures are not target problems at all. They happen before ScraperFly can make a meaningful delivery attempt: a missing or malformed URL, an unsupported output format, an incompatible visual file type, a missing API key, an invalid key, or a key that has been paused or disabled. These errors are configuration signals, not retry signals: stop the workflow, point the developer to the exact field that needs correction, and keep credits focused on real target tests instead of repeated bad inputs.

missing_urlinvalid_urlunsupported_formatinvalid_api_key
  • Validate the URL and encoding before sending a batch.
  • Use supported outputs: HTML, text, Markdown, JSON, screenshot, or PDF.
  • Match screenshot file types to image output and PDF file type to PDF output.
  • Treat missing or invalid API keys as configuration work, not retry work.
Business dashboard with charts, documents and usage planning on a desk

02 / Credits, limits and concurrency

Separate limits from failures

A workload can fail because the account has no usable credits, the monthly plan limit has been reached, or concurrency is too aggressive for the current plan and target mix. ScraperFly makes those limits visible as operating signals, not mysterious scrape failures. That keeps the buying decision practical: start free, test the target, buy pay-as-you-go credits for uneven jobs, move to monthly credits when volume becomes predictable, and use backoff when request pressure is the real issue.

usage_limit_reachedrate_limitedcreditsbackoff
  • Use account status to check remaining credits before large runs.
  • Retry rate limits with backoff instead of immediately increasing pressure.
  • Keep one-off projects on pay-as-you-go when volume is uneven.
  • Move predictable recurring work to monthly credits when the pattern is proven.
Server room representing delivery paths, routing and network infrastructure

03 / Target delivery and network

Find delivery failures first

Many scraping platforms collapse delivery issues into a vague request failure. In production, that is not enough. The team needs to know whether the request timed out, the upstream target returned a temporary server error, the connection failed, the response was too large, redirects went somewhere unexpected, or the page came back as tiny HTML with no useful content. ScraperFly turns those failures into delivery evidence: try the light profile first, compare status and response size, then decide whether the next request needs backoff, another route, premium proxy, country targeting, or a narrower capture.

timeout5xxredirectsresponse_too_large
  • Retry temporary network and upstream failures with a controlled backoff policy.
  • Compare final URL, status, content type and response size across samples.
  • Escalate routing only when the response proves the simple path is unstable.
  • Treat oversized responses as a scope problem before scaling the same profile.
Digital security screen representing anti-bot and protected access signals

04 / Anti-bot, geo and access blocks

Read blocks before escalation

A target 403, 401, 429, CAPTCHA screen, WAF challenge, login wall, consent loop, or region-specific mismatch is not just an error; it is a clue about what the site expects from the visitor. Competitors often push teams toward a heavier default profile, but that can burn budget without proving the fix. ScraperFly's better path is evidence-based escalation: preserve realistic headers when context matters, use sessions when continuity changes the response, enable rendering when the useful content is browser-built, and choose premium or country routing when reputation or geography changes the result.

403429CAPTCHAcountry mismatch
  • Use premium routing when IP reputation is the proven bottleneck.
  • Use country targeting when language, currency, inventory or search results change by market.
  • Use headers, cookies and sessions when visitor state changes the response.
  • Reduce concurrency and add backoff when repeated requests trigger target throttling.
Developer preparing code and output artifacts on a laptop

05 / Rendering and output quality

Ship usable artifacts

A 200 status is not the same thing as a usable scrape. The raw HTML can be an empty app shell, Markdown can miss the main article, JSON can lack expected metadata, text can include noise, screenshots can be blank, and PDF or image output can fail if the browser step times out. ScraperFly is valuable because the same API request can move from raw HTML to rendered DOM, clean text, Markdown, JSON, screenshot or PDF, then be checked against the artifact your product actually needs. That reduces glue code, failed imports, and expensive batch runs that only discover bad output after the fact.

render_timeoutbrowser_render_failedJSON fieldsPDF/image output
  • Enable rendering when raw HTML is only a shell and the useful content appears after JavaScript.
  • Validate text, Markdown and JSON against expected fields before batching.
  • Use screenshot or PDF output when visual proof or audit evidence matters.
  • Treat blank or partial artifacts as quality failures even when HTTP status is successful.
ScraperFly fit

Cleaner error recovery

ScraperFly helps teams decide what to fix, what to retry, and what to escalate without turning every scrape into the most expensive request profile.

Stable error shape

Use HTTP status and error code together so application logic can choose between fixing input, refreshing credentials, slowing down, retrying, or escalating delivery.

Retry only when it helps

Network failures, rate limits, and temporary server errors can use backoff. Invalid URLs, unsupported formats, and bad keys should be corrected once.

Cost-aware escalation

Start with the light request profile, then add rendering, premium routing, country, sessions, headers, waits, or visual capture only when the failure proves it.

Validate output before scale

Confirm the real artifact your product needs: HTML, text, Markdown, JSON, screenshot, or PDF, before copying the same profile across a large URL set.

Header cost

Keep header experiments small before adding heavier controls

Headers are lightweight compared with browser rendering or premium routing. Test them first when request context may solve the problem, then escalate only if response evidence points there.

A lightweight HTML request returning a simple response
01

Basic fetch

Use a basic fetch when public HTML already contains the fields you need.

Lightest request profile; keep it when the response is complete.

JavaScript rendering producing a complete DOM
02

Rendering

Use rendering when raw HTML is a shell and JavaScript completes the page.

Heavier profile; use it only when browser output changes the result.

Several requests preserving cookies and visitor state
03

Stateful session

Use sessions when cookies, consent, locale, or pagination change the response.

Heavier state profile; preserve it only when continuity matters.

Request routing through geo and higher quality routes
04

Premium routing & geo

Use premium routing or geo only when origin, country, reputation, or regional content changes the result.

Heaviest routing profile; apply it only to targets that prove they need it.

What makes header-based scraping heavier

More infrastructure work

Browser rendering, routing choices, and longer waits mean the platform has to do more than return a simple response.

More target uncertainty

Redirects, empty states, rate limits, and challenge pages often require stronger delivery options or retries.

More state to preserve

Cookies, sessions, consent, and multi-page flows add moving parts that a plain stateless fetch does not have.

More evidence to return

Screenshots, PDFs, rendered output, and richer response artifacts are useful, but they are heavier than plain HTML.

How to keep header workflows predictable

Sample before scale

Test a small URL set first and group targets by the lightest profile that returns complete data.

Do not render by default

Inspect raw HTML before turning on rendering. Many public pages already contain the data you need.

Escalate by evidence

Move up only when the response shows missing content, state dependency, geo variance, or routing problems.

Measure useful results

Optimize around valid records delivered, not raw request volume. A lighter profile is best only when it stays complete.

Header questions

Common questions about custom headers and cookies in ScraperFly

Practical answers for teams deciding when headers, cookies, sessions, rendering, and routing should be part of a public web scraping request.

HEADER FAQ
HEADERS

Forwarding request context

Headers should explain a specific response change, not copy a browser by habit.

Should I forward all browser headers?

No. Start with the smallest set that changes the response in a useful way, then remove anything that does not improve the result.

Which headers are worth testing first?

Test language, user-agent, accept, content type, referer, or cache-related headers when the baseline response suggests one of those signals changes the page.

COOKIES

Working with public state

Cookies can carry preferences or continuity when the workflow genuinely depends on them.

When do cookies help a scraping request?

Cookies help when a public page needs consent state, currency, language, region, preferences, or continuity that is legitimate and reproducible for the workflow.

Are cookies the same as sessions?

No. Cookies carry state values. Sessions keep related requests together so that state remains consistent across a multi-step public workflow.

CONTROLS

Combining headers with ScraperFly options

Headers can work alongside rendering, sessions, country targeting, and routing when evidence supports the mix.

Can headers work with JavaScript rendering?

Yes. Use headers for request context and rendering for browser-built content. Enable both only when each one solves a visible response problem.

When should routing be added?

Add country targeting, rotating proxies, or premium routing when status, redirects, blocks, or regional output show that the delivery path affects the response.

DEBUGGING

Keeping profiles predictable

A clear profile makes failures easier to diagnose before traffic scales.

How do I know a header helped?

Compare baseline and header-aware responses for final URL, status, content type, response size, language, visible fields, and parser output.

How do headers affect cost control?

Headers are lightweight compared with browser rendering or premium routing, so they are often worth testing first when request context is the suspected issue.