AI Search
Learn how to use the Desearch API to search the web.
The Desearch API allows you to perform AI-powered web searches, gathering relevant information from multiple sources, including web pages,
research papers, and social media discussions. This guide provides usage instructions, code samples, and parameter details to help you
integrate the API into your applications.
Using Desearch AI Search API
The following examples demonstrate how to interact with the Desearch API using multiple coding platforms.
Request Sample
The following scripts:
-
Sends a POST request to the AI-powered search API at https://apis.datura.ai/desearch/ai/search.
-
It includes an Authorization header with an API key and sets the Content-Type to "application/json".
-
The request body contains parameters such as "date_filter": "PAST_24_HOURS", which limits results to the past 24 hours, and
"model": "NOVA", specifying the AI model used. -
The "prompt" field contains the search query "Tesla Space Program", and "streaming": False
ensures non-streaming results. -
The "tools" list specifies multiple data sources, including "Web Search", "Hacker News Search", "Reddit Search", "Wikipedia Search", "YouTube Search", "Twitter Search", and "ArXiv Search".
-
The script sends the request, passing the URL, payload, and headers, and then prints the raw response text.
import requests
url = "https://apis.datura.ai/desearch/ai/search"
headers = {
"Authorization": "<your-api-key>", # Replace with your actual API key
"Content-Type": "application/json"
}
data = {
"date_filter": "PAST_24_HOURS",
"model": "NOVA",
"prompt": "Tesla Space Program",
"streaming": False,
"tools": [
"Web Search",
"Hacker News Search",
"Reddit Search",
"Wikipedia Search",
"Youtube Search",
"Twitter Search",
"ArXiv Search"
]
}
response = requests.post(url, json=data, headers=headers)
# Handle errors gracefully
if response.status_code == 200:
try:
print(response.json())
except ValueError:
print("Invalid JSON response received.")
else:
print(f"Error: {response.status_code}, {response.text}")
const url = "https://apis.datura.ai/desearch/ai/search";
const headers = {
"Authorization": "<your-api-key>",
"Content-Type": "application/json"
};
const data = {
date_filter: "PAST_24_HOURS",
model: "NOVA",
prompt: "Tesla Space Program",
streaming: false,
tools: [
"Web Search",
"Hacker News Search",
"Reddit Search",
"Wikipedia Search",
"Youtube Search",
"Twitter Search",
"ArXiv Search"
]
};
fetch(url, {
method: "POST",
headers: headers,
body: JSON.stringify(data)
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error("Error:", error));
const axios = require('axios');
const url = "https://apis.datura.ai/desearch/ai/search";
const headers = {
"Authorization": "<your-api-key>",
"Content-Type": "application/json"
};
const data = {
date_filter: "PAST_24_HOURS",
model: "NOVA",
prompt: "Tesla Space Program",
streaming: false,
tools: [
"Web Search",
"Hacker News Search",
"Reddit Search",
"Wikipedia Search",
"Youtube Search",
"Twitter Search",
"ArXiv Search"
]
};
axios.post(url, data, { headers })
.then(response => console.log(response.data))
.catch(error => console.error("Error:", error));
<?php
$url = "https://apis.datura.ai/desearch/ai/search";
$headers = [
"Authorization: <your-api-key>",
"Content-Type: application/json"
];
$data = [
"date_filter" => "PAST_24_HOURS",
"model" => "NOVA",
"prompt" => "Tesla Space Program",
"streaming" => false,
"tools" => [
"Web Search",
"Hacker News Search",
"Reddit Search",
"Wikipedia Search",
"Youtube Search",
"Twitter Search",
"ArXiv Search"
]
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>
import Foundation
let url = URL(string: "https://apis.datura.ai/desearch/ai/search")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("<your-api-key>", forHTTPHeaderField: "Authorization")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
let requestData: [String: Any] = [
"date_filter": "PAST_24_HOURS",
"model": "NOVA",
"prompt": "Tesla Space Program",
"streaming": false,
"tools": [
"Web Search",
"Hacker News Search",
"Reddit Search",
"Wikipedia Search",
"Youtube Search",
"Twitter Search",
"ArXiv Search"
]
]
do {
request.httpBody = try JSONSerialization.data(withJSONObject: requestData, options: [])
} catch {
print("Error serializing JSON:", error)
}
let task = URLSession.shared.dataTask(with: request) { data, response, error in
if let error = error {
print("Error:", error)
return
}
if let data = data {
print(String(data: data, encoding: .utf8) ?? "Invalid response")
}
}
task.resume()
Parameters
Required
url
: The endpoint for the Desearch API.payload
/body
: A JSON string or dictionary containing:prompt
: A string representing the search query.tools
: A list of tools to be used for the search, e.g., ["Web Search"].model
: The model to be used for processing, e.g., "NOVA".date_filter
: A string to filter search results by date, e.g., "PAST_24_HOURS".
Optional
streaming
: A boolean indicating whether to enable streaming responses. Defaults totrue
.
Response Sample
Based on the above code, here is how the response is retrieved as JSON. Each coding language has its own way of retrieving data from the below JSON.
{
"reddit_search_results": {
"organic_results": [
{
"title": "what is it about SpaceX that is fostering their success?",
"link": "https://www.reddit.com/r/space/comments/1fdl7k4/"
}
]
},
"hacker_news_search_results": {
"organic_results": [
{
"title": "SpaceX runs as a giant R&D program",
"link": "https://news.ycombinator.com/item?id=23370130"
}
]
},
"completion": {
"key_sources": [
{
"text": "SpaceX put a Tesla sportscar into space five years ago.",
"url": "https://www.cnn.com/2023/02/06/world/spacex-elon-musk-tesla-roadster-five-years-scn/index.html"
}
],
"search_summary": "The Tesla Roadster launched by SpaceX is currently orbiting the Sun, traveling between Earth and Mars.",
"key_tweets": [
{
"text": "Starship is key to making life multiplanetary.",
"url": "https://x.com/teslaownersSV/status/1889722986036330565"
}
],
"key_news": [
{
"text": "SpaceX runs as a giant R&D program.",
"url": "https://news.ycombinator.com/item?id=23370130"
}
],
"key_posts": [
{
"text": "What is it about SpaceX that is fostering success?",
"url": "https://www.reddit.com/r/space/comments/1fdl7k4/"
}
],
"reddit_summary": "The Tesla Space Program showcases a synergy between automotive and aerospace innovation."
}
}
Models
Nova 1.0
Quick insights, broad coverage.
Orbit 1.0
Balanced analysis, targeted relevance.
Horizon 1.0
In-depth exploration, profound insights.
Tools
Web Search
To find information and resources across the internet.
To gather community-driven insights and discussions.
YouTube
For video content and tutorials.
Hacker News
To find tech-related news and discussions.
Wikipedia
For detailed and comprehensive information on a wide range of topics.
To gather real-time updates and discussions.
arXiv
For accessing research papers and preprints in various fields.
Test API
To experiment with the Desearch AI Search and see it in action, visit the Desearch API.
Updated about 11 hours ago