> ## Documentation Index
> Fetch the complete documentation index at: https://docs.laozhang.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Web search API: web_search and google_search

> Search the web before answering and return source links: web_search in Responses for GPT and Grok, google_search for Gemini, with per-search pricing.

Web search is a server-side tool. The model decides what to search for and how many times, reads the results, and answers with source links; your code doesn't run anything. LaoZhang API exposes it the way each vendor does: Responses for GPT and Grok, native `generateContent` for Gemini.

| Item | GPT, Grok | Gemini |
| - | - | - |
| Endpoint | `POST /v1/responses` | `POST /v1beta/models/{model}:generateContent` |
| Tool | `{"type": "web_search"}` | `{"google_search": {}}` |
| Search fee | \$0.01 per search | \$0.014 per search |
| Sources | `url_citation` annotations | `groundingMetadata` |

On top of the search fee, the search results the model reads are billed as input tokens, which usually adds several thousand to tens of thousands of input tokens per search.

Searching takes longer than a plain request, typically from ten seconds to a minute. Set your client timeout to 300 seconds.

## Supported models

Verified on October 14, 2026:

| Method | Models |
| - | - |
| Responses `web_search` | `gpt-6.1-sol`, `gpt-6-sol`, `gpt-5.6-luna`, `gpt-5.4-mini`, `gpt-5.4-nano`, `grok-4.5` |
| Gemini `google_search` | `gemini-4-argon`, `gemini-3.8-flash`, `gemini-3.5-flash-lite` |

The Chat Completions `web_search_options` parameter isn't available and returns 400 `Unknown parameter`. If your app is built on Chat Completions, send the requests that need search through Responses.

## GPT and Grok: Responses web\_search

Install the SDK (`python -m pip install openai`) and set the `LAOZHANG_API_KEY` environment variable first.

```python theme={null}
import os

from openai import OpenAI

client = OpenAI(
    api_key=os.environ["LAOZHANG_API_KEY"],
    base_url="https://api.laozhang.ai/v1",
    timeout=300.0,
)

response = client.responses.create(
    model="gpt-5.4-mini",
    input="What did the S&P 500 close at yesterday? Cite your source.",
    tools=[{"type": "web_search"}],
)
print(response.output_text)

for item in response.output:
    if item.type == "message":
        for part in item.content:
            for note in part.annotations or []:
                if note.type == "url_citation":
                    print(note.title, note.url)
```

`response.output` contains, in order:

* `web_search_call`: one item per search, and each one is billed
* `message`: the final answer, with `url_citation` sources in `annotations`

The same code works with `model="grok-4.5"`. Grok may search several times for one request, which adds time and search fees.

## Gemini: google\_search

Install the SDK (`python -m pip install google-genai`):

```python theme={null}
import os

from google import genai
from google.genai import types

client = genai.Client(
    api_key=os.environ["LAOZHANG_API_KEY"],
    http_options={"base_url": "https://api.laozhang.ai", "api_version": "v1beta", "timeout": 300_000},
)

response = client.models.generate_content(
    model="gemini-3.8-flash",
    contents="What did the S&P 500 close at yesterday? Cite your source.",
    config=types.GenerateContentConfig(tools=[types.Tool(google_search=types.GoogleSearch())]),
)
print(response.text)

grounding = response.candidates[0].grounding_metadata
if grounding:
    print("Queries:", grounding.web_search_queries)
    for chunk in grounding.grounding_chunks or []:
        print(chunk.web.title, chunk.web.uri)
```

The search fee is charged per query in `web_search_queries`. `grounding_chunks` lists the pages the model used; each `uri` is a Google redirect link that opens the original page.

Without the SDK, send the JSON directly:

```bash theme={null}
curl -s "https://api.laozhang.ai/v1beta/models/gemini-3.8-flash:generateContent" \
  -H "x-goog-api-key: ${LAOZHANG_API_KEY}" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{"parts": [{"text": "What did the S&P 500 close at yesterday? Cite your source."}]}],
    "tools": [{"google_search": {}}]
  }'
```

Gemini's OpenAI-compatible endpoint doesn't support this tool, so use the native format for search.

## Check search fees in your logs

On the console Logs page, a request that searched shows the number of web search tool calls and their cost. Through the [log query API](/en/api-capabilities/log-query), the same details are in `web_search_billing` inside the `other` field. Total cost = number of searches × per-search price + token cost.

## FAQ

### Why did the model answer without searching?

The tool lets the model search; it doesn't force it. Models usually search when the question needs current information. To make a search more likely, ask for it in the prompt, for example "search the web and cite your sources".

### Can I limit search to certain sites?

You can ask the model in the prompt to prefer certain sites, but it may still cite others. Check the behavior with a few requests before you rely on it.

### Is Nano Banana's Google Search grounding priced the same?

Yes. When a Nano Banana image model uses Google Search grounding, each search is also \$0.014; see [Nano Banana 2.1](/en/api-capabilities/nano-banana-2-1-image).

## Related documentation

* Let the model call your own functions: [Function calling](/en/api-capabilities/function-calling)
* Chat Completions compared with Responses: [OpenAI models](/en/api-reference/openai#chat-completions-or-responses)
* All fields of the native Gemini format: [Gemini protocol](/en/api-reference/gemini)
* Token prices per model: [Models and pricing](/en/models)

## References

* OpenAI: [Web search tool](https://developers.openai.com/api/docs/guides/tools-web-search)
* xAI: [Search tools](https://docs.x.ai/docs/guides/tools/search-tools)
* Google: [Grounding with Google Search](https://ai.google.dev/gemini-api/docs/google-search)
* LaoZhang API search fees and token usage: console [call logs](https://api.laozhang.ai/log)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.