Enhance Your Web Applications with Real-Time Search Capabilities

29 Oct 2025
Enhance Your Web Applications with Real-Time Search Capabilities

The Real Time Web Search API is a powerful tool designed for developers looking to integrate dynamic, AI-enhanced search functionalities into their applications. By leveraging this API, you can retrieve structured search results from the web in real-time, enabling users to access the most relevant information quickly and efficiently. Whether you're building a content aggregator, a research tool, or an e-commerce platform, the Real Time Web Search API simplifies the process of fetching and presenting search results, enhancing user experience with speed and accuracy.

Common use cases for this API include:

  • Developing applications that require timely information, such as news aggregators or event trackers.
  • Creating educational tools where users can ask questions and receive instant, curated responses.
  • Enhancing e-commerce platforms with real-time product and service searches to improve customer engagement.

Fetch AI-Enhanced Search Results

The Fetch AI-Enhanced Search Results action allows you to send a prompt or query and receive structured results enriched with reference links, all powered by Google's AI capabilities. This action is particularly useful for applications that need to provide detailed, curated answers to user inquiries in a conversational format.

Input Requirements:

  • Prompt: The initial query or instruction (e.g., "How to make a pizza step by step?").
  • Region Code: Optional parameter to specify the regional settings (default is 'us').
  • Language Code: Optional parameter to determine the response language (default is 'en').
  • Session Token: Optional token for maintaining session state between requests.

Expected Output:

The output will include structured data, such as:

  • Detailed text responses including paragraphs, headings, and lists.
  • Reference links to reputable sources for further reading.

Use Cases for this Specific Action:

  • Perfect for chatbots and virtual assistants that provide detailed responses to user queries.
  • Useful for educational platforms that require step-by-step guides or tutorials.
  • Ideal for content creation tools that aim to provide users with quick access to relevant resources.
import requests
import json

# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"

action_id = "39578f8f-9fd8-49c1-bf2c-95c0898c19be" # Action ID for: Fetch AI-Enhanced Search Results

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "prompt": "How to make a pizza step by step?",
  "region": "us",
  "language": "en"
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json",
    # Add any other required headers for the Cognitive Actions API
}

# Prepare the request body for the hypothetical execution endpoint
request_body = {
    "action_id": action_id,
    "inputs": payload
}

print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json=request_body
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully. Result:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body (non-JSON): {e.response.text}")
    print("------------------------------------------------")

The Execute Real-Time Web Search action retrieves organic search results from the web based on a specified query. This action supports advanced search operators and parameters, making it highly flexible for developers looking to implement comprehensive search functionalities.

Input Requirements:

  • Query: The main search term (e.g., "how to build a website").
  • Start Index: Optional index for paginating results.
  • Location: Optional geographical location to refine search results.
  • Country Code: Filters results based on the specified country (default is 'us').
  • Language Code: Sets the language of the search results (default is 'en').
  • Results Count: Number of results to return per query (default is 10).
  • No Family Filter: Flag to enable or disable family filter (default is '0').
  • Time Bound Search: Limits search results to a specific time period.
  • Remove Duplicates: Indicates whether to remove duplicate results.

Expected Output:

The output will consist of a list of search results that include:

  • URLs and titles of the relevant pages.
  • Snippets providing a brief description of the content.
  • The position of each result in the search listing.

Use Cases for this Specific Action:

  • Ideal for applications that require real-time access to web content, such as news aggregators or research tools.
  • Useful for e-commerce platforms that want to showcase products or services based on user queries.
  • Enhances user engagement in educational apps by allowing users to discover resources related to their interests instantly.
import requests
import json

# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"

action_id = "4d7c3202-bfdb-4a84-9971-33db0f95c35a" # Action ID for: Execute Real-Time Web Search

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "query": "how to build a website",
  "countryCode": "us",
  "languageCode": "en",
  "resultsCount": 10,
  "noFamilyFilter": "0"
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json",
    # Add any other required headers for the Cognitive Actions API
}

# Prepare the request body for the hypothetical execution endpoint
request_body = {
    "action_id": action_id,
    "inputs": payload
}

print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json=request_body
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully. Result:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body (non-JSON): {e.response.text}")
    print("------------------------------------------------")

Conclusion

Integrating the Real Time Web Search API into your applications can significantly enhance user experience by providing instant, relevant search results. Whether you choose to fetch AI-enhanced search results or execute real-time searches, the API offers a versatile solution for a variety of use cases, from educational tools to e-commerce platforms. As the demand for timely information continues to grow, leveraging such capabilities can set your application apart in a competitive landscape.

To get started, ensure you have your API key and familiarize yourself with the API documentation to tailor the integration to your specific needs.