Construction does no I/O. Nothing is validated against the server, no session is exchanged, no file is read. The first call that needs an identity is what reaches the network — which is why a wrong key surfaces there, and not here.
- It does not contact the server, so a bad
baseUrlis silent until the first call. - It does not read the session cache — that is lazy, on first use.
- It does detect the runtime, the capabilities and the framework, synchronously, from globals already present.
- It does refuse immediately when it has neither a key nor a session store.
Parameters
apiKeystringrequired*Your key. Required unless you pass a storage that already holds a session.
baseUrlstringWhere the API lives: https://api.iagenify.com. Set it here, or set IAGENIFY_API_URL and leave it out.
storageobjectA replacement session store — { read, write, clear }. See below and Session storage.
sessionPathstringNode only. Where the session file goes instead of ~/.iagenify/session. One path per account.
appNamestringNames the caller. It travels with the key exchange and takes part in the deduplication of concurrent exchanges.
timeoutintegerDefault deadline in milliseconds for the calls that have one. 0 removes it. See Timeouts.
The constructor throws a plain Error, synchronously, before anything else is built. It is the one failure you get without awaiting — which makes it the one you can assert in a unit test without a server.
new IaGenify();
// Error: IaGenify requires an API key.
new IaGenify({ apiKey: "" });
// same — an empty string is not a key
new IaGenify({ storage: myStore });
// fine: no key, but a store that may already hold a sessionIaGenify()
# ValueError: IaGenify requires api_key or a custom session storage.
IaGenify(api_key="")
# same — an empty string is not a key
IaGenify(storage=my_store)
# fine: no key, but a store that may already hold a sessionWhat the instance carries
| Property | Type | What it is |
|---|---|---|
| baseUrl | string | The address that won: the one passed, else the one in the environment. |
| env | string | node · browser · worker · unknown |
| capabilities | object | What this runtime can do: shell, filesystem, persistentStorage, http |
| framework | string | node · next.js · gatsby · vite · browser |
All three detections are read once, at construction, and never refreshed. Full tables on env · capabilities · framework.
The resources
Fourteen, each one a branch of this reference. They share the client, the session and the timeout — constructing the instance is what configures all of them.
| Resource | What it reaches |
|---|---|
| api.auth | The current session: end it, revoke another, update the profile. |
| api.keys | API keys: list, create, revoke. |
| api.models | Model sessions, and one stateless turn. |
| api.memory | The agent's short notes, kept between sessions. |
| api.files | Files on the account, and on the machine. |
| api.storage | Storages: connect one, create one, register a device. |
| api.cloud | Usage and add-ons for IaGenify Cloud. |
| api.tools | Search, fetch, convert, documents, media — callable directly. |
| api.agents | Agents, and the skills and subagents they are given. |
| api.mcp | MCP servers connected to the account. |
| api.workflows | Workflows: define, run, resume. |
| api.domains | Attached domains and their DNS. |
| api.mail | Mailboxes, messages, contacts. |
| api.hosts | Sites, apps and functions put online. |
Methods on the client itself
Four, and all four are cheap: no credit is spent and nothing is created.
await api.getUser(); // { id, email, credits, pack } — or null
await api.catalogue(); // every model the account can call, with its price
await api.getStorage(); // the account's default storage — or null
await api.session(); // { id, storageId } — or null before the first exchangeapi.get_user() # {"id", "email", "credits", "pack"} — or None
api.catalogue() # every model the account can call, with its price
api.get_storage() # the account's default storage — or None
api.session() # {"id", "storageId"} — or None before the first exchangeReplacing the session store
The default store is picked from the runtime. Pass storage and yours is used instead — three async methods, and that is the whole contract.
const store = {
// Optional: it travels with the key exchange. Defaults to "custom".
storageType: "redis",
async read() {
const raw = await redis.get(`iagenify:${tenant}`);
return raw ? JSON.parse(raw) : null; // null when nothing is cached
},
async write(data) {
await redis.set(`iagenify:${tenant}`, JSON.stringify(data));
},
async clear() {
await redis.del(`iagenify:${tenant}`);
},
};
const api = new IaGenify({ apiKey, storage: store });import json
class RedisStore:
# Optional: informational. Defaults to "custom".
storage_type = "redis"
def read(self):
raw = redis.get(f"iagenify:{tenant}")
return json.loads(raw) if raw else None # None when nothing is cached
def write(self, data):
redis.set(f"iagenify:{tenant}", json.dumps(data))
def clear(self):
redis.delete(f"iagenify:{tenant}")
api = IaGenify(api_key=api_key, storage=RedisStore())read()must answernull— not throw, notundefined— when there is nothing cached.write()is handed the whole session object. Store it opaquely; the shape is not yours to interpret.- What you store is credential material. Give it the protection a token deserves, and never log it.
- A store whose
write()does not actually persist still works — it just exchanges the key on every call, which is slower and makes a new session each time.
Where to construct it
A server, one account
Build it once, at module scope, and import it. The session cache is shared inside the process anyway, so a second instance buys nothing.
// iagenify.js
import { IaGenify } from "iagenify";
export const api = new IaGenify({
apiKey: process.env.IAGENIFY_API_KEY,
baseUrl: process.env.IAGENIFY_API_URL,
appName: "invoice-worker",
});# iagenify_client.py
import os
from iagenify import IaGenify
api = IaGenify(
api_key=os.environ["IAGENIFY_API_KEY"],
base_url=os.environ.get("IAGENIFY_API_URL"),
app_name="invoice-worker",
)A server, several accounts
This is the case that needs care. Two clients sharing a session file overwrite each other, so give each one its own path — and its own appName if you want them told apart in a session list.
const clients = new Map();
function clientFor(tenant) {
if (!clients.has(tenant)) {
clients.set(tenant, new IaGenify({
apiKey: secrets[tenant],
sessionPath: `/var/lib/app/sessions/${tenant}`,
appName: `worker-${tenant}`,
}));
}
return clients.get(tenant);
}clients = {}
def client_for(tenant):
if tenant not in clients:
clients[tenant] = IaGenify(
api_key=secrets[tenant],
session_path=f"/var/lib/app/sessions/{tenant}",
app_name=f"worker-{tenant}",
)
return clients[tenant]Each client writes its session over the other's. Nothing is lost — the key is re-exchanged — but you get a new session on nearly every call, and session lists fill with short-lived entries. One path per account.
An isolate that does not persist
Where there is no durable storage, the session lives in memory for as long as the isolate does. Construct per request and let it exchange once; or hand it a store you control, and the session survives the isolate.
A page
Anything shipped to a browser is readable by whoever opens it, and a key is the account. Build the client on your server, expose only the operations your app needs, and let the page call those.
Four things that look like bugs and are not
| What you see | What it is |
|---|---|
| The constructor succeeded with a wrong key | Nothing is verified at construction. The first call fails instead. |
| unreachable on every call in production | baseUrl is not what you meant. Read api.baseUrl and compare. |
| A new session on every call | The session store is not persisting — a read-only disk, or a store whose write is a no-op. |
| api.env is node inside a page | A bundler shimmed process. Node is tested first, so it wins. |