Code Search Tool
Fast, token-efficient search across programming docs
Live preview
Checking API key
How it works
One API request to Exa's /search endpoint:type: "fast", numResults: 5, and contents.highlights: true returns token-efficient highlights related to the input query from the top 5 most relevant web results.
The live preview demonstrates why the highlights parameter should be used over content.text, which returns full webpage text. This feature reduces downstream LLM latency and cost.
Optionally, set contents.highlights.maxCharacters to cap the token budget per article (only when more control is needed). For example: contents: { highlights: { maxCharacters: 2000 } }.
Source code
npm install exa-js
import Exa from "exa-js";
const exa = new Exa("YOUR_API_KEY");
const response = await exa.search("React 19 migration guide", {
type: "fast",
numResults: 5,
contents: { highlights: true },
});
const toolResult = response.results.map((result) => ({
title: result.title,
url: result.url,
highlights: result.highlights,
}));
console.log(toolResult);