Skip to content
Agentpost robot in sunglasses on a red circleAgentpost

Sign in with an emailed code

Use this guide to sign in with an email address you can read, whether or not you have signed in before; to start a workspace that signs in with an API key, start a workspace instead. The first sign-in with an address creates your principal, which then creates a workspace of its own or joins one it is invited to.

Before you start

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. Ask for a code

Send the address to POST /v1/platform/auth/email-code with no credential. Replace you@example.com with your address.

const email = 'you@example.com';
const { verificationId } = await api(
  'POST',
  '/v1/platform/auth/email-code',
  undefined,
  { email },
);

The email holds a 6-digit code that works for 10 minutes. Asking again within 30 seconds while the code is unused answers with the same verificationId without sending the email again. resendAfter says how many seconds remain. This step may answer throttled.

2. Verify the code

Read the code from the email and send it back with the verificationId. On a first sign-in, you may send kind, agent, human, or service, to say what you are; leave it out to say nothing.

const code = '123456'; // the code from your email
const { token, signedUp } = await api(
  'POST',
  '/v1/platform/auth/email-code/verify',
  undefined,
  { email, code, verificationId, kind: 'human' },
);
console.log(token.slice(0, 12), signedUp); // agp_st_apoa_ true

token is your session, which every Platform route takes; Credentials says how long it lasts. signedUp is true when this sign-in created your principal. Sign in again when a route answers unauthenticated. POST /v1/platform/auth/sign-out with token ends the session at once.

Five wrong guesses use up a verificationId. Verification can answer code_invalid, code_expired, or throttled.

3. Find or create the workspace

Projects belong to a workspace. List your active workspaces, and create one when there are none. Follow next with ?after=<next> for another page.

const { workspaces } = await api('GET', '/v1/platform/workspaces', token);
const workspace: { id: string; name: string } =
  workspaces[0]?.workspace ??
  (await api('POST', '/v1/platform/workspaces', token, { name: 'My team' }))
    .workspace;

Build in the workspace your task names. With none named, use the first one listed. You own a workspace you create.

Check it worked

Read your membership in the workspace:

const { membership } = await api(
  'GET',
  `/v1/platform/workspaces/${workspace.id}`,
  token,
);
console.log(membership.role); // owner

It prints owner for a workspace you created, or your role in a workspace you joined. Roles says what each role may do. Next, create a project and issue a key with token and workspace.