> ## Documentation Index
> Fetch the complete documentation index at: https://docs.atlaso.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# SDK calls, usage, and memory routes

> Read a call, page app-user usage, search facts, add a batch, and correct a fact.

These methods use your developer key. `calls.get` may return `call_not_ready`
until the call record is written; set `waitMs` (Python: `wait`) to poll.
Usage pages are read lazily. A user scope's `usage` reads only that user's row.
Search scores compare facts within one answer, not across searches.
For month-to-date cost, pass UTC `start` and `end` dates to `app_users`/`appUsers`.
Each row has `cost_usd` (a decimal string, or null), `cost_complete`, and
`unpriced_calls`. Show an incomplete amount as unknown rather than treating
null as zero. `app_user_label` (TypeScript: `appUserLabel`) is a one-way label,
not the user id your app supplied.

> [tab] Python
>
> ```python theme={null}
> from atlaso import Atlaso
>
> atlaso = Atlaso()
> user = atlaso.for_user("demo-user-42")
> raw = user.openai().chat.completions.with_raw_response.create(
>     model="openai/gpt-6.1-terra",
>     messages=[{"role": "user", "content": "Hello"}],
> )
> call = atlaso.calls.get(raw.headers["x-atlaso-call-id"], wait=10.0)
> for row in atlaso.usage.app_users():
>     print(row["app_user_label"], row["calls"], row["cost_usd"], row["cost_complete"], row["unpriced_calls"])
> mine = user.usage()
> assert mine is not None
>
> texts = ["Lives in Pune", "Has a cat"]
> batch = user.memory.add_many(texts)
> if any(item["status"] == "not_saved" for item in batch.results):
>     batch = user.memory.add_many(texts, idempotency_key=batch.idempotency_key)
> saved = [item["fact"] for item in batch.results if item["status"] == "added"]
> rejected = [item for item in batch.results if item["status"] == "rejected"]
> hits = user.memory.search("cat", limit=5)
> updated = user.memory.update(saved[0]["id"], "Lives in Mumbai") if saved else None
> print(call["id"], mine["app_user_label"], hits[0].score if hits else None,
>       updated.replaces if updated else None, len(rejected))
> ```

> [tab] TypeScript
>
> ```typescript theme={null}
> import OpenAI from "openai";
> import { Atlaso } from "atlaso";
>
> const atlaso = new Atlaso({ OpenAI });
> const user = atlaso.forUser("demo-user-42");
> const raw = await user.openai().chat.completions.create({
>   model: "openai/gpt-6.1-terra",
>   messages: [{ role: "user", content: "Hello" }],
> }).withResponse();
> const call = await atlaso.calls.get(raw.response.headers.get("x-atlaso-call-id")!, { waitMs: 10_000 });
> for await (const row of atlaso.usage.appUsers()) console.log(row.appUserLabel, row.calls, row.cost_usd, row.cost_complete, row.unpriced_calls);
> const mine = await user.usage();
>
> const texts = ["Lives in Pune", "Has a cat"];
> let batch = await user.memory.addMany(texts);
> if (batch.results.some(item => item.status === "not_saved")) {
>   batch = await user.memory.addMany(texts, { idempotencyKey: batch.idempotencyKey });
> }
> const saved = batch.results.filter(item => item.status === "added" && item.fact).map(item => item.fact!);
> const rejected = batch.results.filter(item => item.status === "rejected");
> const hits = await user.memory.search("cat", { limit: 5 });
> const updated = saved.length ? await user.memory.update(saved[0].id, "Lives in Mumbai") : null;
> console.log(call.id, mine?.appUserLabel, hits[0]?.score ?? null, updated?.replaces ?? null, rejected.length);
> export { call, batch, hits, updated };
> ```

`add` and `addMany` send an `Idempotency-Key` automatically. Each logical save
gets one key, reused by the SDK for its retries. If the outcome remains unknown,
send the same text or batch again with the returned `idempotencyKey` (Python:
`idempotency_key`) within 24 hours. A new key can create another fact.

For a batch, inspect every item's `status`: `added` has a fact, `rejected` is a
final refusal, and `not_saved` can be retried with the **same full list and key**.
Keep the successful IDs; do not send only the failed items with that key. If a
batch reply is malformed, the typed protocol error carries the key for recovery.

`update` creates a new fact id and returns `replaces`. The old id is hidden from
list and recall. Updating that old id again returns `fact_replaced` (409), with
`replacedBy` (Python: `replaced_by`) on the typed error.

## Calls still running

A call's record is written once the call finishes. Until then `calls.get`
answers `call_not_ready` for the first two minutes, then `call_not_found`; the
`in_progress` and `interrupted` outcomes are not used today.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.