> ## Documentation Index
> Fetch the complete documentation index at: https://docs.goyappr.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Issue an API key

> Issues a new key and returns its secret **once**. There is no way to read
it again.

Two rules decide what the new key may hold:

- **Subset.** You can only grant scopes the calling key itself holds.
  Asking for anything more answers `403 API_KEY_SCOPE_ESCALATION`, naming
  the scopes that went beyond. `api_keys:manage` includes
  `api_keys:read`: a key holding manage can grant read even when read is
  not ticked on it, because it already reads the list.
- **`api_keys:manage` is never granted here.** A key issued through the
  API cannot issue keys of its own, even when the calling key can. Ask
  for it and the answer is `403 API_KEY_MANAGE_NOT_DELEGABLE`. Grant it
  in the dashboard, under Settings → API keys.

`scopes` is required and has no default: a key gets exactly what you ask
for. Requires `api_keys:manage`, which only a key created in the
dashboard can hold: there is no bootstrap endpoint, so the first key of
a workspace is always made by a person under Settings → API Keys.


Issues a key and returns its secret **once**. No later request returns it — the secret is stored only as a hash. Save it before you do anything else; if you lose it, revoke the key and issue another.

This is how an integration gives a job less authority than it has itself: a nightly export that only reads leads gets a key that can only read leads, so a mistake in that job cannot place a call or spend a shekel.

## The first key is made by a person

This endpoint issues the second key onward, never the first. It needs `api_keys:manage`, and **that scope can only be put on a key in the dashboard**, by a workspace owner or admin under Settings → API Keys: tick **API keys → Manage** (or pick **Full access**) when you create a key, or tick it on an existing key under **Edit scopes**. There is no bootstrap endpoint and no way to earn the scope from code, by design: it is the one scope that can widen the whole workspace.

So the pattern this page describes starts with one manual step and is code from then on:

**1. Once, in the dashboard**

Create a key with **API keys → Manage** ticked, or tick **API keys → Manage** on an existing key under **Edit scopes**. Store its secret wherever the integration keeps credentials. This is the only key that can reach `/api-keys`.

**2. Per job or per client, from code**

Call `POST /api-keys` with that key to issue a narrow key — one client, one job, one set of scopes.

**3. Rotate from code**

Issue the replacement under a new name — a name belongs to one active key, compared without regard to case — move the job over, then `DELETE /api-keys/{id}` the old one. Both keys work until you revoke the old one, so nothing stops in between. A key cannot revoke itself. In the dashboard, **Rotate** on a key's card does all of this in one step: the new secret keeps the key's name, permissions and agents, and its end date unless you pick another, and the old secret keeps working for the grace you pick — up to 7 days, shown as its `expires_at`, under the name `<name> (old)` — or stops at once, for a secret that leaked.

**There is no update endpoint.** A key's scopes, agents and end date are changed in the dashboard, under Settings → API keys → **Edit scopes**; `PATCH /api-keys/{id}` answers `405` and says so, whatever scopes the calling key holds. From code, the equivalent is the rotation above: issue the key you want, move over, revoke the old one.

If you are onboarding clients into separate workspaces, each workspace needs its own step 1: a key is scoped to one workspace and cannot issue keys in another.

## What a new key may hold

`scopes` is required and has no default. A key is issued with exactly what you ask for. Any field this page does not list is refused by name with `400 API_KEY_REQUEST_INVALID`, so a typo can never leave you believing a key is narrower than it is.

**Subset.** You can only grant scopes the calling key holds. A key with `leads:read` cannot issue a key with `calls:create`; the refusal names the scopes that went beyond, so you know which one to fix.

**`api_keys:manage` is never granted here.** A key issued through the API can never issue keys of its own, even when the key issuing it can. That keeps key issuance one generation deep and always starting with a person in the dashboard. If a key genuinely needs to issue keys, tick **API keys → Manage** when you create it in the dashboard, under Settings → API keys.

**`api_keys:read` is granted here like any other scope.** An integration that should be able to audit the inventory — which keys exist, what each one can do, when each was last used — without being able to issue or revoke one gets `api_keys:read` and nothing else. Manage includes Read: a key holding `api_keys:manage` can grant `api_keys:read` even when Read was never ticked on it, since it already reads the list. In the dashboard, ticking **API keys → Manage** ticks Read with it.

**`calls:metrics` is the calls read without the people on them** — counts, durations, outcomes and cost, with every number, name, summary, transcript, recording and collected value withheld (see the [scope table](https://docs.goyappr.com/api-reference/introduction.md#api-key-scopes)). Read includes Metrics: a key holding `calls:read` can grant `calls:metrics`, and in the dashboard ticking **Calls → Read** ticks Metrics with it.

**`agent_ids` limits the key to some agents.** Leave it out, or send `null`, and the key reaches the whole workspace, as every key always has. Send 1–100 agent ids and it reaches only those agents, their calls, the leads they called, their spend, their deliveries and their campaigns — see [Limiting a key to some agents](https://docs.goyappr.com/api-reference/introduction.md#limiting-a-key-to-some-agents). This is how an agency gives each client a key that cannot see another client's calls. Every id must be a live agent in this workspace; an empty list is refused rather than guessed at. A key limited to agents is refused the scopes it could never use — those that open only routes belonging to the whole workspace, adding an agent or changing a lead: `agents:create`, `tools:create`, `phone_numbers:*`, `billing:manage`, `dispositions:*`, `leads:manage`, `lead_tags:*`, `agent_eval:*`, `integrations:*`, `tool-connections:*`, `shared_links:*`, `do_not_call:*`, `sip_endpoints:*`, `call_windows:manage`, `affiliates:read`, `api_keys:*` and `carrier_accounts:*` — with `400 API_KEY_REQUEST_INVALID` naming each; they used to be issued and then refused with `403` on every use. `tools:read` and `tools:update` stay: they read and retry the key's own deliveries, and `billing:read` reads its agents' spend (`GET /billing/consumption`). The dashboard greys the same ones out under **Only these agents** and refuses them there too, on a new key and on an edit.

**`expires_at` gives the key an end date.** Send an ISO 8601 date-time with a time zone — `2026-12-31T23:59:59Z` — and from that moment every request made with the key answers `401 EXPIRED_KEY`. Leave it out, or send `null`, for a key that works until it is revoked. A moment that has passed, or a date without a time zone, is refused rather than guessed at. An expired key stays in the list, with its `expires_at`, until you revoke it.

Required scope: `api_keys:manage`.

## Example request

```bash theme={null}
curl -X POST "https://api.goyappr.com/api-keys" \
  -H "Authorization: Bearer $YAPPR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Nightly lead sync",
    "scopes": ["leads:read", "leads:manage"]
  }'
```

A key for one client of an agency — its calls and nothing else:

```bash theme={null}
curl -X POST "https://api.goyappr.com/api-keys" \
  -H "Authorization: Bearer $YAPPR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Client A — dental",
    "scopes": ["agents:read", "calls:read"],
    "agent_ids": ["0b6a3f7e-2d41-4c8a-9f10-5e2b7c9d1a44"]
  }'
```

A contractor's key that stops working at the end of the year:

```bash theme={null}
curl -X POST "https://api.goyappr.com/api-keys" \
  -H "Authorization: Bearer $YAPPR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Contractor — Q4",
    "scopes": ["calls:read"],
    "expires_at": "2026-12-31T23:59:59Z"
  }'
```

## Example response

```json theme={null}
{
  "id": "6a1c2d3e-4f50-4a6b-8c7d-9e0f1a2b3c4d",
  "name": "Nightly lead sync",
  "prefix": "ypr_live_9f2c41a",
  "scopes": ["leads:read", "leads:manage"],
  "agent_ids": null,
  "agents": null,
  "created_at": "2026-09-22T09:14:02.881Z",
  "last_used_at": null,
  "expires_at": null,
  "key": "ypr_live_9f2c41a7b0e3…"
}
```

`key` appears in this response and in no other.

## Testing a scope boundary

The pair of requests below is the whole check — issue a key without a scope, then watch the endpoint that needs it refuse:

```bash theme={null}
NARROW=$(curl -sX POST "https://api.goyappr.com/api-keys" \
  -H "Authorization: Bearer $YAPPR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name":"scope probe","scopes":["calls:read"]}' | jq -r .key)

curl -i -X PUT "https://api.goyappr.com/call-windows" \
  -H "Authorization: Bearer $NARROW" \
  -H "Content-Type: application/json" -d '{"windows":[]}'
# 403 INSUFFICIENT_SCOPE, naming call_windows:manage
```

Revoke the probe key with `DELETE /api-keys/{id}` when you are done.

## Errors

| HTTP | Code | When |
| - | - | - |
| 400 | `API_KEY_REQUEST_INVALID` | `name` missing or over 100 characters, `scopes` missing, empty, or not an array of strings, `expires_at` not a date-time with a time zone or already past, `agent_ids` empty, over its limit, or holding an entry that is not an agent id (each such entry is named by position, `agent_ids[1] ("clinic-a")`), `scopes` that a key limited by `agent_ids` could never use (each named — see `agent_ids` above), or the body carries a field this endpoint does not take. The message names the field; nothing is issued. |
| 400 | `API_KEY_SCOPE_UNKNOWN` | A requested scope does not exist. The message names it — check it against the [scope list](https://docs.goyappr.com/api-reference/introduction.md). |
| 400 | `API_KEY_AGENT_UNKNOWN` | An id in `agent_ids` is not a live agent in this workspace. The message names each one. |
| 403 | `INSUFFICIENT_SCOPE` | API key lacks `api_keys:manage`. |
| 403 | `API_KEY_SCOPE_ESCALATION` | A requested scope is one the calling key does not hold. The message names each one. `api_keys:read` is never among them for a key holding `api_keys:manage`, nor `calls:metrics` for a key holding `calls:read`. |
| 403 | `API_KEY_MANAGE_NOT_DELEGABLE` | `api_keys:manage` was requested. Create that key in the dashboard instead. |
| 409 | `API_KEY_NAME_TAKEN` | An active key of that name already exists here. Names are compared without regard to case — `Client-A` is taken while `client-a` is live — and the message names the key as it is spelled. Two creates sent at once under one spelling get one key and one 409 — the database holds the rule, not a check that both could pass. |
| 503 | `API_KEY_STORAGE_UNAVAILABLE` | Nothing was created. Retry. |


## OpenAPI

````yaml POST /api-keys
openapi: 3.1.0
info:
  title: Yappr API
  description: >
    Create and manage AI voice agents, purchase phone numbers, configure tools,
    and initiate calls — all via REST.
  version: 1.0.0
  contact:
    url: https://goyappr.com
servers:
  - url: https://api.goyappr.com
    description: Production
security:
  - apiKey: []
paths:
  /api-keys:
    post:
      tags:
        - API Keys
      summary: Issue an API key
      description: >
        Issues a new key and returns its secret **once**. There is no way to
        read

        it again.


        Two rules decide what the new key may hold:


        - **Subset.** You can only grant scopes the calling key itself holds.
          Asking for anything more answers `403 API_KEY_SCOPE_ESCALATION`, naming
          the scopes that went beyond. `api_keys:manage` includes
          `api_keys:read`: a key holding manage can grant read even when read is
          not ticked on it, because it already reads the list.
        - **`api_keys:manage` is never granted here.** A key issued through the
          API cannot issue keys of its own, even when the calling key can. Ask
          for it and the answer is `403 API_KEY_MANAGE_NOT_DELEGABLE`. Grant it
          in the dashboard, under Settings → API keys.

        `scopes` is required and has no default: a key gets exactly what you ask

        for. Requires `api_keys:manage`, which only a key created in the

        dashboard can hold: there is no bootstrap endpoint, so the first key of

        a workspace is always made by a person under Settings → API Keys.
      operationId: createApiKey
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - name
                - scopes
              additionalProperties: false
              properties:
                name:
                  type: string
                  maxLength: 100
                  description: >-
                    Unique among this workspace's active keys, compared without
                    regard to case (`Client-A` is taken while `client-a` is
                    live). The only handle you have on the key afterwards.
                  example: Nightly lead sync
                scopes:
                  type: array
                  minItems: 1
                  items:
                    type: string
                  description: >-
                    A subset of the calling key's own scopes (`api_keys:read`
                    counts as held by a key with `api_keys:manage`).
                    `api_keys:manage` is not accepted.
                  example:
                    - leads:read
                    - leads:manage
                agent_ids:
                  type: array
                  nullable: true
                  minItems: 1
                  maxItems: 100
                  items:
                    type: string
                    format: uuid
                  description: >
                    Limit the key to these agents — live agents in this
                    workspace.

                    Leave it out or send `null` for a key that reaches the whole

                    workspace. An unknown id answers `400 API_KEY_AGENT_UNKNOWN`

                    and an empty list `400 API_KEY_REQUEST_INVALID`.
                expires_at:
                  type: string
                  format: date-time
                  nullable: true
                  description: >
                    When the key stops working: an ISO 8601 date-time with a
                    time

                    zone, in the future. Leave it out or send `null` for a key
                    that

                    works until it is revoked. A past moment or a date without a

                    time zone answers `400 API_KEY_REQUEST_INVALID`.
                  example: '2026-12-31T23:59:59Z'
      responses:
        '201':
          description: Key issued. The only response that contains the secret.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiKeyCreated'
        '400':
          description: >-
            API_KEY_REQUEST_INVALID - missing name, missing or empty scopes, an
            expires_at that is not a future date-time with a time zone, scopes a
            key limited by agent_ids could never use (agents:create,
            tools:create and the other workspace-wide scopes, each named), or a
            field this endpoint does not take (the message names it; no key is
            issued). API_KEY_SCOPE_UNKNOWN - a scope that does not exist.
            API_KEY_AGENT_UNKNOWN - an agent_ids entry that is not a live agent
            here.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: A requested scope is beyond the calling key, or is `api_keys:manage`
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: >-
            API_KEY_NAME_TAKEN - an active key of that name, compared without
            regard to case, already exists in this workspace; the message names
            it as it is spelled. Two creates sent at once under one spelling get
            one key and one 409.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '503':
          description: The key store could not be written. No key was created — retry.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    ApiKeyCreated:
      allOf:
        - $ref: '#/components/schemas/ApiKey'
        - type: object
          properties:
            key:
              type: string
              description: >
                The full secret. This is the only response that ever contains it
                —

                store it before you do anything else. If you lose it, revoke the

                key and issue another.
              example: ypr_live_9f2c41a7b0e3…
    Error:
      type: object
      required:
        - error
        - code
      description: >
        Every error response - the secret-key API and the browser data plane
        alike - carries a

        human-readable `error` and a stable machine `code`, and a refusal that
        names what is

        wrong with the request carries `issues[]` too. Branch on `code`, never
        on the `error`

        text. A refusal that names nothing more specific carries the code its
        status means:

        `BAD_REQUEST` (400), `UNAUTHORIZED` (401, the browser data plane; the
        secret-key API

        answers `MISSING_KEY`, `INVALID_KEY` or `EXPIRED_KEY`), `BILLING_ERROR`
        (402),

        `FORBIDDEN` (403), `NOT_FOUND` (404), `METHOD_NOT_ALLOWED` (405),
        `CONFLICT` (409),

        `GONE` (410), `PAYLOAD_TOO_LARGE` (413), `UNSUPPORTED_MEDIA_TYPE` (415),

        `UNPROCESSABLE_REQUEST` (422), `RATE_LIMIT` (429), `INTERNAL_ERROR`
        (500),

        `UPSTREAM_ERROR` (502), `SERVICE_UNAVAILABLE` (503), `UPSTREAM_TIMEOUT`
        (504). Some

        refusals add members of their own beside these (a call request's
        `status`, a workflow's

        `current_version`); the operation says which.
      properties:
        error:
          type: string
          description: The refusal, in one sentence for a person. Its wording may change.
        code:
          type: string
          description: The stable code to branch on.
        issues:
          type: array
          description: >
            Each thing at fault, on a 400 or 422 that names them: every query
            parameter or body field, not just the first. `path` is the
            parameter's name or the field's location.
          items:
            type: object
            required:
              - code
              - message
            properties:
              code:
                type: string
                description: >-
                  query_param_unknown, query_param_repeated, query_param_blank,
                  query_param_invalid, field_unknown, field_required,
                  field_invalid, or the route's own word.
              path:
                type: string
              message:
                type: string
    ApiKey:
      type: object
      description: |
        An API key belonging to your workspace. The secret itself is stored only
        as a SHA-256 hash and is returned exactly once, by `POST /api-keys`; no
        read ever returns it. `prefix` is the first 16 characters of the secret
        and is what identifies a key in the dashboard list.
      properties:
        id:
          type: string
          format: uuid
        name:
          type: string
          description: >-
            What you called the key. Unique among this workspace's active keys,
            compared without regard to case.
          example: Nightly lead sync
        prefix:
          type: string
          description: >-
            First 16 characters of the key, enough to tell two keys apart. Never
            the whole secret.
          example: ypr_live_9f2c41a
        scopes:
          type: array
          items:
            type: string
          example:
            - leads:read
            - leads:manage
        agent_ids:
          type: array
          nullable: true
          items:
            type: string
            format: uuid
          description: >
            The agents this key is limited to, or `null` for a key that reaches

            the whole workspace. A limited key reaches those agents, their
            calls,

            the leads they called (read only), their spend, their deliveries and

            their campaigns, and calls only from numbers those agents answer or

            call from; everything the workspace shares answers

            `403 API_KEY_AGENT_SCOPED`, and naming another agent answers

            `403 AGENT_OUTSIDE_KEY_SCOPE`.
          example: null
        agents:
          type: array
          nullable: true
          description: |
            The same agents as `agent_ids`, in the same order, each with its
            name — so a read says which client a limited key reaches. An
            archived agent keeps its name; an agent that no longer exists has
            `name: null`. `null` for a key that reaches the whole workspace.
          items:
            type: object
            properties:
              id:
                type: string
                format: uuid
              name:
                type: string
                nullable: true
          example: null
        created_at:
          type: string
          format: date-time
        expires_at:
          type: string
          format: date-time
          nullable: true
          description: |
            When the key stops working, or `null` for a key that works until it
            is revoked. Past this moment every request made with it answers
            `401 EXPIRED_KEY`; the key stays listed until it is revoked.
          example: null
        last_used_at:
          type: string
          format: date-time
          nullable: true
          description: When this key last authenticated a request. `null` if it never has.
  securitySchemes:
    apiKey:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: >-
        Your Yappr API key (e.g. `ypr_live_...`). Generate one in the dashboard
        under **Settings → API Keys**. No key is `401 MISSING_KEY`; a key that
        is not one of ours, or is revoked, is `401 INVALID_KEY`; an expired one
        is `401 EXPIRED_KEY`. A valid key without the scope an operation needs
        is `403 INSUFFICIENT_SCOPE` on every operation, and the message names
        the scope. Every response, a 401 included, carries X-RateLimit-Limit,
        X-RateLimit-Remaining and X-RateLimit-Reset: the budget is 60 requests a
        minute per API key. Every 429, whatever its code, carries Retry-After
        (whole seconds, never zero): the per-key budget's `RATE_LIMIT` asks for
        what is left of the minute, a route's daily cap (`RATE_LIMITED`) for the
        time until that cap resets. All four headers are listed in
        Access-Control-Expose-Headers, so a browser can read them. A path the
        API does not serve (an unknown sub-path, an id left empty) is `404
        ROUTE_NOT_FOUND`, and a method a served path does not take is `405
        METHOD_NOT_ALLOWED` with an `Allow` header; both are answered before any
        scope check, and nothing is read or changed. A trailing slash is ignored
        where it cannot be an id left empty (`POST /calls/` is `POST /calls`)
        and refused where it can (`GET /calls/`). A doubled slash inside a path
        is merged into one before the request reaches the API (`GET //calls` is
        `GET /calls`).

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.