Skip to content
Agentpost robot in sunglasses on a red circleAgentpost

Platform quickstart

This script starts a workspace you own, creates a project that uses IdentityHound, issues a secret key, and makes a first service call. A project adopts other services the same way.

The examples are TypeScript for Node 24 and use only fetch. Run the blocks in order as one script: later blocks use values from earlier ones. Save the script in a file ending in .mts, such as quickstart.mts, and run it with node quickstart.mts: Node 24 runs TypeScript with no build step.

1. Send requests

Define api to send JSON requests and report errors under the rules in API basics. The error it throws carries the body’s error, so code that expects an error can read its code and details.

const API = 'https://api.agentpost.tools';

async function api(
  method: string,
  path: string,
  token?: string,
  body?: unknown,
  headers: Record<string, string> = {},
) {
  const response = await fetch(`${API}${path}`, {
    method,
    headers: {
      ...(token ? { authorization: `Bearer ${token}` } : {}),
      ...(body === undefined ? {} : { 'content-type': 'application/json' }),
      ...headers,
    },
    body: body === undefined ? undefined : JSON.stringify(body),
  });
  const text = await response.text();
  const json = text ? JSON.parse(text) : {};
  if (!response.ok)
    throw Object.assign(
      new Error(
        `${method} ${path}: ${json.error?.code} ${json.error?.message} (${json.error?.docs})`,
      ),
      { error: json.error },
    );
  return json;
}

2. Start a workspace

Start a workspace with POST /v1/signup/start and no credential:

const {
  principal,
  workspace,
  apiKey: token,
} = await api('POST', '/v1/signup/start', undefined, {
  workspaceName: 'My team',
});
console.log(workspace.name, workspace.projects); // My team { used: 0, max: 100 }
  • principal is you: a principal that owns the workspace.
  • workspace is the workspace your projects go in.
  • token, agp_ak_apoa_…, is your API key. It is shown once and it is how you sign in, so keep it with your secrets. Send it to every Platform route.

Start a workspace has the options, such as saying what kind of principal you are, and the errors.

3. Create a project

Create a project and adopt IdentityHound; Create a project and issue a key has the options:

const { project } = await api('POST', '/v1/projects', token, {
  workspaceId: workspace.id,
  name: 'My app',
});
const adopted = await api(
  'POST',
  `/v1/projects/${project.id}/services`,
  token,
  { service: 'identityhound' },
);
console.log(adopted.project.services); // [ 'identityhound' ]

4. Issue a secret key

Issue a secret key for your server in the project’s dev environment:

const { key } = await api('POST', `/v1/projects/${project.id}/keys`, token, {
  name: 'server',
  environment: 'dev',
});
console.log(key.slice(0, 8)); // sk_test_

key is shown once: keep it on your server.

5. Make your first call

Use the project’s secret key to read the IdentityHound config Agentpost supplied when the project adopted it:

const { config } = await api('GET', '/v1/identity/config', key);
console.log(config.version, config.signUp.mode); // 1 open

Check it worked

Read the workspace with token:

const { workspace: current } = await api(
  'GET',
  `/v1/workspaces/${workspace.id}`,
  token,
);
console.log(current.projects); // { used: 1, max: 100 }

Use this project’s key in the quickstart for the service you want to use next. Follow that quickstart’s adoption step if the project hasn’t adopted the service yet.

You are the workspace’s only owner, so add a second owner before you build further, ideally your human, with an email address:

  • A second owner keeps the workspace reachable. A sole owner that loses its only way to sign in can’t get back in, and the workspace is left with no owner. Workspaces says what stays reachable.
  • Agentpost emails its notices to the owners’ addresses, such as when a key is issued or a sending domain verifies. Each is one delivery of a workspace event, which every member reads.

Next, invite a member by email with the role owner. The invitee becomes an owner when they accept.