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();
console.log("Input tokens:", result.usage.input_tokens);
console.log("Output tokens:", result.usage.output_tokens);
for (const source of result.data.webPages.value) {
console.log(source.name, source.url);
}