OpenAI Function Calling with Web Search APIs: Complete Comparison
OpenAI's function calling (also called tool use) lets GPT models decide when to call external APIs. When you combine this with a web search API, you get an AI that can answer questions using real-time data from the internet. This comparison covers the best search APIs for OpenAI function calling, with code examples, pricing, and a verdict on which delivers the most value.
Key Takeaways
- OpenAI's function calling API works with any search API that returns free JSON formatter
- SearchHive offers the best value for GPT integrations: $49/mo for 100K credits across search, scraping, and research
- SerpApi has a native OpenAI integration but is 50x more expensive at scale
- Tavily is purpose-built for AI agents but costs $8/1K vs SearchHive's $0.49/1K
How OpenAI Function Calling Works with Search
The pattern is simple. You define a "function" (tool) that performs a web search. The model decides when to call it based on the user's question. Here is the minimal pattern:
import openai
import json
import requests
client = openai.OpenAI()
def web_search(query, num_results=5):
# Execute search via SearchHive SwiftSearch
resp = requests.post(
"https://api.searchhive.dev/v1/swiftsearch",
headers={
"Authorization": "Bearer your-api-key",
"Content-Type": "application/json",
},
json={"query": query, "num_results": num_results},
)
return json.dumps(resp.json().get("results", []))
tools = [
{
"type": "function",
"function": {
"name": "web_search",
"description": "Search the web for real-time information",
"parameters": {
"type": "object",
"properties": {
"query": {
"type": "string",
"description": "The search query",
},
"num_results": {
"type": "integer",
"description": "Number of results (1-10)",
"default": 5,
},
},
"required": ["query"],
},
},
}
]
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "What is the latest AI news?"}],
tools=tools,
)
if response.choices[0].message.tool_calls:
for tool_call in response.choices[0].message.tool_calls:
if tool_call.function.name == "web_search":
args = json.loads(tool_call.function.arguments)
result = web_search(args["query"])
# Feed back to model
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "user", "content": "What is the latest AI news?"},
response.choices[0].message,
{
"role": "tool",
"tool_call_id": tool_call.id,
"content": result,
},
],
)
print(response.choices[0].message.content)
Comparison Table
| Feature | SearchHive | SerpApi | Serper | Tavily | Brave Search | Exa |
|---|---|---|---|---|---|---|
| Per-1K Price | ~$0.49 | $25.00 | $1.00 | $8.00 | $5.00 | $7.00 |
| Free Tier | 500 credits | 250/mo | 2,500 one-time | 1,000/mo | $5 credits/mo | 1,000/mo |
| Search Quality | Excellent | Excellent | Good | Good | Good | Excellent (semantic) |
| Content Extraction | ScrapeForge + DeepDive | No | No | Built-in | No | $1/1K pages |
| JS Rendering | Yes (ScrapeForge) | No | No | No | No | No |
| Proxy Rotation | Built-in | No | No | No | No | No |
| OpenAI Compatible | Yes (any REST) | Yes | Yes | Yes | Yes | Yes |
| Rate Limits | 100 QPS | Varies by plan | 50-100 QPS | Varies | 50 QPS | Varies |
| Data Sources | Multi-engine | Google only | Google only | Multi-engine | Brave index | Neural index |
Feature-by-Feature Breakdown
Search Quality
SerpApi and Serper both query Google directly, which gives the best general-purpose results. SearchHive aggregates across multiple engines, which provides broader coverage. Tavily optimizes its results specifically for AI consumption (cleaner snippets, less noise). Exa uses a neural/semantic index that excels at research queries but can miss obvious keyword matches.
Content Extraction
This is where SearchHive separates from the pack. Most search APIs return titles, URLs, and snippets. SearchHive adds ScrapeForge (JS-rendered page scraping) and DeepDive (full content extraction). With other providers, you need a separate scraping API to get full page content. SearchHive gives you all three in one.
Pricing at Scale
At 100K searches per month:
- SearchHive Builder: $49 (flat)
- SerpApi: $725
- Serper: $100 (100K credits)
- Tavily: $800
- Brave Search: $500
- Exa: $700 (search only, no content extraction)
SearchHive is 15x cheaper than SerpApi, 16x cheaper than Tavily, and 10x cheaper than Brave -- while including features the others do not offer (scraping, research).
OpenAI Integration Complexity
All of these APIs work identically with OpenAI function calling since they all return JSON. The integration code is the same regardless of provider. The only difference is SerpApi's official Python SDK, which has a convenience wrapper, but you pay a massive premium for it.
Code Examples by Provider
SearchHive (Best Value)
import openai, json, requests
def search(query, n=5):
resp = requests.post(
"https://api.searchhive.dev/v1/swiftsearch",
headers={"Authorization": "Bearer KEY"},
json={"query": query, "num_results": n},
)
return json.dumps(resp.json().get("results", []))
Tavily (AI-Optimized)
import openai, json, requests
def search(query, n=5):
resp = requests.get(
"https://api.tavily.com/search",
params={"query": query, "api_key": "KEY", "max_results": n},
)
return json.dumps(resp.json().get("results", []))
Serper (Cheap Google SERP)
import openai, json, requests
def search(query, n=10):
resp = requests.get(
"https://google.serper.dev/search",
headers={"X-API-KEY": "KEY"},
params={"q": query, "num": n},
)
return json.dumps(resp.json().get("organic", []))
Brave Search (Privacy-Focused)
import openai, json, requests
def search(query, n=10):
resp = requests.get(
"https://api.search.brave.com/res/v1/web/search",
headers={"X-Subscription-Token": "KEY"},
params={"q": query, "count": n},
)
return json.dumps(resp.json().get("web", {}).get("results", []))
Exa (Semantic Search)
import openai, json, requests
def search(query, n=5):
resp = requests.post(
"https://api.exa.ai/search",
headers={"x-api-key": "KEY"},
json={"query": query, "num_results": n},
)
return json.dumps(resp.json().get("results", []))
Verdict
SearchHive is the best search API for OpenAI function calling for three reasons:
- Price: At $49/mo for 100K credits, it is an order of magnitude cheaper than any competitor with comparable features
- Completeness: Three APIs (SwiftSearch, ScrapeForge, DeepDive) in one means you do not need separate providers for search and content extraction
- Quality: Multi-engine search gives broader results than single-engine providers like SerpApi or Serper
Tavily is worth considering if you want zero-integration AI-optimized results and do not care about cost. Serper is decent for Google-only results at low volume. SerpApi is hard to recommend given the pricing.
For GPT agents that need to both search and read web content, there is no better value than SearchHive.
Next Steps
- Get a free SearchHive API key (500 credits, no credit card)
- Read the SwiftSearch API docs for advanced filtering and formatting options
- Check our Claude web access guide for Anthropic function calling patterns
- Compare with our LlamaIndex integration comparison
Get Started with SearchHive
SearchHive gives you search, scraping, and deep research in a single API with unified credits. Start free with 500 credits, then scale to 100K credits for $49/month.
Sign up free and start building smarter AI agents today.