Client

getUser()

api.getUser() → Promise<User | null>

Who the key belongs to, and what the balance is. The shortest call that proves the whole chain works.

GET /api/auth/mefreefour fields
Using Python?

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

Returns

{
  id: "…",                  // the account id
  email: "you@example.com",
  credits: 10869,           // the balance, at the moment of the call
  pack: "go"                // the plan this account is on
}
{
    "id": "…",                  # the account id
    "email": "you@example.com",
    "credits": 10869,           # the balance, at the moment of the call
    "pack": "go",               # the plan this account is on
}
idstring

The account. Stable; worth logging next to anything you bill back.

emailstring

The address the account was opened with.

creditsinteger

The balance. A reading, not a reservation — see below.

packstring

The plan. It is what decides quotas, not what decides a model's price.

The server holds more than this; the method narrows it to the four fields a program actually branches on. When you need the wider record, updateProfile() returns it.

pack

ValueMeans
freeThe plan an account starts on.
goA paid plan.
starterA paid plan, with more of everything.
enterpriseA paid plan: one balance shared by up to five people.
freemiumAn older name that follows free.

Read the plan to decide what to offer, never to compute a price: a model costs what catalogue() says. What the plan governs is how much room a service has — storages, mailboxes, hosts — and those limits are readable from the service that enforces them.

When it is null

null means the call succeeded and carried no account. It is not what a wrong key looks like: a wrong key fails the session exchange, long before this.

SymptomWhat happened
Unauthorized thrownThe key was refused, or it has been revoked.
unreachable thrownNo answer at baseUrl. Check the address first.
timeout thrownSomething answered too slowly, or not at all.
null returnedThe request worked, and there was no account behind it.

The boot check

This is the call to make at startup. It exercises the key, the exchange, the session cache and an authenticated request, costs nothing, and fails in four distinguishable ways.

import { IaGenify, IaGenifyError, Unauthorized } from "iagenify";

export async function checkIaGenify(api) {
  try {
    const user = await api.getUser();
    if (!user) return { ok: false, why: "no account behind this key" };
    return { ok: true, email: user.email, credits: user.credits };
  } catch (err) {
    if (err instanceof Unauthorized) return { ok: false, why: "key refused or revoked" };
    if (err instanceof IaGenifyError && err.code === "unreachable") {
      return { ok: false, why: `no answer at ${api.baseUrl}` };
    }
    throw err;
  }
}
from iagenify import IaGenifyError, Unauthorized

def check_iagenify(api):
    try:
        user = api.get_user()
        if not user:
            return {"ok": False, "why": "no account behind this key"}
        return {"ok": True, "email": user["email"], "credits": user["credits"]}
    except Unauthorized:
        return {"ok": False, "why": "key refused or revoked"}
    except IaGenifyError as error:
        if error.code == "unreachable":
            return {"ok": False, "why": f"no answer at {api.base_url}"}
        raise

Reading the balance

The number is true when it is read and nothing holds it. A run started a second later spends against the same balance, as does every other process on the account.

Do not gate a run on the balance

Checking first and spending after leaves a window where both succeed and the second one should not have. Give the run a budget instead: it is enforced where the spending happens, not where you looked.

// Fragile: two processes both read 400 and both start a 300-credit run
const { credits } = await api.getUser();
if (credits < 300) throw new Error("not enough");
await agent.run({ message });

// Sound: the ceiling travels with the run, and a shortfall is refused at the debit
const agent = api.agents.create({ runtime: "local", machine: pc, budget: 300 });
await agent.run({ message });
# Fragile: two processes both read 400 and both start a 300-credit run
if api.get_user()["credits"] < 300:
    raise RuntimeError("not enough")
agent.run(message=message)

# Sound: the ceiling travels with the run, and a shortfall is refused at the debit
agent = api.agents.create(runtime="local", machine=pc, model=model, budget=300)
agent.run(message=message)

A shortfall surfaces as a NotEnoughCredits exception carrying what was needed and what was there — catch that rather than predicting it. See Credits.

How often to call it

Every call is a round trip. Reading it once at boot, and again after something that spends, is enough; polling it per request adds latency to your own endpoints and tells you nothing new between spends.

let cached = null;
let readAt = 0;

export async function user(api, maxAgeMs = 60_000) {
  if (!cached || Date.now() - readAt > maxAgeMs) {
    cached = await api.getUser();
    readAt = Date.now();
  }
  return cached;
}
import time

_cached = None
_read_at = 0.0

def user(api, max_age=60):
    global _cached, _read_at
    if _cached is None or time.monotonic() - _read_at > max_age:
        _cached = api.get_user()
        _read_at = time.monotonic()
    return _cached