Quickstart
Version 2026-10-15 · effective Oct 15, 2026
Before you start
Create a test key in the portal, then put it in an environment variable. Never paste the key itself into code you share.
export EXEGESY_API_KEY="ex_test_<your-key>"Make your first call
Choose the tab for your language. Each one sends the same search. The Python SDK tab needs the SDK installed first; the Python SDK section below shows how.
With a test key (`ex_test_`) the search runs, but it returns no passages: the answer is only the end line, marked `x-exegesy-simulated: true`. Use a live key to see results.
curl https://api.exegesy.com/v1/search \
-H "Authorization: Bearer $EXEGESY_API_KEY" \
-H "Content-Type: application/json" \
-d '{"query": "limitation period for written contracts", "top_k": 5}'What comes back
A search answers with `application/x-ndjson`: one JSON object per line. Each `passage` line is a result, with an `id`, a `score`, the passage (`snippet`) and its source metadata. Each passage carries its id, text and citation; there is no separate document endpoint.
The last line tells you how the search ended. When the search completed, it is `{"type":"end","billableBytes":…,"status":"ok"}`. When it failed after it had started, it is `{"type":"error","code":…,"message":…}` instead, and the HTTP status is already `200`. Read the last line; do not rely on the status code alone. The Python SDK reads this for you and raises on a failed search.
If a call fails before the answer starts, the body is the error envelope described in Errors. Read `code` in your code; do not parse `message`.
Python SDK
The SDK wraps the search: it reads the answer, checks the last line, and raises on any failure. It has a sync client (`Exegesy`) and an async one (`AsyncExegesy`) that behave the same. It needs Python 3.10 or later.
pip install exegesyStreaming
By default the SDK waits for the whole answer. Pass `stream=True` to receive passages as they arrive. This changes how the SDK reads the answer, not what the server receives.
from exegesy import Exegesy
with Exegesy() as client, client.search("limitation period", stream=True) as stream:
for passage in stream:
print(passage.citation, passage.text)
print("billable bytes:", stream.billable_bytes) # known once the stream has endedRead the stream to its end, or use it as a context manager, so the connection is released. A stream can be iterated once. `billable_bytes` is known only after the last line.
Handling errors
Branch on `code`, not `message`. The SDK never retries a search for you, and a retry is a new, charged call.
from exegesy import APIError, Exegesy, StreamError, TransportError
with Exegesy() as client:
try:
result = client.search("limitation period for written contracts", top_k=5)
except APIError as err:
if err.code == "insufficient_balance":
... # top up or raise the credit limit
elif err.retryable:
... # 429 or 5xx: a transient failure; retry only if you accept the charge
else:
raise
except StreamError as err:
... # the answer was incomplete or failed part-way; err.code is set when the server sent one
except TransportError:
... # network failure; the call may still have been billed