Get your Exa API key
Overview
The Context API (also called Exa Code) is a powerful tool for coding agents that need fast, efficient web context. It searches over billions of GitHub repos, docs pages, Stack Overflow posts, and more to find the perfect, token-efficient context that agents need to code correctly. This endpoint helps eliminate hallucinations in coding agents by providing real, working code examples from the open source community.Example Use Cases
The Context API excels at finding practical code examples for:- Framework usage: “use Exa search in python and make sure content is always livecrawled”
- API syntax: “use correct syntax for vercel ai sdk to call gpt-5 nano asking it how are you”
- Development setup: “how to set up a reproducible Nix Rust development environment”
- Library implementation: “React hooks for state management examples”
- Best practices: “authentication patterns in NextJS applications”
Response Format
The API returns a JSON response with the following structure:Parameters
query
(required)
- Type:
string
- Description: Search query to find relevant code snippets
- Example:
"how to use React hooks for state management"
- Min Length: 1 character
- Max Length: 2000 characters
tokensNum
(optional)
- Type:
string | integer
- Default:
"dynamic"
- Description: Token limit for the response
- Options:
"dynamic"
: Automatically determine optimal response length50-100000
: Specific number of tokens to return (5000 is good default for most queries, and use 10000 when 5k doesn’t provide enough context)
- Use
"dynamic"
for most queries to get optimal, token-efficient responses - Specify exact token counts when you need precise output length control
- Higher token counts return more comprehensive examples but cost more
Integration Examples
Using with PythonAbout Exa Code
Vibe coding should never have a bad vibe.exa-code
is a huge step towards coding agents that never hallucinate.
When your coding agent makes a search query, exa-code
searches over billions of GitHub repos, docs pages, Stack Overflow posts, and more, to find the perfect, token-efficient context that the agent needs to code correctly. It’s powered by the Exa search engine.
Use with MCP
You can also useexa-code
through the Exa MCP server for seamless integration with AI coding assistants like Claude, Cursor, and other MCP-compatible clients.
The MCP integration provides the same powerful code context search capabilities directly within your development environment without needing to make direct API calls.