AI Search Engine

Overview

AI Web Search Engine is designed to retrieve real-time information from the internet. This solution processes user queries and return relevant data from various online sources, making them useful for tasks that require up-to-date knowledge beyond static datasets. It supports two usage options:

1

Using six specialized API endpoints, each designed to search for only one specific type of information. These endpoints return structured responses, making them more suitable for integration into specialized services (e.g., a weather widget). Here are the types of information you can retrieve this way:

See API references and examples on the subpages.

2

As a general chat completion solution (but searching on the internet): enter a query in the prompt and receive an internet-sourced answer, similar to asking a question on a search engine through a browser. See the API Schema below or check how this call is made in the Python example on the bottom of this page.

How to make a call

Check how this call is made in the examples below.

API Schema

Generate a conversational response using a language model.

post

Creates a chat completion using a language model, allowing interactive conversation by predicting the next response based on the given chat history. This is useful for AI-driven dialogue systems and virtual assistants.

Authorizations
Body
modelundefined · enumRequiredPossible values:
frequency_penaltynumber | nullableOptional
logprobsboolean | nullableOptional
top_logprobsnumber | nullableOptional
max_tokensnumber · min: 1OptionalDefault: 512
ninteger | nullableOptional
presence_penaltynumber | nullableOptional
response_formatone ofOptional
or
seedinteger · min: 1Optional
stopany ofOptional
stringOptional
or
string[]Optional
or
any | nullableOptional
streambooleanOptionalDefault: false
temperaturenumber · max: 2Optional
top_pnumber · min: 0.1 · max: 1Optional
tool_choiceany ofOptionalDeprecated
string · enumOptionalPossible values:
or
userstringOptional
best_ofinteger | nullableOptional
use_beam_searchboolean | nullableOptional
top_kinteger | nullableOptional
min_pnumber | nullableOptional
repetition_penaltynumber | nullableOptional
length_penaltynumber | nullableOptional
early_stoppingboolean | nullableOptional
ignore_eosboolean | nullableOptional
min_tokensinteger | nullableOptional
stop_token_idsinteger[] | nullableOptional
skip_special_tokensboolean | nullableOptional
spaces_between_special_tokensany | nullableOptional
echoboolean | nullableOptional

If true, the new message will be prepended with the last message if they belong to the same role.

add_generation_promptboolean | nullableOptional

If true, the generation prompt will be added to the chat template. This is a parameter used by chat template in tokenizer config of the model.

add_special_tokensboolean | nullableOptional

If true, special tokens (e.g. BOS) will be added to the prompt on top of what is added by the chat template. For most models, the chat template takes care of adding the special tokens so this should be set to False (as is the default).

chat_templatestring | nullableOptional

A Jinja template to use for this conversion. If this is not passed, the model's default chat template will be used instead.

include_stop_str_in_outputboolean | nullableOptional

Whether to include the stop string in the output. This is only applied when the stop or stop_token_ids is set

guided_jsonany ofOptional

If specified, the output will follow the JSON schema.

stringOptional
or
or
any | nullableOptional
guided_regexstring | nullableOptional

If specified, the output will follow the regex pattern.

guided_choicestring[] | nullableOptional

If specified, the output will be exactly one of the choices.

guided_grammarstring | nullableOptional

If specified, the output will follow the context free grammar.

guided_decoding_backendstring · enum | nullableOptional

If specified, will override the default guided decoding backend of the server for this specific request. If set, must be either 'outlines' / 'lm-format-enforcer'

Possible values:
guided_whitespace_patternstring | nullableOptional

If specified, will override the default whitespace pattern for guided json decoding.

ipstring · ipOptional

IP from which a request is executed

Responses
201Success
post
POST /v1/chat/completions HTTP/1.1
Host: api.aimlapi.com
Authorization: Bearer <YOUR_AIMLAPI_KEY>
Content-Type: application/json
Accept: */*
Content-Length: 981

{
  "model": "bagoodex/bagoodex-search-v1",
  "messages": [
    {
      "role": "user",
      "content": "text"
    }
  ],
  "frequency_penalty": 1,
  "logit_bias": {
    "ANY_ADDITIONAL_PROPERTY": 1
  },
  "logprobs": true,
  "top_logprobs": 1,
  "max_tokens": 512,
  "n": 1,
  "presence_penalty": 1,
  "response_format": {
    "type": "text"
  },
  "seed": 1,
  "stop": "text",
  "stream": false,
  "temperature": 1,
  "top_p": 1,
  "user": "text",
  "best_of": 1,
  "use_beam_search": true,
  "top_k": 1,
  "min_p": 1,
  "repetition_penalty": 1,
  "length_penalty": 1,
  "early_stopping": true,
  "ignore_eos": true,
  "min_tokens": 1,
  "stop_token_ids": [
    1
  ],
  "skip_special_tokens": true,
  "spaces_between_special_tokens": null,
  "echo": true,
  "add_generation_prompt": true,
  "add_special_tokens": true,
  "documents": [
    {
      "ANY_ADDITIONAL_PROPERTY": "text"
    }
  ],
  "chat_template": "text",
  "chat_template_kwargs": {
    "ANY_ADDITIONAL_PROPERTY": null
  },
  "include_stop_str_in_output": true,
  "guided_json": "text",
  "guided_regex": "text",
  "guided_choice": [
    "text"
  ],
  "guided_grammar": "text",
  "guided_decoding_backend": "outlines",
  "guided_whitespace_pattern": "text",
  "ip": "text"
}
201Success

No content

Example #1

import requests
from openai import OpenAI

# Insert your AIML API Key instead of <YOUR_AIMLAPI_KEY>:
API_KEY = '<YOUR_AIMLAPI_KEY>'
API_URL = 'https://api.aimlapi.com'

def complete_chat():
    client = OpenAI(
        base_url=API_URL,
        api_key=API_KEY,
    )    

    response = client.chat.completions.create(
        model="bagoodex/bagoodex-search-v1",
        messages=[
            {
                "role": "user",
                
                # Enter your query here
                "content": 'how to make a slingshot',
            },
        ],
    )
    
    
    print(response.choices[0].message.content)


# Run the function
complete_chat()
Response
To make a slingshot, you can follow the instructions provided in the two sources:

**Option 1: Make a Giant Slingshot**

* Start by cutting two 2x4's to a length of 40 inches each, which will be the main arms of the slingshot.
* Attach the arms to a base made of plywood using screws, and then add side braces to support the arms.
* Install an exercise band as the launching mechanism, making sure to tighten it to achieve the desired distance.
* Add a cross brace to keep the arms rigid and prevent them from spreading or caving in.

**Option 2: Make a Stick Slingshot**

* Find a sturdy, Y-shaped stick and break it down to the desired shape.
* Cut notches on the ends of the stick to hold the rubber bands in place.
* Create a pouch by folding a piece of fabric in half and then half again, and then cutting small holes for the rubber bands.        
* Thread the rubber bands through the holes and tie them securely to the stick using thread.
* Decorate the slingshot with coloured yarn or twine if desired.

You can choose to make either a giant slingshot or a stick slingshot, depending on your preference and the materials available.  

Example #2: Using the IP Parameter for Personalized Model Output

When using regular search engines in browsers, we can simply ask, 'Weather today' without specifying our location. In this case, the search engine automatically uses your IP address to determine your location and provide a more relevant response. The AI Search Engine also supports IP-based personalization.

In the example below, the query does not specify a city, but since the request includes an IP address registered in Stockholm, the system automatically adjusts, and the response will contain today's weather forecast for that city.

import requests
from openai import OpenAI

# Insert your AIML API Key instead of <YOUR_AIMLAPI_KEY>:
API_KEY = '<YOUR_AIMLAPI_KEY>'
API_URL = 'https://api.aimlapi.com'

# Call the standart chat completion endpoint to get an ID
def complete_chat():
    client = OpenAI(
        base_url=API_URL,
        api_key=API_KEY,
    )    

    response = client.chat.completions.create(
        model="bagoodex/bagoodex-search-v1",
        messages=[
            {
                "role": "user",
                "content": "Weather today",
            },
        ],
        
        # insert your IP into this section
        extra_body={
            'ip': '192.44.242.19' # we used a random IP address from Stockholm
        }
    )
    print(response.choices[0].message.content)
    return response


# Run the function
complete_chat()
Response When Using IP Parameter
"According to the forecast, today's weather in Stockholm is partly cloudy with light winds. The temperature is expected to be around 6°C (43°F) with a gentle breeze. \n\nThe forecast also mentions that the weather will be sunny intervals and light winds throughout the day."

If an IP address registered in one location is used while explicitly specifying a different location in the query, AI Search Engine will prioritize the location from the query:

Response when the IP parameter is used (from Stockholm), but the request also includes a different location (San Francisco)
"According to the weather forecast, today in San Francisco, there will be a strong cold front moving through the Bay Area from late morning into the afternoon, boosting wind speeds with gusts at around 45 mph midday and featuring high rain rates at times. This may lead to localized runoff issues. The high temperature is expected to be around 56F, with a chance of rain 100% and rainfall near a half an inch. \n\nYou can check the latest forecast and weather conditions on websites such as [https://weather.com/weather/today/l/USCA0987:1:US] or [https://www.accuweather.com/en/us/san-francisco/94103/weather-forecast/347629]."

Last updated

Was this helpful?