Overview
This guide shows how to expose Perplexity’s Search API to Gemini as a function tool through Google’sgoogle-genai SDK. The model emits a functionCall part with name and args, you execute the tool (in this case, call client.search.create), and you send the result back as a functionResponse part. The loop continues until the model returns a final text response.
The Python SDK can run the tool-call loop automatically if you pass a Python callable directly to
tools=[...] — the SDK introspects the signature and invokes your function. This page uses the manual loop so the pattern matches the Anthropic and OpenAI integration pages and so you keep explicit control over the call. The auto-loop variant is shown in Notes.Prerequisites
Tool definition
Gemini accepts aTool containing one or more FunctionDeclaration objects. Each declaration takes a name, description, and a JSON Schema for parameters. The description below was tuned for Perplexity’s Search API; keep it verbatim — the wording is what produces good, short, keyword-style queries.
Tool handler
The handler is a thin wrapper aroundclient.search.create. The Search API natively accepts an array of queries (up to five), so the array Gemini emits can be passed straight through.
Tool-call loop
Disable the automatic loop withAutomaticFunctionCallingConfig(disable=True) (Python) — the JS SDK doesn’t auto-loop in core APIs to begin with. Then walk response.function_calls, execute each call, and send the model a follow-up Content array that contains the original function_call parts and the matching function_response parts.
Streaming
For streaming, usegenerate_content_stream (Python) or generateContentStream (TypeScript). A single functionCall part can be split across stream chunks, so accumulate parts before invoking your handler. The loop structure is otherwise identical to the non-streaming version.
Notes
-
Automatic loop (Python only). The Python SDK can run the tool-call loop for you. Pass a Python callable directly and the SDK will introspect its signature, invoke it, and feed the result back to the model — no manual loop, no
Contentplumbing.The auto-loop depth caps at 10 by default — raise it viaAutomaticFunctionCallingConfig(maximum_remote_calls=N)for long research chains. Auto-mode is convenient but trades visibility for terseness: errors surface through exceptions rather than tool-result content the model can recover from. -
Parallel calls. Gemini can emit multiple
function_callparts in a single response. Build onefunction_responsepart per call (matched bynameplus the call’s position within the turn) and put them all in one follow-upContent. -
Pair
function_callandfunction_response. Both turns must be present in the nextgenerate_contentcall — the model needs to see its ownfunction_callpart alongside yourfunction_responsepart. Dropping either side produces “missing function response” errors. -
Domains and dates. Pass
search_domain_filter,country, and other Search API parameters insiderun_web_searchif you want fixed retrieval constraints. See the Search API quickstart for the full parameter list.
Next Steps
Use with Anthropic SDK
Wire Search API into the Anthropic Messages API.
Use with OpenAI SDK
Wire Search API into the OpenAI Responses API.
Search API Quickstart
Full Search API parameter reference.
Search Best Practices
Patterns for production search workloads.