fetch and AbortSignal.timeout. Select JavaScript below, save as search.mjs, replace the key, and run node search.mjs.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Use native fetch from a server-side JavaScript application.
fetch and AbortSignal.timeout. Select JavaScript below, save as search.mjs, replace the key, and run node search.mjs.
curl https://api.langsearch.com/v1/web-search \
-H "Authorization: Bearer YOUR_LANGSEARCH_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"query": "How does a search API help an AI agent?",
"count": 5,
"contents": {"text": true},
"freshness": "noLimit"
}'
import json
from urllib.request import Request, urlopen
request = Request(
"https://api.langsearch.com/v1/web-search",
data=json.dumps({
"query": "How does a search API help an AI agent?",
"count": 5, "contents": {"text": True}, "freshness": "noLimit"
}).encode(),
headers={
"Authorization": "Bearer YOUR_LANGSEARCH_API_KEY",
"Content-Type": "application/json"
}
)
with urlopen(request, timeout=30) as response:
result = json.load(response)
for source in result["data"]["webPages"]["value"]:
print(source["name"], source["url"])
const response = await fetch("https://api.langsearch.com/v1/web-search", {
method: "POST",
headers: {
Authorization: "Bearer YOUR_LANGSEARCH_API_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
query: "How does a search API help an AI agent?",
count: 5, contents: { text: true }, freshness: "noLimit",
}),
signal: AbortSignal.timeout(30000),
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const result = await response.json();
for (const source of result.data.webPages.value) {
console.log(source.name, source.url);
}
const sources = result.data.webPages.value.map((item) => ({
title: item.name,
url: item.url,
context: item.text || item.snippet || "",
}));
