[ Web Proxy ]
URL:
Viewing: https://serpapi.com/integrations/cpp [Back]  [Original]

SerpApi: C++ Integration
SerpApi home [SerpApi home]
Pricing

Choose the plan that suits you best.

Easy Integrations

Start integration with your preferred language.

Features

Dive deeper into our advanced features.

Company

Explore company information and helpful guides.

Search API for C++

SerpApi SDK for C++.

Get started for free

C++

Official SDK installation

  • serpapi_dep = dependency("serpapi")

Code to integrate

SerpApi C++ [SerpApi C++]

Integrate search data into your C++ application. This library is the official wrapper for SerpApi.

SerpApi supports Google, Google Maps, Google Shopping, Baidu, Yandex, Yahoo, eBay, App Stores, and more.

Installation

C++17 and meson are required.

Install RapidJSON before configuring the build:

# macOS
brew install rapidjson

# Debian/Ubuntu Linux
sudo apt update && sudo apt install -y rapidjson-dev

Installation from Release

Download and extract the latest release:

curl -sL https://github.com/serpapi/serpapi-cpp/archive/refs/tags/v0.5.0.tar.gz | tar xz
cd serpapi-0.5.0
meson setup build
meson compile -C build
sudo meson install -C build

Tests are disabled by default for release builds. To build and run tests with Meson, install GoogleTest and configure with -Dtests=true.

Meson Dependency

Add the dependency to your meson.build:

serpapi_dep = dependency('serpapi')

Or if you are using it as a subproject:

serpapi_proj = subproject('serpapi')
serpapi_dep = serpapi_proj.get_variable('libserpapi_dep')

SerpApi C++

Simple Usage

#include <iostream>
#include <map>
#include <string>
#include <serpapi.hpp>
#include <rapidjson/document.h>
#include <rapidjson/stringbuffer.h>
#include <rapidjson/prettywriter.h>

int main() {
    const char* env_p = std::getenv("SERPAPI_KEY");
    if (!env_p) return 1;

    std::string apiKey(env_p);
    std::map<std::string, std::string> default_parameter;
    default_parameter["api_key"] = apiKey;
    default_parameter["engine"] = "google";

    serpapi::Client client(default_parameter);

    std::map<std::string, std::string> parameter;
    parameter["q"] = "coffee";
    parameter["location"] = "Austin,TX";

    rapidjson::Document d = client.search(parameter);

    rapidjson::StringBuffer buffer;
    rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
    d.Accept(writer);
    std::cout << "\nINFO: " << buffer.GetString() << std::endl;
    return 0;
}

This example runs a search for "coffee" on Google. It then returns the results as a RapidJSON Document. See the playground to generate your own code, or check out our local examples.

Advanced Usage

Search API

#include <serpapi.hpp>

// serpapi client created with default parameters
std::map<std::string, std::string> default_params = {
    {"api_key", "secret_key"},
    {"engine", "google"}
};
serpapi::Client client(default_params);

// search query overview (more fields available depending on search engine)
std::map<std::string, std::string> params = {
  {"engine", "google"},
  {"q", "Coffee"},
  {"location", "Portland,Oregon,United States"},
  {"device", "desktop"},
  {"hl", "en"},
  {"gl", "us"}
};

// formatted search results as a RapidJSON Document
rapidjson::Document results = client.search(params);

// raw search engine html as a String
std::string raw_html = client.html(params);

// raw search engine results as Markdown String
std::string raw_markdown = client.markdown(params);

Google search documentation.

Documentation

Location API

std::map<std::string, std::string> default_parameter = {};
serpapi::Client client(default_parameter);
std::map<std::string, std::string> parameter;
parameter["limit"] = "3";
parameter["q"] = "Austin";

rapidjson::Document doc = client.location(parameter);
const rapidjson::Value& list = doc.GetArray();

rapidjson::StringBuffer buffer;
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
list.Accept(writer);
std::cout << buffer.GetString() << std::endl;

It prints the first 3 locations matching Austin (Texas, Texas, Rochester).

NOTE: api_key is not required for this endpoint.

Search Archive API

This API allows retrieving previous search results.

serpapi::Client client({{"api_key", "secret_api_key"}, {"engine", "google"}});
rapidjson::Document results = client.search({{"q", "Coffee"}, {"location", "Portland"}});
std::string search_id = results["search_metadata"]["id"].GetString();

// Now let's retrieve the previous search results from the archive.
rapidjson::Document archived_results = client.search_archive(search_id);

Account API

serpapi::Client client({{"api_key", "secret_api_key"}});
rapidjson::Document account_info = client.account();

Advanced search API usage

Search API features non-blocking search using the option: async=true.

Example: Asynchronous searches

#include <serpapi.hpp>
#include <rapidjson/document.h>
#include <iostream>

int main() {
    serpapi::Client client({{"api_key", "YOUR_API_KEY"}, {"engine", "google"}});

    std::map<std::string, std::string> parameter;
    parameter["q"] = "coffee";
    parameter["async"] = "true";

    rapidjson::Document d = client.search(parameter);
    std::string id = d["search_metadata"]["id"].GetString();

    // You can later retrieve the results using search_archive
    rapidjson::Document results = client.search_archive(id);
    return 0;
}

Supported C++ version.

C++ versions validated by Github Actions:

Change logs

Developer Guide

Key goals

Code quality expectations

Latest coverage report

Generated with rake coverage (requires SERPAPI_KEY set to exercise the live API tests):

File Lines Exec Cover src/callback.cpp 11 8 72% src/serpapi.cpp 97 76 78% src/serpapi.hpp 1 1 100% TOTAL 109 85 78%

Design : UML diagram

Class diagram

classDiagram
  Application *-- serpapi 
  serpapi *-- Client
  class Client {
    engine String
    api_key String
    parameter map
    search() Document
    html() String
    markdown() String
    location() Document
    search_archive() Document
    account() Document
  }

Continuous integration

We use GitHub Actions for continuous integration.

Set your secret API key in your shell before running tests.

export SERPAPI_KEY="your_secret_key"

Check code quality using Lint.

rake lint

Run tests.

rake test

Run with Docker

env SERPAPI_KEY=SERPAPI_KEY docker run --rm -it -e SERPAPI_KEY --workdir /tmp/serpapi -v $PWD:/tmp/serpapi conanio/gcc10 make install_linux reset all

Development

References

Free Plan · 250 searches / month

Get started

They trust us

You are in good company. Join them.

APIs

About

Contact

Our Values SerpApi [SerpApi]

We value full transparency and painful honesty both in our internal and external communications. We believe a world with complete and open transparency is a better world.

Built with love in Austin, TX. 2026 SerpApi, LLC.


Web Proxy Viewer  |  New URL  |  Original Page