curl

Google Search · curl
curl -G https://www.searchapi.io/api/v1/search \
  -H "Authorization: Bearer $SEARCHAPI_API_KEY" \
  --data-urlencode 'engine=google' \
  --data-urlencode 'q=best brazilian footballer' \
  --data-urlencode 'gl=us'

Python

Google Search · Python
import os

import requests

response = requests.get(
    "https://www.searchapi.io/api/v1/search",
    headers={"Authorization": f"Bearer {os.environ['SEARCHAPI_API_KEY']}"},
    params={
        "engine": "google",
        "q": "best brazilian footballer",
        "gl": "us",
    },
)
print(response.json())

JavaScript

Google Search · JavaScript
const params = new URLSearchParams({
  "engine": "google",
  "q": "best brazilian footballer",
  "gl": "us",
});
const response = await fetch(`https://www.searchapi.io/api/v1/search?${params}`, {
  headers: { Authorization: `Bearer ${process.env.SEARCHAPI_API_KEY}` },
});
console.log(await response.json());

Ruby

Google Search · Ruby
require "json"
require "net/http"

uri = URI("https://www.searchapi.io/api/v1/search")
uri.query = URI.encode_www_form(
  "engine" => "google",
  "q" => "best brazilian footballer",
  "gl" => "us"
)
request = Net::HTTP::Get.new(uri, "Authorization" => "Bearer #{ENV.fetch("SEARCHAPI_API_KEY")}")
response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(request) }
puts JSON.parse(response.body)

With a token placeholder

Fetch AI Overview · curl
curl -G https://www.searchapi.io/api/v1/search \
  -H "Authorization: Bearer $SEARCHAPI_API_KEY" \
  --data-urlencode 'engine=google_ai_overview' \
  --data-urlencode 'page_token=PASTE_FROM_PREVIOUS_RESPONSE'

Replace PASTE_FROM_PREVIOUS_RESPONSE with ai_overview.page_token from the response before it. It is valid for a few minutes.