Quick Start

Install the OptimAI tools, set an API key, and run a decentralized live web search request.

This quick start gets a developer from zero to one working request. The API examples use server-side code because API keys should not be shipped to a browser.

1. Set your API key

Create an API key at search.optimai.network/api-keys, then keep it outside source control.

export OPTIMAI_API_KEY="sk-..."

Use --fail-with-body so a non-2xx response still prints the API error body.

curl --fail-with-body https://api-onchain.optimai.network/v1/search \
  -H "X-API-Key: $OPTIMAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "What are the latest AI agent retrieval patterns?",
    "limit": 5
  }'

3. Call from TypeScript

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 search infrastructure 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()
console.log(result.answer)

4. Choose the right integration

Use caseStart here
A product backend needs live web answersFirst Query
An AI coding agent should call OptimAI as a toolSearch MCP
A request should be paid through HTTP-native x402 flowx402 SDK

5. Read the response

A useful response should include a cited answer from the live web, source URLs, a tracking ID, and enough node context for a user or agent to verify where the answer came from.

Next step

Continue with First Query for response handling patterns.