Skip to main content
Lesson 13 of 14 · Real-Time Web & X Search

Combining Web and X: Advanced Strategies

Lesson 13 of 14 Updated July 30, 2026 Beginner
On this page
  1. Orchestrating the two search engines
  2. Strategy 1: Fact/reaction complementarity
  3. Strategy 2: Cross-validation
  4. Strategy 3: Sequential pipeline
  5. Managing costs
  6. Managing API limits
  7. Hands-on practice
  8. Key takeaways

Orchestrating the two search engines

You now have web_search and x_search down individually. Grok API’s real power emerges when you combine them strategically. This lesson shows you how to orchestrate both tools to build sophisticated information pipelines while keeping costs and limits in check.

$5
/ 1,000 tool calls
2x
tools per request
Multi
invocations possible
Auto
selection by the model

Strategy 1: Fact/reaction complementarity

The most natural combination uses the web for facts and X for reactions. The model chooses the appropriate tool based on the nature of the information sought:

response = client.responses.create(
    model="grok-4.5",
    input="""Analyze the recent announcement of the European AI Act.

    PART 1 (web search):
    - Exact content of the new regulation
    - Effective dates and obligations
    - Companies and sectors affected

    PART 2 (X search):
    - Reactions from tech companies
    - Expert criticism and support
    - Perceived community impact

    SYNTHESIS: convergences and divergences
    between official facts and public perception.""",
    tools=[
        {"type": "web_search"},
        {"type": "x_search"}
    ]
)

Strategy 2: Cross-validation

Use both sources to validate information. If the web and X converge, confidence increases:

response = client.responses.create(
    model="grok-4.5",
    input="""I'm hearing that [Company X] is preparing
    massive layoffs.

    Verify this information:
    1. Web search: press articles, press releases
    2. X search: employee posts, insiders

    Assess credibility (1-10) by cross-referencing sources.
    Explicitly state whether both channels converge.""",
    tools=[
        {"type": "web_search"},
        {"type": "x_search"}
    ]
)

Strategy 3: Sequential pipeline

Sometimes, making two separate calls is more efficient than a single combined one. This gives you more control over the parameters for each search:

# Step 1: web collection with strict filtering
web_result = client.responses.create(
    model="grok-4.5",
    input="Latest advances in quantum computing",
    tools=[{
        "type": "web_search",
        "allowed_domains": ["arxiv.org", "nature.com", "science.org"]
    }]
)

# Step 2: X reactions filtered by handles
x_result = client.responses.create(
    model="grok-4.5",
    input=f"""Taking these advances into account:
    {web_result.output_text[:500]}

    What are researchers' reactions on X?""",
    tools=[{
        "type": "x_search",
        "allowed_x_handles": [
            "PeterShor_MIT",
            "ScottAaronson"
        ]
    }]
)

Managing costs

Each tool invocation costs $0.005, regardless of the number of results. When the model uses both tools in the same call, the cost doubles. If the model calls a tool multiple times (for example, two successive web searches to refine), each call is billed:

# Minimum cost: 1 tool x 1 invocation = $0.005
tools=[{"type": "web_search"}]

# Potential cost: 2 tools = $0.01 minimum
# But the model may invoke each tool
# multiple times if needed
tools=[
    {"type": "web_search"},
    {"type": "x_search"}
]

Optimizing quality/cost ratio

  • Combine only when necessary: if the question is purely factual, web_search alone suffices
  • Filter upstream: domain and handle parameters reduce noise and improve relevance at no extra cost
  • Use the sequential pipeline for complex analyses: the first step informs the second, reducing unnecessary searches

Managing API limits

Parameter limits

Each tool has its own constraints. Do not mix them:

  • web_search: allowed_domains OR excluded_domains (max 5 each)
  • x_search: allowed_x_handles OR excluded_x_handles (max 10 each) + from_date/to_date

Non-deterministic behavior

The model decides autonomously when and how many times to use each tool. Two identical requests may yield different search patterns. If reproducibility is critical, use the sequential pipeline with targeted requests.

Latency

Requests with two tools are slower. Plan for appropriate timeouts in your applications, especially if image or video analysis is enabled.

Hands-on practice

Implement all three strategies (complementarity, cross-validation, sequential pipeline) on the same current event topic. Compare result quality, response time, and total cost for each approach. Identify which strategy best suits your use case.

Key takeaways

  • Two tools in the same call: the model automatically chooses which one to use
  • The complementary strategy (web = facts, X = reactions) is the most common
  • Cross-validation strengthens confidence in the information
  • The sequential pipeline offers more control over parameters
  • Each tool invocation costs $0.005, regardless of the number of results
  • Optimize costs by combining only when both sources bring distinct value