Skip to main content
If you only need a working client, start with the Quickstart. Come back here when you are wiring secrets, using your own JWT, or rotating keys.
The SDK starts with your API key. On the first real call, it exchanges that key for short-lived access and refresh tokens. After that, the client keeps the tokens in memory, refreshes them when needed, and retries the original call. Most apps never need to handle raw token strings.

Flow

The diagram shows what happens when your app calls the SDK.

Steps in the SDK

Auth mode

Most apps use an API key. Use one of the other modes only when you already manage auth somewhere else.

Key storage

Local dev

.env file. Add it to .gitignore. Load with python-dotenv.

Docker / Kubernetes

Secret manager mounted as TEX_API_KEY env var.

Vercel / Netlify

Project environment variable named TEX_API_KEY.

GitHub Actions

Repository secret exposed as ${{ secrets.TEX_API_KEY }}.
The SDK reads TEX_API_KEY from the environment automatically when api_key= is omitted.

Rotation

2

Roll out

Deploy with TEX_API_KEY=<key B>.
3

Verify

Check the dashboard’s last_used_at value or your own logs.
4

Revoke key A

Click Revoke on the old key. JWTs created from key A can keep working for up to 24h, so customers do not see a sudden failure.

Bad key

from tex import Tex, AuthenticationError

try:
    tex = Tex(api_key="tex_live_BOGUS", base_url="https://api.getmetacognition.com")
    tex.usage.today()
except AuthenticationError as e:
    print(e.status_code)   # 401
    print(e.message)       # "Invalid API key" or similar
    print(e.request_id)    # Quote this when filing tickets
Token lifetimes. Access JWTs last 24h. Refresh JWTs last 7d. After that, the SDK exchanges your API key again. To invalidate tokens, revoke the API key they came from.

Next: multi-user memory

How org_id / user_id / session_id partition memory.