---
title: "Create a project and issue a key"
description: "Create a project in a workspace, adopt the services it uses, and issue a secret key for its server and a publishable key for its browser or native app code."
url: "https://agentpost.tools/docs/platform/guides/keys"
kind: guide
needs:
  - what: "The `api` helper that sends each request"
    from: "https://agentpost.tools/docs/platform/quickstart.md"
  - what: "Your credential, `token`, and the workspace to build in, `workspace`"
    from: "https://agentpost.tools/docs/platform/guides/sign-up.md"
---

# Create a project and issue a key

[Projects](/docs/platform/concepts/projects.md) explains when to create a project; [Secret keys](/docs/platform/concepts/secret-keys.md) and [Publishable keys](/docs/platform/concepts/publishable-keys.md) say which key each caller sends.

`token` is your API key, from [Start a workspace](/docs/platform/guides/sign-up.md), or your session, from [Sign in with an emailed code](/docs/platform/guides/sign-in.md). Both pages also give `workspace`. Creating a project and issuing keys take the role of an owner or an admin; [Roles](/docs/platform/concepts/workspaces.md#roles) lists each role’s permissions.

## Before you start

-   The `api` helper that sends each request, from [Platform quickstart](/docs/platform/quickstart.md).
-   Your credential, `token`, and the workspace to build in, `workspace`, from [Start a workspace](/docs/platform/guides/sign-up.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\. Create a project

Send `POST /v1/projects` with the workspace and a name of 1 to 120 characters:

```ts
const { project } = await api('POST', '/v1/projects', token, {
  workspaceId: workspace.id,
  name: 'My app',
});
console.log(project.id.slice(0, 4), project.services); // prj_ []
```

A workspace holds 100 projects; past that, creating one answers [`quota_exceeded`](/docs/errors.md#quota_exceeded). A role without the permission answers [`forbidden`](/docs/errors.md#forbidden).

## 2\. Adopt a service

A project reaches a service once it adopts it. Send the service’s code name, such as `identityhound`:

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

Send one request for each service the project uses. Agentpost writes the [starting config](/docs/platform/concepts/projects.md#adopting-a-service) in both environments. Adopting a service the project already has changes nothing and answers `adopted: false`. This step answers [`invalid_request`](/docs/errors.md#invalid_request) for a service Agentpost doesn’t host and lists the hosted services in `details.hosted`.

## 3\. Issue a secret key

Issue a secret key for the project’s server in its `dev` environment. `name` says what the key is for:

```ts
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: store it where the server reads it. For production, send `environment: 'prd'`. This step may answer [`invalid_request`](/docs/errors.md#invalid_request).

## 4\. Issue a publishable key

A browser starts a sign-in with a publishable key. Issue one with `kind: 'publishable'` and the origins the browser code runs on:

```ts
const { key: publishableKey } = await api(
  'POST',
  `/v1/projects/${project.id}/keys`,
  token,
  {
    name: 'web',
    environment: 'dev',
    kind: 'publishable',
    allowedOrigins: ['https://app.example.com', 'http://localhost:3000'],
  },
);
console.log(publishableKey.slice(0, 8)); // pk_test_
```

Origins follow [these rules](/docs/platform/concepts/publishable-keys.md#origins); [Update a publishable key](/docs/platform/reference/keys.md#update-a-publishable-key) changes them later. For a native app, such as an iOS, Android, or Expo app, issue a key of its own with `allowNativeApps: true`, which may list no origins; [Native apps](/docs/platform/concepts/publishable-keys.md#native-apps) says what it reaches. Issuing the key may answer [`invalid_request`](/docs/errors.md#invalid_request).

## Check it worked

List the project’s keys:

```ts
const { keys } = await api('GET', `/v1/projects/${project.id}/keys`, token);
const kinds = keys.map((k: { kind: string }) => k.kind);
console.log(kinds); // [ 'secret', 'publishable' ]
```

Each key’s `prefix` tells keys apart. The [keys reference](/docs/platform/reference/keys.md) has every field.
