[▲ Vercel Community](/) · [Categories](/categories) · [Latest](/latest) · [Top](/top) · [Live](/live)

[AI SDK](/c/ai-sdk/62)

# Enabling web-search for OpenAI makes it so expensive, how can we improve that?

117 views · 1 like · 6 posts


marcolivierbouch (@marcolivierbouch) · 2026-01-12

A request with the websearch enabled cost around 0.22$ and without the websearch it is $0.0003593.

Why such difference?

```
const result = await generateText({
  model: 'openai/gpt-5-nano',
  prompt: truncatedPrompt,
  maxOutputTokens: tokenLimits.maxOutputTokens,
  //tools: {
  //  web_search: openai.tools.webSearch(webSearchConfig) as Tool,
  //},
});
```


Anshuman Bhardwaj (@anshumanb) · 2026-01-13

Hi @marcolivierbouch, welcome to the Vercel Community!

That's interesting. Can you check how many search calls did it make?

Are you using AI Gateway? If not you can refer to OpenAI's pricing for web search and models here:

https://openai.com/api/pricing/

![OpenAI websearch tool pricing](upload://jO9VrXVSavzDNWloLON8q6vPIZU.png)


marcolivierbouch (@marcolivierbouch) · 2026-01-13
| openai/gpt-5-nano | OpenAI | $0.1358454 | 54K | 4.6K | 1m18s |
|----|----|---:|---:|---:|---:|
| |

| openai/gpt-5-nano | OpenAI | $0.22060187 | 97K | 8K | 2m11s |
|----|----|---:|---:|---:|---:|
| |

| openai/gpt-5-nano | OpenAI | $0.13672295 | 56K | 5.2K | 1m35s |
|----|----|---:|---:|---:|---:|


Here’s what I get using the AI Gateway.

cost: ‘0.13672295’,
marketCost: ‘0.13672295’,
billableWebSearchCalls: 13

I just don’t understand why I get to 13 websearches, I would like to be able to limit that to one because it is very expensive.


Anshuman Bhardwaj (@anshumanb) · 2026-01-14

Hi @marcolivierbouch, I found this thread on the [OpenAI forum](https://community.openai.com/t/heads-up-web-search-tool-billing-can-be-higher-than-you-expect-here-s-why/1236954) discussing the issue you are facing. 

I'm not sure if we can control how the tool works, maybe check it's [references](https://ai-sdk.dev/providers/ai-sdk-providers/openai#web-search-tool). For example, change the ` searchContextSize: 'high'` to `medium`.

But, ai-sdk's `stopWhen` feature let's you limit number of steps, which I think is 1 by default.


Anshuman Bhardwaj (@anshumanb) · 2026-01-24

Hi @marcolivierbouch, I wanted to check in regarding your concern about the 13 web searches resulting in increased costs. Have you been able to implement any adjustments, such as modifying the `searchContextSize` or using the `stopWhen` feature? Did you find a solution or still need assistance? Let me know if you need more details.


marcolivierbouch (@marcolivierbouch) · 2026-01-26 · ♥ 1

Basicly I migrated to their API directly using responses api and it is doing only one websearch, which makes it quite cheap.