Learning resourcesReviewed · Perplexity

Use Search API with the Google Gemini SDK

This Perplexity guide teaches Python and TypeScript developers to add web search to Gemini assistants, but its manual loop leaves API failure handling and call limits to the developer. It covers function declarations, search-result formatting, conversation history and a Python option for automatic tool execution.

Researched 25 Nov 2026

In short.

This Perplexity tutorial helps Python and TypeScript developers connect web search to Gemini assistants, but its manual loop needs added API failure handling and call limits. Each search invocation passes up to three queries to Perplexity and requests at most five combined results, then removes duplicate URLs and empty snippets. The guide explains matched function calls and responses, outlines streaming, and offers an automatic execution option for Python. The examples were not executed; runtime correctness, model availability, operating costs and reuse rights remain unverified or unknown.

Researched and written by an AI model and checked by a second AI model. How it works

Covers the complete selected documentation page at [https://docs.perplexity.ai/docs/search/agent-sdks/gemini.md], including Python and TypeScript prerequisites, tool descriptions and declarations, search handlers, manual loops, streaming excerpts and notes about automatic execution, multiple calls and filters. Linked documentation, pricing, service terms and SDK licenses are outside the selected scope. No explicit license notice appears in the supplied page. No code was executed; model availability, SDK compatibility, API behavior, generated answers and performance remain unverified.

The overview

Identity

Use Search API with the Google Gemini SDK is an integration tutorial published in Perplexity’s documentation at [https://docs.perplexity.ai/docs/search/agent-sdks/gemini.md]. It explains how to expose Perplexity Search as a function tool through Google’s Gen AI SDK, with examples in Python and TypeScript.

Assessment

The guide is useful when a Gemini assistant needs web information and the developer wants explicit control over search execution and conversation history. Its strongest detail is the complete non-streaming pattern: declare the tool, handle searches, retain the model’s calls and return matching results.

The manual examples provide a starting point for implementation. They do not include an iteration limit or API exception handling, and the page supplies no execution results establishing reliability or answer quality.

Users

The intended readers are developers building Gemini assistants that need current or externally supported information. Python readers can choose manual conversation management or an SDK-managed callable; the TypeScript examples use a manual loop.

Beginners will need familiarity with functions, environment variables, API clients and basic JSON schemas. Experienced developers can use the examples to understand call identifiers, multiple tool calls and where to add retrieval filters or application controls.

Capabilities

The web_search declaration accepts an array of one to three query strings. Its handler passes the first three queries in one Search API request, with max_results set to five across all queries. It skips results with empty snippets, removes duplicate URLs, flattens snippet line breaks and truncates long snippets to 400 characters followed by an ellipsis.

Results sent back to Gemini contain titles, URLs and snippets. The guide also explains how to return several tool results in one follow-up message and outlines streaming. Domain, country and date constraints can be added inside the handler; the supplied handler does not configure them.

Using it

Requirements

The Python examples require google-genai and perplexityai. The TypeScript examples require @google/genai and @perplexity-ai/perplexity_ai. Both paths require GEMINI_API_KEY and PERPLEXITY_API_KEY environment variables and access to the corresponding services.

The page does not specify Python, JavaScript runtime or SDK version requirements. Its examples use the model string gemini-3.8-flash; availability and compatibility are not established by the supplied evidence.

Mechanism

Gemini receives a description and parameter schema for web_search. When it requests that function, the application calls Perplexity, formats the results and returns them in a functionResponse. The next Gemini request includes both the original model content containing the functionCall and the corresponding response, paired by call id and name.

The loop repeats until Gemini returns no function calls, then returns the response text. Multiple calls receive separate response parts collected into one follow-up Content message; the shown handlers execute them sequentially. Unknown tool names receive an error object.

Setup

The documented installation commands are pip install google-genai perplexityai for Python and npm install @google/genai @perplexity-ai/perplexity_ai for TypeScript. After setting the two API-key environment variables, assemble the description strings, tool declaration, search handler and chat function.

The snippets depend on definitions from earlier blocks. The TypeScript declaration block contains placeholders for the description strings that must be replaced by the actual definitions when combining the examples. The Python manual path explicitly disables automatic function calling.

Example

The demonstration asks: What were the major AI infrastructure announcements this week? It passes that question to chat_with_search in Python or chatWithSearch in TypeScript, allowing Gemini to request searches before returning text.

The page provides no captured search results or final answer for this question. It therefore does not establish whether the answer covers the requested week, includes citations or correctly summarizes announcements. A date mentioned in a query does not enforce a publication-date restriction; the guide says explicit filters are needed for that.

Assessment & evidence

Limitations

The manual loops have no maximum iteration count and show no API retries, timeouts or exception handling. The handlers slice the query array but do not perform explicit runtime validation of model-supplied argument types.

Search context is limited to snippets, with empty snippets discarded and long ones shortened. The examples do not fetch full pages or require citations in the final answer. These choices can leave relevant context unavailable to Gemini.

The streaming examples show how to receive chunks but leave function-call accumulation as a comment. They do not supply a complete streaming tool loop. Correct streaming behavior, SDK compatibility and end-to-end execution were not assessed.

Reasoning

The design separates search retrieval from answer generation: Perplexity supplies search material, and Gemini receives it through a function response. Keeping the original call alongside its response preserves the conversation structure required by the documented pattern.

The three-query cap is an example-level efficiency choice; the page says the Search API accepts up to five queries. Short queries, a combined result cap and snippet truncation keep returned material compact. The recommendation to use short, single-entity queries is documentation advice without comparative performance measurements on this page.

Alternatives

Within the guide, Python’s automatic callable option reduces manual conversation bookkeeping. The page says the SDK inspects the callable’s signature, executes it and returns results to the model. It documents a default automatic-call limit of 10, configurable through maximum_remote_calls, and says function exceptions are returned as error messages.

The page also links to integration guides for the OpenAI SDK [https://docs.perplexity.ai/docs/search/agent-sdks/openai.md] and Anthropic SDK [https://docs.perplexity.ai/docs/search/agent-sdks/anthropic.md]. Their contents, feature parity and comparative suitability are not assessed.

Evidence

The evidence consists of the complete selected Perplexity documentation page, including both language examples, streaming fragments and explanatory notes. It supports an assessment of the documented integration pattern.

The page supplies no runtime logs, benchmark measurements, expected final answer or dependency lockfile. The examples were not executed, so successful API calls, answer accuracy, latency and reliability remain unverified.

Access & freshness

Costs

The page gives no Gemini or Perplexity prices, free-tier terms, billing units or worked cost examples. Total operating cost is unknown.

The three-query and five-result settings describe request behavior, not a verified billing limit. Multiple tool calls and repeated model requests can increase API activity, and the manual loop places no explicit ceiling on that activity.

Rights

The selected page contains no explicit license or redistribution notice for its documentation or code examples. It also does not provide SDK licenses, service terms or rights governing retrieved snippets. Those permissions and obligations are unknown from this evidence.

Freshness

The supplied capture is dated November 25, 2026. The page text does not identify a publication or last-updated date, and its installation commands do not pin dependency versions.

The model identifier gemini-3.8-flash is an example value in the captured code. Its current availability, the installed SDK interfaces and the stated automatic-call defaults have not been independently verified.

Actions

Start with the non-streaming example in the chosen language and preserve both sides of every function-call exchange, including call identifiers. Before deployment, add a manual-loop limit, argument validation and API failure handling. A streaming implementation also needs the function-call accumulator omitted from the excerpts.

Confirm model availability, compatible SDK versions, API pricing and applicable terms. Configure explicit date or domain filters when the task requires them, and evaluate whether the shortened snippets provide enough evidence for the intended answers.

Evidence for this report

selected-page.txtselected · checked 2026-11-25