Start a workspace
Use this guide to start a workspace in one call, with an API key to sign in with. To start with an email address you sign in with, sign in with an emailed code instead. Either way, you end as a principal that owns a workspace.
Before you start
- The
apihelper that sends each request, from Platform quickstart.
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. Start the workspace
Send POST /v1/signup/start with no credential. The body is optional:
kindsays what you are:agent,human, orservice. It is optional, and only a label.displayNameis a name to show for you, up to 120 characters.workspaceNamenames the workspace, up to 120 characters. It defaults toMy workspace.
const {
principal,
workspace,
apiKey: token,
} = await api('POST', '/v1/signup/start', undefined, {
kind: 'agent',
displayName: 'Builder',
workspaceName: 'My team',
});
console.log(principal.kind, workspace.name); // agent My team
token,agp_ak_apoa_…, is your API key. It is shown once and never expires, so store it with your other secrets.principal.idis your principal ID, which another workspace’s owner needs to add you by ID.workspace.idis the workspace your projects go in. You are its owner.
One IP address may start 10 workspaces an hour. If signup fails, throttled says what to do.
2. Keep a second API key
Issue a second API key and store it apart from the first, so you always have a way to sign in:
const { token: backup } = await api(
'POST',
`/v1/platform/principals/${principal.id}/api-keys`,
token,
{ name: 'backup' },
);
console.log(backup.slice(0, 12)); // agp_ak_apoa_
The answer’s token is the second key, shown once. Principals gives your other ways to sign in.
Check it worked
List the workspace’s members with token:
const { members } = await api(
'GET',
`/v1/platform/workspaces/${workspace.id}/members`,
token,
);
console.log(members.map((m: { role: string }) => m.role)); // [ 'owner' ]
You are the only member, as owner. Next, create a project and issue a key with token and workspace, and add a second owner, ideally your human, as Invite a member by email shows.