Skip to main content
For AI agents: a documentation index is available at https://docs.parallel.ai/llms.txt. The full text of all docs is at https://docs.parallel.ai/llms-full.txt. You may also fetch any page as Markdown by appending .md to its URL or sending Accept: text/markdown.
Give your OpenAI-powered applications real-time web search capabilities by integrating Parallel Search as a tool. This guide shows how to define Parallel Search as an OpenAI function and handle tool calls in your application.

Overview

OpenAI’s tool calling (formerly function calling) allows GPT models to output structured JSON indicating they want to call a function you’ve defined. Your application then executes the function and returns results to the model. By defining Parallel Search as a tool, your model can:
  • Search the web for current information
  • Access real-time news, research, and facts
  • Cite sources with URLs in responses

Prerequisites

  1. Get your Parallel API key from Platform
  2. Get your OpenAI API key from OpenAI
  3. Install the required SDKs:

Define the Search Tool

First, define the Parallel search tool using OpenAI’s tool schema format. See Search Tool Definition for a framework-agnostic, copy-paste-ready version.
Setting strict: true (with additionalProperties: false and every field listed in required) enables OpenAI’s structured outputs for tool arguments, preventing schema-violating arguments from the model.

Implement the Search Function

Create a function that calls the Parallel Search API when the model requests it:

Process Tool Calls

Handle the tool calls returned by OpenAI:

Complete Example

Here’s a complete example that ties everything together:

Tool Parameters

This example uses the default advanced mode, which prioritizes result quality for tool use. For lower-latency responses, consider "turbo" (p50 ~200ms) or "basic". To switch, set the search mode to "turbo" inside your search_web handler. The tool schema the model sees stays unchanged. See Search Modes.