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:
max_tokensnumber · min: 1Optional

The maximum number of tokens that can be generated in the chat completion. This value can be used to control costs for text generated via API.

Default: 512
streambooleanOptional

If set to True, the model response data will be streamed to the client as it is generated using server-sent events.

Default: false
frequency_penaltynumber | nullableOptional

Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.

logprobsboolean | nullableOptional

Whether to return log probabilities of the output tokens or not. If True, returns the log probabilities of each output token returned in the content of message.

top_logprobsnumber | nullableOptional

An integer between 0 and 20 specifying the number of most likely tokens to return at each token position, each with an associated log probability. logprobs must be set to True if this parameter is used.

ninteger | nullableOptional

How many chat completion choices to generate for each input message. Note that you will be charged based on the number of generated tokens across all of the choices. Keep n as 1 to minimize costs.

presence_penaltynumber | nullableOptional

Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.

response_formatone ofOptional

An object specifying the format that the model must output.

or
or
seedinteger · min: 1Optional

This feature is in Beta. If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result.

stopany ofOptional

Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence.

stringOptional
or
string[]Optional
or
any | nullableOptional
temperaturenumber · max: 2Optional

What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or top_p but not both.

top_pnumber · min: 0.01 · max: 1Optional

An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or temperature but not both.

echobooleanOptional

If True, the response will contain the prompt. Can be used with logprobs to return prompt logprobs.

repetition_penaltynumber | nullableOptional

A number that controls the diversity of generated text by reducing the likelihood of repeated sequences. Higher values decrease repetition.

top_knumberOptional

Only sample from the top K options for each subsequent token. Used to remove "long tail" low probability responses. Recommended for advanced use cases only. You usually only need to use temperature.

min_pnumber · max: 1Optional

A number between 0 and 1 that can be used as an alternative to top_p and top_k.

userstringOptional
best_ofinteger | nullableOptional
use_beam_searchboolean | 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
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: 1035

{
  "model": "bagoodex/bagoodex-search-v1",
  "messages": [
    {
      "role": "user",
      "content": "text",
      "name": "text"
    }
  ],
  "max_tokens": 512,
  "stream": false,
  "stream_options": {
    "include_usage": true
  },
  "frequency_penalty": 1,
  "logit_bias": {
    "ANY_ADDITIONAL_PROPERTY": 1
  },
  "logprobs": true,
  "top_logprobs": 1,
  "n": 1,
  "presence_penalty": 1,
  "response_format": {
    "type": "text"
  },
  "seed": 1,
  "stop": "text",
  "temperature": 1,
  "top_p": 1,
  "echo": true,
  "repetition_penalty": 1,
  "top_k": 1,
  "min_p": 1,
  "user": "text",
  "best_of": 1,
  "use_beam_search": true,
  "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,
  "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?