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

# LLM Search

## 1️⃣ Real-time Web Search: Breaking LLM Time Limitations for More Accurate and Reliable Outputs

We've enhanced OpenAI and Gemini series models com o ability to access o mais recente information a partir do web, helping you:

* ✅ **Access Latest Information**: Get real-time updates on current events, latest research, or live data
* ✅ **Eliminate Knowledge Gaps**: Overcome the time limitations of LLM training data by accessing post-training information
* ✅ **Reduce Hallucinations**: Provide fact-based answers through real-time web searches, significantly reducing AI confabulations
* ✅ **Improve Decision Quality**: Make more confident decisions based on analysis and recommendations grounded in current facts

**Modelos Suportados:**
Currently supporting OpenAI and Gemini model series with two integration methods:

**1. Models with Native Search Capabilities**
**Gemini Series** (Ground with Google search):

* gemini-3.1-pro-preview-search
* gemini-3-flash-preview-search
* gemini-2.5-pro-search
* gemini-2.5-flash-search

**OpenAI Series** (Search Preview):

* gpt-4o-search-preview
* gpt-4o-mini-search-preview

**2. Parameter-Based Support**
Adicione o parâmetro `web_search_options={}` to enable web connectivity for Gemini and OpenAI models that support this parameter. If the API returns `Unknown parameter: 'web_search_options'`, the current model or upstream API does not accept this parameter. Use one of the native search models above, or use the `:surfing` suffix described below. Gemini search pricing is subject to the console and model detail page.

## Guia de Uso

Before using, run `pip install -U openai` to upgrade the openai package, and set your AIHubMix API Key as an environment variable:

```shellscript theme={null}
export AIHUBMIX_API_KEY="<AIHUBMIX_API_KEY>"
```

Windows PowerShell:

```powershell theme={null}
setx AIHUBMIX_API_KEY "<AIHUBMIX_API_KEY>"
```

**Example:**

<CodeGroup>
  ```py Python theme={null}
  import os
  from openai import OpenAI

  client = OpenAI(
      api_key=os.environ["AIHUBMIX_API_KEY"], # Replace with the key you generated in AiHubMix
      base_url="https://aihubmix.com/v1"
  )

  chat_completion = client.chat.completions.create(
      model="gemini-3.5-flash",
      # 🌐 Enable search
      web_search_options={},
      messages=[
          {
              "role": "user",
              "content": "Search for information about the AIhubmix LLM API platform, provide a brief introduction, and include relevant links."
          }
      ]
  )

  print(chat_completion.choices[0].message.content)
  ```

  ```ts Typescript theme={null}
  import OpenAI from 'openai';

  const client = new OpenAI({
      apiKey: process.env.AIHUBMIX_API_KEY,
      baseURL: 'https://aihubmix.com/v1'
  });

  async function main() {
      const chatCompletion = await client.chat.completions.create({
          model: 'gemini-3.5-flash',
          // 🌐 Enable search
          web_search_options: {},
          messages: [
              {
                  role: 'user',
                  content: 'Search for information about the AIhubmix LLM API platform, provide a brief introduction, and include relevant links.'
              }
          ]
      });

      console.log(chatCompletion.choices[0].message.content);
  }

  main().catch(console.error);
  ```

  ```shell Curl theme={null}
  curl "https://aihubmix.com/v1/chat/completions" \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $AIHUBMIX_API_KEY" \
      -d '{
      "model": "gemini-3.5-flash",
      "web_search_options": {},
      "messages": [
          {
              "role": "user",
              "content": "Provide information about Van Gogh on the Google Arts & Culture website, with a brief introduction and relevant links."
          }
      ],
      "stream": false
  }'
  ```
</CodeGroup>

## 2️⃣ Smart Surfing: Allowing AI to Explore the Internet Freely

By appending `:surfing` to the model id, any large language model can be equipped with search capabilities.

* Simply append the suffix, no complex integration é obrigatório
* This method will default to forwarding the user's request to the **Tavily search service**, and the LLM will reference the search results for response
* Search fee: **\$0.006 per search**
* The fee is currently deducted directly a partir do "credit change", and the "log detail" does not list the search fee yet, but will be shown no future

<Tip>
  The model id can be copied a partir do [model gallery](https://aihubmix.com/models).
</Tip>

**Example:**

<CodeGroup>
  ```py Python theme={null}
  import requests
  import json
  import os

  try:
      response = requests.post(
          url="https://aihubmix.com/v1/chat/completions",
          headers={
              "Authorization": f"Bearer {os.environ.get('AIHUBMIX_API_KEY')}",
              "Content-Type": "application/json",
          },
          json={
              "model": "gpt-5.5:surfing", # Append :surfing to the model id to support searching
              "messages": [
                  {
                      "role": "user",
                      "content": "Search for recent AIHubMix model updates, return concise Portuguese bullet points with source links."
                  }
              ],
              "stream": False
          },
          timeout=60
      )

      result = response.json()
      if response.status_code >= 400:
          print("Request failed:", response.status_code)
      print("API response:", json.dumps(result, ensure_ascii=False, indent=2))

  except requests.exceptions.RequestException as e:
      print(f"Request error: {e}")
  except json.JSONDecodeError as e:
      print(f"JSON decode error: {e}")
  except Exception as e:
      print(f"Other error: {e}")
  ```
</CodeGroup>

**API Response Example:**

```json theme={null}
{
  "id": "chatcmpl-xxxx",
  "model": "gpt-5.5-2026-04-24",
  "object": "chat.completion",
  "created": 1760000000,
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "AIHubMix is an API platform that aggregates model capabilities from multiple providers. Its official website is https://aihubmix.com."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 220,
    "completion_tokens": 240,
    "total_tokens": 460,
    "prompt_tokens_details": {
      "audio_tokens": 0,
      "cached_tokens": 0
    },
    "completion_tokens_details": {
      "accepted_prediction_tokens": 0,
      "audio_tokens": 0,
      "reasoning_tokens": 196,
      "rejected_prediction_tokens": 0
    }
  }
}
```

***

Última atualização: 2026-06-15
