usingvarclient=newSerperClient(apiKey);// Perform a Google web search using the Serper API.varresponse=awaitclient.SearchAsync(newBaseSearchRequest{Q="artificial intelligence latest news",Num=5,});// The response includes organic results, knowledge graph, and more.foreach(varresultinresponse.Organic){Console.WriteLine($"[{result.Position}] {result.Title}");Console.WriteLine($" {result.Link}");}
News Search
Shows how to search Google News for recent articles.
1 2 3 4 5 6 7 8 91011121314151617
usingvarclient=newSerperClient(apiKey);// Search Google News for recent articles on a topic.varresponse=awaitclient.NewsSearchAsync(newBaseSearchRequest{Q="technology startups 2026",Num=5,});// The response contains a list of news articles with titles, sources, and dates.foreach(vararticleinresponse.News){Console.WriteLine($"{article.Title}");Console.WriteLine($" Source: {article.Source}, Date: {article.Date}");Console.WriteLine($" {article.Link}");}
Image Search
Shows how to search Google Images for image results.
1 2 3 4 5 6 7 8 91011121314151617
usingvarclient=newSerperClient(apiKey);// Search Google Images for images matching a query.varresponse=awaitclient.ImageSearchAsync(newBaseSearchRequest{Q="northern lights aurora borealis",Num=5,});// The response contains image results with URLs, dimensions, and source info.foreach(varimageinresponse.Images){Console.WriteLine($"{image.Title}");Console.WriteLine($" {image.ImageUrl} ({image.ImageWidth}x{image.ImageHeight})");Console.WriteLine($" Source: {image.Domain}");}
Search Tool
Shows how to use Serper as an AIFunction tool with any IChatClient.
1234
usingvarclient=newSerperClient(apiKey);// Create a Google search tool from the Serper client for use with any IChatClient.vartool=client.AsSearchTool(numResults:3);