Is the new web search parameter working?

Testing out the new web search tool but getting an error either the supplied code from the Documentation over at

https://platform.openai.com/docs/guides/tools-web-search?api-mode=chat


TypeError Traceback (most recent call last)
in <cell line: 0>()
10
11 # Make the API request
—> 12 completion = client.chat.completions.create(
13 model=“gpt-4o-search-preview”,
14 web_search_options={},

/usr/local/lib/python3.11/dist-packages/openai/_utils/_utils.py in wrapper(*args, **kwargs)
277 msg = f"Missing required argument: {quote(missing[0])}"
278 raise TypeError(msg)
→ 279 return func(*args, **kwargs)
280
281 return wrapper # type: ignore

TypeError: Completions.create() got an unexpected keyword argument ‘web_search_options’

Using Python.

This reply has been updated:

Here is a sample code snippet from the docs for using the web search tool with the completions API:

https://platform.openai.com/docs/guides/tools-web-search?api-mode=chat

from openai import OpenAI
client = OpenAI()

completion = client.chat.completions.create(
    model="gpt-4o-search-preview",
    web_search_options={},
    messages=[
        {
            "role": "user",
            "content": "What was a positive news story from today?",
        }
    ],
)

print(completion.choices[0].message.content)

Hi!
You need to use the responses API.
In your code your are invoking the chat.completions API:

completion = client.chat.completions.create(

I copied this from the documentation:

from openai import OpenAI
client = OpenAI()

response = client.responses.create(
    model="gpt-4o",
    tools=[{"type": "web_search_preview"}],
    input="What was a positive news story from today?"
)

print(response.output_text)

https://platform.openai.com/docs/guides/tools-web-search?api-mode=responses#page-top

4 Likes

so you’re saying web searches don’t work with the chat completions API? Because I see it web_search_options as a valid argument in self.client.beta.chat.completions.parse

for me personally I’m getting this error:

openai.BadRequestError: Error code: 400 - {‘error’: {‘message’: “Unknown parameter: ‘web_search_options’.”, ‘type’: ‘invalid_request_error’, ‘param’: ‘web_search_options’, ‘code’: ‘unknown_parameter’}}

Can you rephrase the question?
It’s a valid argument but you get a invalid parameter error message?

You do not need to use the responses API.

On chat completions, you’d use the offered model gpt-4o-search-preview-2025-03-11. It has built-in internet search retrieval, and some limitations in what else it can do.

Then the only parameter you need to address is the usefulness of adding those web_search_options, where size has a bit of effect on the default price of $0.035 per call (currently erroneously billed at $0.11 per call).

The API SDK code can deny unknown API parameters if not updated.


web_search_options (object, optional)

Tool configuration for searching the web to gather relevant results for a response.

  • search_context_size (string, optional, default: medium)
     High-level guidance on how much context window space to use for the search. One of low, medium, high.

  • user_location (object or null, optional)
     Approximate location parameters for the search.

    • type (string, required)
       The location approximation type. Always approximate.

    • approximate (object, required)
       Approximate location parameters.

      • city (string, optional)
         Free text for the user’s city, e.g. San Francisco.
      • country (string, optional)
         Two-letter ISO country code, e.g. US.
      • region (string, optional)
         Free text for the user’s region, e.g. California.
      • timezone (string, optional)
         IANA timezone of the user, e.g. America/Los_Angeles.
3 Likes

You are correct.
I just noted there is a little toggle on the documents page.

https://platform.openai.com/docs/guides/tools-web-search?api-mode=chat

This should work when using chat completions:

from openai import OpenAI
client = OpenAI()

completion = client.chat.completions.create(
    model="gpt-4o-search-preview",
    web_search_options={},
    messages=[
        {
            "role": "user",
            "content": "What was a positive news story from today?",
        }
    ],
)

print(completion.choices[0].message.content)

@rabbitandpork

3 Likes

They changed how to enable it. The old method, used in the old semi-deprecated completions api (https://api.openai.com/v1/chat/completions) was

{
        "model": "gpt-4o",
        "web_search_options": {},
(...)

The new method, used in the modern responses api (https://api.openai.com/v1/responses) is

{
    "model": "gpt-4o",
    "tools": [
        {
            "type": "web_search_preview"
        }
(if you have more tools, insert them here ofc)
      ]
(...)
  • adding a tool with just the type “web_search_preview” enables web searching.

That is not correct in the case of Chat Completions. The endpoint simply cannot use internal tools, so there was no such parameter.

On Chat Completions, you use an AI model specifically to make up for the lack of any tool call ability besides functions:

https://platform.openai.com/docs/models/gpt-4o-search-preview

For the Responses endpoint, you are correct, and you also may want to choose your cost with an additional parameter:

{
        "model": "gpt-4o",
        "tools": [{
            "type": "web_search_preview",
            "search_context_size": "low"
        }],
        "input": "How much does Google charge per web search?"
    }
Model Search context size Cost
gpt-4o or gpt-4o-search-preview low $30.00 / 1k calls
medium (default) $35.00 / 1k calls
high $50.00 / 1k calls
gpt-4o-mini or gpt-4o-mini-search-preview low $25.00 / 1k calls
medium (default) $27.50 / 1k calls
high $30.00 / 1k calls
1 Like

The chat.completions API is not going to be deprecated because of the responses API, the Assistants API will be.

We’re working to achieve full feature parity between the Assistants and the Responses API, including support for Assistant-like and Thread-like objects and the Code Interpreter tool. When complete, we plan to formally announce the deprecation of the Assistants API with a target sunset date in the first half of 2026.

Source:
https://platform.openai.com/docs/guides/responses-vs-chat-completions