Cost Control

ScraperAPI helps you control and manage your costs efficiently. By using the max_cost parameter with your requests, you instruct the API to set a limit on the maximum API credits you'd like to spend per each individual scrape. This helps prevent overspending, ensuring you stay within your individual project's budget.

  • API REQUEST

require 'net/http'
require 'json'

params = {
  :api_key => "API_KEY",
  :premium => "true",
  :max_cost => "5",
  :url => "https://example.com/"
}

uri = URI('https://api.scraperapi.com/')
uri.query = URI.encode_www_form(params)
website_content = Net::HTTP.get(uri)
print(website_content)
  • ASYNC REQUEST

require 'net/http'
require 'json'

uri = URI('https://async.scraperapi.com/jobs')

# Main payload including apiParams
payload = {
  "apiKey" => "API_KEY",
  "url" => "https://example.com",
  "apiParams" => {
    "render" => true,
    "max_cost" => 5
  }
}

# Convert payload to JSON
json_payload = payload.to_json

# Perform the POST request
response = Net::HTTP.post(uri, json_payload, "Content-Type" => "application/json")

# Print the response body
print(response.body)
  • PROXY MODE - COMING SOON!

If the scrape cost exceeds your limit, a 403 status code will be returned for the request, with the following error message:

"This request would cost more than your max_cost. You can see the cost per request in your response header or in API Playground in the dashboard."

Last updated