Skip to main content
Exa is one of the fastest and most accurate web search APIs, built for AI applications. By combining Exa’s search API with Cerebras Inference, you can ground responses in current web content while keeping agent latency low.

Prerequisites

Before you begin, ensure you have:
  • Cerebras API Key
  • Exa API Key
  • Python or Node.js

Configure Exa with Cerebras

1

Install required dependencies

Install the Exa SDK and the OpenAI client library. The OpenAI client is used to connect to Cerebras’ OpenAI-compatible API.
The Node.js examples use ES modules and top-level await. Save them with a .mjs extension (or set "type": "module" in your package.json) and run them with node file.mjs.
2

Configure environment variables

Create a .env file in your project directory to securely store your API keys:
Get your keys here: Cerebras and Exa.
3

Perform your first grounded web search

This example uses Exa search to gather current web results, then asks a Cerebras model to combine them into a short answer.

Search types and freshness controls

Exa supports a few search modes with different speed and coverage tradeoffs: Freshness is controlled with max_age_hours in Python or maxAgeHours in Node, inside contents. It is optional: leave it out for no freshness limit, or set 0 to always fetch fresh content, 24 to accept cached pages up to one day old, or -1 to use cached content only.

Get page contents

Every Exa search result already includes page content (highlights), so you usually don’t need a separate call. We recommend using search for most grounding workflows. Reach for the Contents API when you already have a URL and want to get its highlights directly.

Use Exa as a tool for grounded answers

Tool calling works well when you want a Cerebras model to decide when to search the web. This example exposes Exa search as a tool.

Next steps