Integrate search data into your .NET application, AI workflow, or LLM/RAG pipeline. This is the official .NET client for SerpApi.
SerpApi supports Google, Google Maps, Google Shopping, Bing, Baidu, Yandex, Yahoo, DuckDuckGo, eBay, Walmart, YouTube, and 100+ engines.
- Async-first with full
CancellationTokensupport - Sync convenience wrappers
IAsyncEnumerablepagination- Dependency injection integration (
IHttpClientFactory) - Targets .NET Standard 2.0, .NET 7, 8, 9, and 10
- Zero external runtime dependencies
dotnet add package serpapiusing SerpApi;
using var client = new SerpApiClient(Environment.GetEnvironmentVariable("SERPAPI_KEY")!);
using var results = await client.SearchAsync(new Dictionary<string, string>
{
["engine"] = "google_light",
["q"] = "coffee"
});
foreach (var result in results.OrganicResults!.Value.EnumerateArray())
{
Console.WriteLine(result.GetProperty("title").GetString());
}try
{
using var results = await client.SearchAsync(parameters);
}
catch (SerpApiKeyException) { /* 401 — invalid API key */ }
catch (SerpApiHttpException ex) { /* 429, 500, etc — ex.StatusCode */ }
catch (SerpApiTimeoutException) { /* request timed out */ }
catch (SerpApiException ex) { /* catch-all */ }using var results = await client.SearchAsync(new Dictionary<string, string>
{
["engine"] = "google_light",
["q"] = "coffee",
["num"] = "10"
});
Console.WriteLine(results.SearchId);
Console.WriteLine(results.OrganicResults);
Console.WriteLine(results["local_results"]);string html = await client.HtmlAsync(new Dictionary<string, string>
{
["engine"] = "google_light",
["q"] = "coffee"
});// Next page
using var page2 = await client.NextPageAsync(results);
// Iterate all pages as an async stream
await foreach (var page in client.SearchPagesAsync(parameters, maxPages: 5))
{
using (page)
{
Console.WriteLine($"Page has {page.OrganicResults?.GetArrayLength()} results");
}
}var tasks = new[]
{
client.SearchAsync(new Dictionary<string, string>
{
["engine"] = "google_light", ["q"] = "coffee"
}),
client.SearchAsync(new Dictionary<string, string>
{
["engine"] = "google_news_light", ["q"] = "coffee"
})
};
try
{
var results = await Task.WhenAll(tasks);
// Process results here.
}
finally
{
foreach (var task in tasks)
{
if (task.Status == TaskStatus.RanToCompletion)
task.Result.Dispose();
}
}var locations = await client.LocationAsync("Austin, TX", limit: 3);
foreach (var loc in locations.EnumerateArray())
{
Console.WriteLine(loc.GetProperty("name").GetString());
}Retrieve a previous search (0 credits):
using var archived = await client.SearchArchiveAsync("previous_search_id");using var account = await client.AccountAsync();
Console.WriteLine(account["plan_id"]);using var results = await client.SearchAsync(new Dictionary<string, string>
{
["engine"] = "google",
["q"] = "coffee",
["location"] = "Austin, Texas"
});using var results = await client.SearchAsync(new Dictionary<string, string>
{
["engine"] = "google_light",
["q"] = "coffee"
});using var results = await client.SearchAsync(new Dictionary<string, string>
{
["engine"] = "google_scholar",
["q"] = "machine learning"
});using var results = await client.SearchAsync(new Dictionary<string, string>
{
["engine"] = "google_news",
["q"] = "artificial intelligence"
});using var results = await client.SearchAsync(new Dictionary<string, string>
{
["engine"] = "google_maps",
["q"] = "pizza",
["ll"] = "@40.7455096,-74.0083012,14z"
});using var results = await client.SearchAsync(new Dictionary<string, string>
{
["engine"] = "google_shopping",
["q"] = "laptop"
});using var results = await client.SearchAsync(new Dictionary<string, string>
{
["engine"] = "google_jobs",
["q"] = "software engineer"
});using var results = await client.SearchAsync(new Dictionary<string, string>
{
["engine"] = "google_images",
["q"] = "sunset"
});using var results = await client.SearchAsync(new Dictionary<string, string>
{
["engine"] = "google_finance",
["q"] = "AAPL:NASDAQ"
});using var results = await client.SearchAsync(new Dictionary<string, string>
{
["engine"] = "bing",
["q"] = "coffee"
});using var results = await client.SearchAsync(new Dictionary<string, string>
{
["engine"] = "duckduckgo",
["q"] = "coffee"
});using var results = await client.SearchAsync(new Dictionary<string, string>
{
["engine"] = "baidu",
["q"] = "coffee"
});using var results = await client.SearchAsync(new Dictionary<string, string>
{
["engine"] = "yahoo",
["p"] = "coffee"
});using var results = await client.SearchAsync(new Dictionary<string, string>
{
["engine"] = "youtube",
["search_query"] = "latte art"
});using var results = await client.SearchAsync(new Dictionary<string, string>
{
["engine"] = "walmart",
["query"] = "coffee maker"
});using var results = await client.SearchAsync(new Dictionary<string, string>
{
["engine"] = "ebay",
["_nkw"] = "laptop"
});using var results = await client.SearchAsync(new Dictionary<string, string>
{
["engine"] = "amazon",
["k"] = "coffee"
});using var results = await client.SearchAsync(new Dictionary<string, string>
{
["engine"] = "naver",
["query"] = "coffee"
});using var results = await client.SearchAsync(new Dictionary<string, string>
{
["engine"] = "apple_app_store",
["term"] = "coffee"
});using var results = await client.SearchAsync(new Dictionary<string, string>
{
["engine"] = "home_depot",
["q"] = "drill"
});using var client = new SerpApiClient("YOUR_API_KEY", new SerpApiClientOptions
{
Timeout = TimeSpan.FromSeconds(30)
});builder.Services.AddSerpApi(options =>
{
options.ApiKey = builder.Configuration["SerpApi:ApiKey"]!;
options.Timeout = TimeSpan.FromSeconds(30);
});Uses IHttpClientFactory for connection management.
Install the Microsoft.Extensions.Http.Resilience package:
dotnet add package Microsoft.Extensions.Http.Resiliencebuilder.Services.AddSerpApi(options =>
{
options.ApiKey = builder.Configuration["SerpApi:ApiKey"]!;
})
.AddStandardResilienceHandler();var handler = new HttpClientHandler
{
Proxy = new WebProxy("http://proxy.corp.example:8080"),
UseProxy = true
};
using var client = new SerpApiClient(
new HttpClient(handler),
new SerpApiClientOptions { ApiKey = "YOUR_API_KEY" });See examples/ for runnable projects:
| Example | Use Case | Description |
|---|---|---|
| LeadFinder | Lead generation | Find local businesses via Google Maps for sales outreach |
| CompetitorTracker | SEO & competitive intel | Monitor brand vs competitor SERP positions across engines |
| RankTracker | SEO rank monitoring | Track keyword positions page-by-page with pagination |
| PriceMonitor | Price monitoring | Compare product prices across Google Shopping and Walmart |
| AiResearchAgent | AI/RAG pipelines | Gather multi-source context (web + news + scholar) for LLMs |
| ContentDiscovery | Market research | Find trending topics, PAA questions, and content gaps |
| ErrorHandling | Reliability | Exception types, retry patterns, and graceful degradation |
| DependencyInjection | Enterprise integration | ASP.NET Core / generic host with IHttpClientFactory |
export SERPAPI_KEY=your_key_here
cd examples/LeadFinder
dotnet runBug reports and pull requests are welcome on GitHub at https://github.com/serpapi/serpapi-dotnet.
git clone https://github.com/serpapi/serpapi-dotnet.git
cd serpapi-dotnet
dotnet build
dotnet testMIT — see LICENSE.