Get an API key
Concepts

Session storage

Where the cached session is kept is decided by the runtime — a file, localStorage, or memory. You can replace it with three methods.

read · write · clear
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

What you get by default

RuntimeKept inSurvives
node~/.iagenify/session, in a directory created with mode 0700restarts
browserlocalStorage, under iagenify_sessionreloads, per origin
workermemoryonly the isolate

In Node, sessionPath moves the file. Everywhere else the location is fixed, and the way to change it is to supply your own storage.

Supplying your own

Three async methods. read returns what was last written, or null; write stores it; clear removes it.

const api = new IaGenify({
  apiKey,
  storage: {
    storageType: "custom",          // reported at exchange; informational
    async read()      { return JSON.parse((await redis.get(key)) || "null"); },
    async write(data) { await redis.set(key, JSON.stringify(data)); },
    async clear()     { await redis.del(key); },
  },
});
import json

class RedisSession:
    storage_type = "custom"          # informational
    def read(self): return json.loads(redis.get(key) or "null")
    def write(self, data): redis.set(key, json.dumps(data))
    def clear(self): redis.delete(key)

api = IaGenify(api_key=api_key, storage=RedisSession())
read must return null, not throw

A first run has nothing stored. Catch inside read and return null, or the very first call fails instead of exchanging the key.

A client with no key at all

If your storage already holds a session, you can build a client without a key. Pass neither and the constructor refuses, naming both ways out.

// Valid: the session comes from the store
const api = new IaGenify({ storage: myStore });

// Refused at construction
new IaGenify({});
// Error: IaGenify requires an API key. Pass { apiKey } or provide a custom
// storage with an existing session.
# Valid: the session comes from the store
api = IaGenify(storage=my_store)

# Refused at construction
IaGenify()
# ValueError: IaGenify requires api_key or a custom session storage.

Keeping tenants apart

const clientFor = (tenant) => new IaGenify({
  apiKey: keyOf(tenant),
  appName: "billing-worker",
  storage: {
    storageType: "custom",
    async read()      { return JSON.parse((await kv.get(`sess:${tenant}`)) || "null"); },
    async write(data) { await kv.put(`sess:${tenant}`, JSON.stringify(data)); },
    async clear()     { await kv.delete(`sess:${tenant}`); },
  },
});
import json

class TenantSession:
    def __init__(self, tenant): self.key = f"sess:{tenant}"
    def read(self): return json.loads(kv.get(self.key) or "null")
    def write(self, data): kv.set(self.key, json.dumps(data))
    def clear(self): kv.delete(self.key)

def client_for(tenant):
    return IaGenify(api_key=key_of(tenant), app_name="billing-worker", storage=TenantSession(tenant))