Skip to main content

Goal

In a few minutes, you will run one Python script that does the core Tex flow:
  1. Store a turn with remember.
  2. Ask a question with recall.
  3. Print the matching memory, confidence, and token usage.
You need Python 3.9+.
1

Get an API key

Open app.getmetacognition.com/signup, create an account, and copy the key shown once.
You only see the full key when you create it. Store it now in a password manager or secret store.
2

Install the SDK

pip install tex-sdk
On PyPI the package is tex-sdk. In Python you import tex.
3

Run this script

first_call.py
import os
from tex import Tex

tex = Tex(
    api_key=os.environ["TEX_API_KEY"],
    base_url="https://api.getmetacognition.com",
)

tex.conversations.remember(session_id="chat-1", turns=[
    {"role": "user", "text": "I'm allergic to shellfish.",
     "timestamp": "2026-05-08T14:00:00Z"},
])

hits = tex.recall(q="any food restrictions?", session_id="chat-1")
for h in hits.hits.turns:
    print(f"[{h.score:.2f}] {h.text}")

print("confidence:", hits.confidence)
print("usage:", hits.usage.tokens_in, "in /", hits.usage.tokens_out, "out")
export TEX_API_KEY="tex_live_..."
python first_call.py
You should see the shellfish line with a score, plus confidence and token usage. If you get AuthenticationError, check your key and base_url, then use Troubleshooting.

Next

Once the script works, decide how you want to load secrets and whether you want to stay on the SDK.

Load the key from a .env file

Use python-dotenv or your framework’s loader. Keep .env out of git. In production, load TEX_API_KEY from your normal secret store.

Call the API without the SDK

If you do not use the SDK, first exchange your API key for an access token and refresh token. Send Authorization: Bearer ... on ingest and recall. Refresh the access token when it expires. The REST API overview lists the endpoints. The SDK does this for you.

Reads

If confidence is low but you know the memory exists, try mode="deep" once, raise top_k, or ask the question closer to the stored wording. Recall and ranking explains the knobs.
GoalPage
Understand what gets storedHow memory works
Tune recall qualityRecall and ranking
Ship real usersScopes and multi-tenancy
Put a backend in front of a UIProduction chatbot (FastAPI)
Production errorsErrors and retries

How memory works

Turns, observations, entities after each remember.

Scopes for real users

Map session_id (and tenants) to your product.

FastAPI backend

Small service pattern behind a UI.

Errors and retries

What the SDK throws and what it retries.