Python SDK
The neurophic package is a typed client for the REST API. It sends requests with httpx, returns pydantic models, ships a sync and an async client, and needs Python 3.10 or later.
Install
pip install neurophic
uv add neurophic
poetry add neurophic
Create a client
from neurophic import Neurophic
client = Neurophic(
api_key="nph_...",
base_url="https://api.neurophic.ai",
timeout=10,
)
api_key: a project key. Falls back to theNEUROPHIC_API_KEYenvironment variable; if neither is set the constructor raisesValueError.base_url: where requests go. Falls back toNEUROPHIC_BASE_URL, then the production API.timeout: seconds the client waits for each step of a request, anhttpx.Timeout, orNonefor no limit. Defaults to 30 seconds.http_client: your ownhttpx.Client, for a proxy or event hooks. It keeps its own timeout unless you settimeout.
Use the client as a context manager, or call close(), to release its connections.
identifier as the first argument of every call. Keep keys server-side; see Get started > API keys.Every date argument takes an ISO 8601 string, a date or a datetime; a naive datetime is sent as UTC. Wherever a role or rerank mode is accepted, pass a plain string or the MemoryRole and RerankMode enums.
Memory
Ingest
Stores a memory. The write is queued, not written on the spot.
receipt = client.ingest(
"user-123",
"Prefers window seats on long flights.",
name="Ada",
occurred_at="2026-08-12T09:12:00Z",
role="user",
)
print(receipt.id, receipt.status) # the memory id once the write is processed, "queued"
occurred_at: when the content was said. Defaults to now; set it when backfilling history, oldest first.role: who said it,userby default. Store your agent's own replies asassistant; they never replace what the person said.
Learn more under API reference > Ingest.
Context
Fetches a short, ready-to-prompt summary for a query, as a string. It is empty when nothing is relevant.
context = client.context(
"user-123",
"Booking a flight to Lisbon next month",
sources=True,
rerank="fast",
)
roles: whose words to include, the person's own by default. Add"assistant"for what your agent said.sources: also return the original turns, each once: the turns behind the block, plus up to five that match the query directly.rerank: a second ranking stage before the cut,fastorthorough. Off by default; a paid mode adds the reranking model's cost to the request.
Learn more under API reference > Context.
Retrieve
Searches memory. The return type follows format: Markdown ready to drop into a prompt by default, the same results as typed objects with format="json".
markdown = client.retrieve("user-123", "travel preferences")
result = client.retrieve(
"user-123",
"travel preferences",
goal="book a flight for the user",
since="2026-08-01T00:00:00Z",
roles=["user", "assistant"],
limit=10,
reference_date="2026-08-19",
format="json",
sources=True,
rerank="fast",
)
for memory in result.memories:
print(memory.content)
since,until: only memories observed in that window.roles: whose words to return, the person's own by default. Add"assistant"for what your agent said; patterns are always the person's.sources: also return the original turns, each once, asresult.sources, withsource_idon each memory they were taken from.rerank: a second ranking stage before the cut,fastorthorough. Off by default; a paid mode adds the reranking model's cost to the request, andlimitstill applies after it.reference_date: the day relative time in the query, such as "last week", is read from. Defaults to today.
With format="json" the result is a RetrieveResult holding memories, observations, patterns and sources, as lists of RetrievedMemory, RetrievedObservation, RetrievedPattern and RetrievedSource. Timestamps are datetime, event_date is a date, and each role is a MemoryRole, or plain text for a role this version of the client does not know. relevance is None when rerank was used; the order of the list is then the ranking.
Learn more under API reference > Retrieve.
List
Pages through every memory stored for an identifier, newest first.
page = client.memory.list("user-123", page=2, per_page=10)
print(page.total)
print(page.memories[0].content)
Learn more under API reference > List.
Get
Fetches one memory by id.
memory = client.memory.get("5f1d2c3e-...", identifier="user-123")
Learn more under API reference > Get.
Delete
Deletes one memory by id.
client.memory.delete("5f1d2c3e-...", identifier="user-123")
Pass restore_previous=True to delete only this version and restore the one it superseded.
Learn more under API reference > Delete.
Async
AsyncNeurophic has the same calls and options, awaited. Close it with aclose(), or use it as an async context manager.
from neurophic import AsyncNeurophic
async with AsyncNeurophic() as client:
await client.ingest("user-123", "Prefers window seats on long flights.")
context = await client.context("user-123", "Booking a flight to Lisbon next month")
Errors
Every HTTP and transport failure raises neurophic.NeurophicError, carrying:
0 for timeouts and connection failures.VALIDATION_ERROR; see API reference > Errors. Compare it to the ErrorCode constants. UNKNOWN when the body is not the standard envelope, for example a plain-text 413 from the edge.VALIDATION_ERROR, each with field and message.Retry-After header when the API sent one.A response outside the 2xx range raises the subclass for its status, so you can catch what you expect by name:
| Status | Class |
|---|---|
| 400 | BadRequestError, with details on a validation error |
| 401 | AuthenticationError |
| 402 | InsufficientCreditError, with balance and required |
| 403 | PermissionDeniedError |
| 404 | NotFoundError |
| 409 | MemoryLimitError |
| 429 | RateLimitError |
| 5xx | InternalServerError, and ServiceUnavailableError for 503 |
Three more subclasses cover failures that never reach the API, or that it did not answer as expected:
NeurophicTimeoutError. The client stopped waiting; the API may still have handled the request.NeurophicConnectionError. A network failure, with the cause as__cause__.InvalidResponseError. A success status with a body the client cannot read, not JSON or not the expected shape. It usually means the API has changed and the client needs updating.
from neurophic import BadRequestError, InsufficientCreditError, Neurophic, NeurophicError, NeurophicTimeoutError
client = Neurophic()
try:
client.ingest("user-123", "Prefers window seats.")
except NeurophicTimeoutError:
print("No reply in time; the write may still go through.")
except BadRequestError as error:
print(error.message, error.details)
except InsufficientCreditError as error:
print(f"Balance {error.balance}, required {error.required}. Top up the project.")
except NeurophicError as error:
print(error.status_code, error.code, error.message)
Licence
The SDK is MIT-licensed; use of the API it calls is governed by the Terms of Use.