First Query
Send a natural language query and handle cited live-web output.
Start with one specific question and a small source limit.
const response = await fetch("https://api-onchain.optimai.network/v1/search", {
method: "POST",
headers: {
"X-API-Key": process.env.OPTIMAI_API_KEY ?? "",
"Content-Type": "application/json",
},
body: JSON.stringify({
query: "What changed in AI agent retrieval this week?",
limit: 5,
}),
})
if (!response.ok) {
const message = await response.text()
throw new Error(`OptimAI Search failed: ${response.status} ${message}`)
}
const result = await response.json()Minimal response renderer
console.log(result.answer ?? "No answer returned")
for (const source of result.sources ?? []) {
console.log(`- ${source.title ?? source.url}: ${source.url}`)
}What to inspect
answer: the cited live-web response.sources: URLs used to support the answer.metadata: request timing, tracking ID, and node context.
UI behavior
Show sources close to the answer. The product promise is trust, so the evidence should not be hidden behind a secondary screen.
Keep the original query and the source list together in logs. When a user asks "why did the answer say that?", the source URLs are the fastest path to debug the result.