---
title: "IdentityHound quickstart"
description: "Configure IdentityHound's roles and resources for your project, sign a principal in with an emailed code, and check what it may do, through HTTP or the SDK."
url: "https://agentpost.tools/docs/identityhound/quickstart"
kind: quickstart
needs:
  - what: "The `api` helper, which sends a request and throws on an error"
    from: "https://agentpost.tools/docs/platform/quickstart.md"
  - what: "A `dev` secret key, `key`, for a project that adopted IdentityHound"
    from: "https://agentpost.tools/docs/platform/quickstart.md"
---

# IdentityHound quickstart

Sign a principal in and check its access through HTTP or the SDK. The script runs start to finish on its own: it reads the sign-in code from your project’s test inbox. Pick the same tab throughout, and run its blocks and the shared blocks in order as one TypeScript script in Node 24: later blocks use values from earlier ones. The [API reference](/docs/identityhound/reference.md) has every operation.

For the SDK variant, install the client:

```sh
npm i @agentpost-tools/identityhound-sdk
```

Both variants use the [Platform quickstart’s](/docs/platform/quickstart.md) `api` helper to read the Platform test inbox.

## Before you start

-   The `api` helper, which sends a request and throws on an error, from [Platform quickstart](/docs/platform/quickstart.md).
-   A `dev` secret key, `key`, for a project that adopted IdentityHound, from [Platform quickstart](/docs/platform/quickstart.md).

This page's code continues the script of the pages above: run its blocks after theirs, in the same file. To run them as a script of their own, first copy each helper from the page that defines it, and set each other value, such as a key or an ID, to one you already have.

## 1\. Configure your project

IdentityHound answers for your project at `/v1/identity`. Your server sets its config with the secret key: the resources your product has and their actions, what each role may do, and the entitlements you sell. Here a `report` can be viewed, edited, shared, and exported, and exporting needs the `reports.export` entitlement.

The shared `identity` helper sends HTTP calls and is also used by the guides that follow:

```ts
const identity = (
  method: string,
  path: string,
  body?: unknown,
  headers?: Record<string, string>,
) => api(method, `/v1/identity${path}`, key, body, headers);
```

Read the config, change the settings you need, and send the whole config back. Use the version you read to catch another write before yours. Agentpost supplies the starting config when your project adopts IdentityHound. The example uses its `admin` and `member` roles.

```ts
const report = {
  actions: ['view', 'edit', 'share', 'export'],
  requiresEntitlement: { export: 'reports.export' },
};
const exportReports = { description: 'Export reports' };

function addPermissions<P extends string>(
  permissions: readonly P[],
  ...added: P[]
): P[] {
  return [...new Set([...permissions, ...added])];
}
```

```ts tab="HTTP"
const { config: settings } = await identity('GET', '/config');
settings.signUp.mode = 'open';
settings.signIn.emailCode.enabled = true;
settings.urls.invitationAccept = 'https://app.example.com/invitations/accept';
settings.resourceTypes.report = report;
settings.entitlements['reports.export'] = exportReports;
settings.roles.admin.permissions = addPermissions(
  settings.roles.admin.permissions,
  'report:*',
);
settings.roles.member.permissions = addPermissions(
  settings.roles.member.permissions,
  'report:view',
  'report:edit',
  'report:export',
);

await identity(
  'PUT',
  '/config',
  {
    ...settings,
    roles: {
      ...settings.roles,
      owner: {
        ...settings.roles.owner,
        permissions: addPermissions(
          settings.roles.owner?.permissions ?? [],
          'report:*',
        ),
      },
    },
  },
  { 'If-Match': String(settings.version) },
);
```

```ts tab="SDK"
import { createClient } from '@agentpost-tools/identityhound-sdk';

const client = createClient({ token: key });
const { config: settings } = await client.config.get();
settings.signUp.mode = 'open';
settings.signIn.emailCode.enabled = true;
settings.urls.invitationAccept = 'https://app.example.com/invitations/accept';
settings.resourceTypes.report = report;
settings.entitlements['reports.export'] = exportReports;
settings.roles.admin.permissions = addPermissions(
  settings.roles.admin.permissions,
  'report:*',
);
settings.roles.member.permissions = addPermissions(
  settings.roles.member.permissions,
  'report:view',
  'report:edit',
  'report:export',
);

await client.config.put(
  {
    ...settings,
    roles: {
      ...settings.roles,
      owner: {
        ...settings.roles.owner,
        permissions: addPermissions(
          settings.roles.owner?.permissions ?? [],
          'report:*',
        ),
      },
    },
  },
  settings.version,
);
```

Send the version, audit fields, and built-in role details as read if you include them. A provider’s client secret stays in place when you send the provider back without it. [Config](/docs/identityhound/reference/config.md) has the field rules and errors.

## 2\. Sign a principal in

A principal signs in with an emailed code: `POST /auth/email-code` sends it, and `POST /auth/email-code/verify` takes it back with the `verificationId`. [Sessions](/docs/identityhound/concepts/sessions.md#how-a-session-starts) has the code’s limits.

This script reads the code from your project’s [Platform test inbox](/docs/platform/concepts/environments.md#test-inbox):

```ts
async function testInbox(to: string) {
  const { messages } = await api(
    'GET',
    `/v1/test-inbox?to=${encodeURIComponent(to)}`,
    key,
  );
  return messages.at(-1);
}
```

```ts tab="HTTP"
async function signIn(email: string) {
  const { verificationId } = await identity('POST', '/auth/email-code', {
    email,
  });
  const { data } = await testInbox(email);
  return identity('POST', '/auth/email-code/verify', {
    email,
    code: data.code,
    verificationId,
  });
}

const ana = await signIn('ana@acme.test');
console.log(ana.signedUp, ana.principal.id); // true prn_…
```

```ts tab="SDK"
async function signIn(email: string) {
  const { verificationId } = await client.auth.requestCode({ email });
  const { data } = await testInbox(email);
  return client.auth.verifyCode({
    email,
    code: data.code,
    verificationId,
  });
}

const ana = await signIn('ana@acme.test');
console.log(ana.signedUp, ana.principal.id); // true prn_…
```

With a real address, whoever holds the inbox reads the code from it, whether an agent or a human. From a browser, your app starts the sign-in with a publishable key instead of the secret key, as [Add email sign-in](/docs/identityhound/guides/email-sign-in.md) shows.

## 3\. Create a workspace

A principal’s own requests carry its session token or API key. Ana creates a workspace, Acme, and becomes its owner:

```ts tab="HTTP"
const { workspace: acme } = await api(
  'POST',
  '/v1/identity/workspaces',
  ana.token,
  { name: 'Acme' },
);
console.log(acme.name); // Acme
```

```ts tab="SDK"
const { workspace: acme } = await client
  .withToken(ana.token)
  .workspaces.create({
    name: 'Acme',
  });
console.log(acme.name); // Acme
```

## 4\. Check access

Before Ana acts on a report, your server asks IdentityHound with `POST /access/check`, naming the principal, the action, and the resource. Each answer has `allowed` and a `reason`; [Access checks](/docs/identityhound/concepts/access-checks.md) explains them:

```ts tab="HTTP"
const check = (action: string) =>
  identity('POST', '/access/check', {
    principalId: ana.principal.id,
    action,
    resource: { type: 'report', id: 'r1', workspaceId: acme.id },
  });
```

```ts tab="SDK"
const check = (action: string) =>
  client.access.check({
    principalId: ana.principal.id,
    action,
    resource: { type: 'report', id: 'r1', workspaceId: acme.id },
  });
```

A denied answer’s `reason` says what to do. The [errors page](/docs/identityhound/errors.md#check-reasons) lists every reason and what to do for each.

## Check it worked

Check whether Ana may edit and export a report:

```ts
const edit = await check('edit');
console.log(edit.allowed, edit.reason); // true workspace_role
const exporting = await check('export');
console.log(exporting.allowed, exporting.reason); // false entitlement_missing
```

Ana’s owner role covers both actions, but Acme holds no `reports.export` entitlement, so the export is denied. To go live, issue a `prd` key, read the config, set your real URLs, send it back, and sign principals in at their real addresses. Next, [Grant a plan](/docs/identityhound/guides/grants.md) grants Acme the missing entitlement.
