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

# Portrix Managed Web Search for Grounded AI Answers

> Use Portrix managed web search to ground AI responses in up-to-date information. Enable search with a single header — no external search API needed.

Portrix includes built-in managed web search that lets AI models retrieve current information from the web before generating a response. There's no separate search API to integrate, no API keys to manage, and no retrieval pipeline to build — you enable it with a single header and Portrix handles the rest.

## What is managed web search?

AI models have a training data cutoff and cannot answer questions about recent events, live prices, or anything that has changed since their training ended. Managed web search closes this gap.

When search is enabled, Portrix's search layer sits between your request and the model:

1. It extracts the user's information need from the message
2. It fetches relevant, current web content
3. It injects that content into the model's context as grounding material
4. The model generates a response using both its parametric knowledge and the fresh web data

This means you get accurate, up-to-date answers without changing your prompt format or managing a retrieval pipeline yourself.

## Enabling web search

Set the `x-portrix-search: true` header on any chat completions request to activate managed web search for that call.

<CodeGroup>
  ```bash cURL theme={null}
  curl https://api.portrix.ai/v1/chat/completions \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -H "x-portrix-search: true" \
    -d '{
      "model": "openai/gpt-4o",
      "messages": [
        {
          "role": "user",
          "content": "What were the top AI announcements this week?"
        }
      ]
    }'
  ```

  ```python Python theme={null}
  from openai import OpenAI

  client = OpenAI(
      api_key="YOUR_API_KEY",
      base_url="https://api.portrix.ai/v1",
  )

  response = client.chat.completions.create(
      model="openai/gpt-4o",
      messages=[
          {
              "role": "user",
              "content": "What were the top AI announcements this week?",
          }
      ],
      extra_headers={
          "x-portrix-search": "true",
      },
  )

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

  ```typescript TypeScript theme={null}
  import OpenAI from "openai";

  const client = new OpenAI({
    apiKey: "YOUR_API_KEY",
    baseURL: "https://api.portrix.ai/v1",
  });

  const response = await client.chat.completions.create(
    {
      model: "openai/gpt-4o",
      messages: [
        {
          role: "user",
          content: "What were the top AI announcements this week?",
        },
      ],
    },
    {
      headers: {
        "x-portrix-search": "true",
      },
    }
  );

  console.log(response.choices[0].message.content);
  ```
</CodeGroup>

You can also enable search in the request body by adding `"search": true` alongside your `model` and `messages` fields — useful in environments where you cannot set custom headers.

## How it works

When a request arrives with search enabled, Portrix executes the following pipeline before the model sees the message:

<Steps>
  <Step title="Query extraction">
    Portrix parses the user's message and generates one or more optimised search queries.
  </Step>

  <Step title="Web retrieval">
    The search layer fetches current results from across the web, including news, documentation, and general web content.
  </Step>

  <Step title="Context injection">
    Retrieved content is formatted and prepended to the model's context as a system-level grounding block. Your original system prompt is preserved.
  </Step>

  <Step title="Model response">
    The model reads the injected content and your original messages, then generates a response grounded in the fresh information.
  </Step>
</Steps>

## Search with tool calling

For applications that need fine-grained control over when search runs, you can expose web search as an OpenAI-compatible tool. Define the tool in your request and Portrix handles execution when the model calls it:

```python theme={null}
tools = [
    {
        "type": "function",
        "function": {
            "name": "web_search",
            "description": "Search the web for current information on a topic.",
            "parameters": {
                "type": "object",
                "properties": {
                    "query": {
                        "type": "string",
                        "description": "The search query to run",
                    }
                },
                "required": ["query"],
            },
        },
    }
]

response = client.chat.completions.create(
    model="openai/gpt-4o",
    messages=[
        {
            "role": "user",
            "content": "What is the current price of Bitcoin?",
        }
    ],
    tools=tools,
    tool_choice="auto",
)
```

When the model decides it needs a web search, it emits a `tool_calls` response. Portrix intercepts the `web_search` call, executes it, and returns the results — you handle the follow-up completion in the same way as any other tool use.

## Use cases

<CardGroup cols={2}>
  <Card title="Current events" icon="newspaper">
    Answer questions about news, sports results, or market movements that postdate the model's training cutoff.
  </Card>

  <Card title="Product research" icon="magnifying-glass">
    Look up current pricing, availability, and reviews for products and services in real time.
  </Card>

  <Card title="Live data queries" icon="chart-line">
    Retrieve live metrics, exchange rates, weather, or any publicly available real-time data.
  </Card>

  <Card title="Fact-checking" icon="circle-check">
    Ground model outputs in current authoritative sources to reduce hallucination on factual claims.
  </Card>
</CardGroup>

## Response with citations

When search is enabled, the response object includes a `citations` field containing the source URLs used to ground the answer. Use these to display references in your UI or to let users verify claims:

```json theme={null}
{
  "id": "chatcmpl-abc123",
  "choices": [
    {
      "message": {
        "role": "assistant",
        "content": "This week's major AI announcements included..."
      }
    }
  ],
  "citations": [
    {
      "url": "https://example.com/ai-news-2025",
      "title": "AI News Weekly — Top Stories",
      "snippet": "The latest releases from major AI labs..."
    }
  ]
}
```

Access citations in Python with `response.citations` or via the raw JSON if you are working with the HTTP API directly.

<Note>
  Managed web search adds approximately 1–3 seconds of latency to each request while results are fetched and injected. If your application is latency-sensitive — such as a real-time chat interface — consider enabling search only for messages that contain explicit signals of recency-dependent questions (e.g. "latest", "current", "today").
</Note>

<Tip>
  Combine managed web search with a capable reasoning model like `openai/gpt-4o` or `anthropic/claude-3-5-sonnet` for the best results. These models are better at synthesising retrieved content into coherent, well-attributed answers.
</Tip>
