Context Endpoint Reference
Code-focused retrieval surface viaPOST /context.
Canonical Docs Links
- Base docs URL:
https://exa.ai/docs - Context reference:
/reference/context
Contents
- Overview
- Request shape
- Parameters
- Response shape
- When it beats general search
- Integration examples
- Critical pitfalls
Overview
The context endpoint, also called Exa Code, is tuned for coding agents and developer workflows. It searches across repositories, docs pages, Stack Overflow, and related technical sources to return token-efficient code context. When the task is code-specific but you still want ranked web results rather than a formatted context blob, prefer/search with type: "fast".
Use it when the query is about:
- framework or library usage
- API syntax examples
- implementation patterns
- setup or configuration guidance
- coding best practices sourced from real code and docs
Request Shape
Parameters
Use
"dynamic" for most cases. Set an explicit token count only when you need tighter output-size control.
Response Shape
Typical fields:requestIdqueryresponseas markdown/code contextresultsCountcostDollarssearchTimeoutputTokens
response field is already formatted as usable code context, not as a ranked list of URLs.
When It Beats General Search
Prefer the context endpoint over the search endpoint when:- code examples are more important than general web pages
- the consumer is a coding agent or developer tool
- token-efficient technical context is the main goal
- the query is general web research, not code-specific
- you need specialized categories such as
peopleorcompany - you need result-level content extraction or synthesized
outputSchemabehavior
Integration Examples
Python:Critical Pitfalls
tokensNumbelongs to the context endpoint, not to the search or contents endpoints.- Do not assume the response looks like ranked search results; the main payload is the formatted
responsefield. - Use the search endpoint instead when the task is general web retrieval rather than code retrieval.