# Create an API key as an agent

> POST /v1/agent/api-keys creates a test key with `full_access` or a live key with `recording_access` and returns the key once: parameters, examples and errors.

Source: https://esigncomply.com/docs/api/agent/create-an-api-key-as-an-agent

Last updated November 26, 2026

In the Esign Comply API, `POST /v1/agent/api-keys` creates a test key with `full_access` or a live key with `recording_access` and returns the key once. An AI agent calls it with an agent token for the `create_test_key` step, before it builds the signing flow.

`POST /v1/agent/api-keys` · API version `2026-11-21`

## Authentication

Send an agent token (`esc_agent_...`) in the `Authorization` header: `Bearer $ESIGNCOMPLY_AGENT_TOKEN`. The token acts as the member who created it, with that member's role. A person creates it under Agent access in the dashboard. An API key is refused with [`invalid_api_key`](https://esigncomply.com/docs/api/errors.md#invalid_api_key). See [Authentication](https://esigncomply.com/docs/api/agent.md#authentication) of the agent account API.

## Request example

### cURL

```bash
curl https://esigncomply.com/v1/agent/api-keys \
  -H "Authorization: Bearer $ESIGNCOMPLY_AGENT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "mode": "test",
    "name": "CI"
  }'
```

This request ran against the API on November 26, 2026, and the response below is what came back. IDs are example values, and long values are shortened with `...`.

## What it does

A test key has `full_access`, like the key the dashboard creates on Get started. A live key has `recording_access` and exists once the domain is verified, the organization's details are saved and the agreements are recorded. The member's role must allow keys: owner or admin.

## Parameters

### Body fields

| Field | Type | Required | Meaning |
|---|---|---|---|
| `mode` | string | No | `test` (default) or `live`. |
| `name` | string | No | Up to 80 characters. Default: `Agent: ` and the token's name for a test key, `Production` for a live key. |

`key` holds the whole key, once. Store it on the server as `ESIGNCOMPLY_API_KEY`: the test key in development and preview, the live key in production only. Keep both out of the repository and out of client code.

A live key asked for too early answers `403` [`domain_not_verified`](https://esigncomply.com/docs/api/errors.md#domain_not_verified). The error names what is missing: `blocker` is the first thing in the way, `blockers` lists all of them, `next_step` is the step to take, and `needs_person` says whether that step is the person's.

## Response

`201 Created` with an ApiKey object.

```json
{
  "object": "api_key",
  "id": "key_t8HP",
  "name": "CI",
  "livemode": false,
  "permission": "full_access",
  "prefix": "esc_test_us_...",
  "key": "esc_test_us_...",
  "env": "ESIGNCOMPLY_API_KEY",
  "created_at": "2026-11-26T00:18:20.446Z"
}
```

### Response fields

| Field | Type | Description |
|---|---|---|
| `object` | string |  |
| `id` | string |  |
| `name` | string |  |
| `livemode` | boolean |  |
| `permission` | string |  |
| `prefix` | string |  |
| `api_version` | string |  |
| `created_at` | datetime |  |
| `last_used_at` | datetime |  |
| `revoked_at` | datetime |  |
| `key` | string | The secret key. Present only in the creation response. |
| `revoked` | boolean |  |

## Errors

| Code | HTTP | When |
|---|---|---|
| [`invalid_request`](https://esigncomply.com/docs/api/errors.md#invalid_request) | 400 | The request is malformed: the body is not valid JSON, a known field has the wrong type, a required field is missing, a value is out of range, or a limit was passed (for example `metadata` over 50 keys, `context.extra` over 16 KB, event `data` over 256 KB, an `Idempotency-Key` over 255 characters, an unknown `Esign-Comply-Version`). |
| [`domain_not_verified`](https://esigncomply.com/docs/api/errors.md#domain_not_verified) | 403 | A live key is used before its domain is verified, or domain verification lapsed more than 14 days ago and the request tries to create a live session. |
| [`insufficient_permission`](https://esigncomply.com/docs/api/errors.md#insufficient_permission) | 403 | The key's permission does not allow the call (for example a `recording_access` key asking for an evidence report), a secret key was sent to a browser-only endpoint, a client token was sent to a server-only endpoint, or a secret key tried to send ceremony events or the signing act for a session that was not created with `capture_mode: "server_only"`. |

Like every call made with an agent token, it can also return [`missing_api_key`](https://esigncomply.com/docs/api/errors.md#missing_api_key), [`invalid_api_key`](https://esigncomply.com/docs/api/errors.md#invalid_api_key), [`not_found`](https://esigncomply.com/docs/api/errors.md#not_found), [`quota_exhausted`](https://esigncomply.com/docs/api/errors.md#quota_exhausted), [`rate_limit_exceeded`](https://esigncomply.com/docs/api/errors.md#rate_limit_exceeded) and [`internal_error`](https://esigncomply.com/docs/api/errors.md#internal_error).

Every error has the same body: `error.type`, `error.code`, `error.message`, `error.doc_url` and `error.request_id`. See [Errors](https://esigncomply.com/docs/api/errors.md).

## Questions about POST /v1/agent/api-keys

### Which credential does POST /v1/agent/api-keys need?

An agent token, which starts with esc_agent_. Send it as a Bearer token in the Authorization header. An API key is refused with invalid_api_key.

### Does POST /v1/agent/api-keys work with a test key?

An agent token has no test or live mode. It acts on the account, and the keys it creates are test keys or live keys.

### Does POST /v1/agent/api-keys count as a signature event?

No. A signature event is counted when a live record is written, by completing a session or by submitting a deferred acceptance. This call writes no record.

### Is POST /v1/agent/api-keys idempotent?

It takes no Idempotency-Key header. The agent account API does not replay responses.

### What is the rate limit for POST /v1/agent/api-keys?

60 calls per minute for each agent token and 120 per minute for each IP address. Past the limit the API answers 429 rate_limit_exceeded with a Retry-After header.

### Does the Node SDK have a method for POST /v1/agent/api-keys?

No. The agent account API is called over HTTP with the agent token. The esigncomply package works with API keys.

## Related

- [Agent account API](https://esigncomply.com/docs/api/agent.md): the overview of the resource and all of its operations.
- [Retrieve the domain as an agent](https://esigncomply.com/docs/api/agent/retrieve-the-domain-as-an-agent.md): `GET /v1/agent/domain`
- [Register the domain as an agent](https://esigncomply.com/docs/api/agent/register-the-domain-as-an-agent.md): `PUT /v1/agent/domain`
- [Verify the domain as an agent](https://esigncomply.com/docs/api/agent/verify-the-domain-as-an-agent.md): `POST /v1/agent/domain/verify`
- [Go live on the Free plan](https://esigncomply.com/docs/api/agent/go-live-on-the-free-plan.md): `POST /v1/agent/go-live`
- [MCP server](https://esigncomply.com/docs/mcp.md)
- [Agent skill](https://esigncomply.com/docs/guides/agent-skill.md)
- [Errors](https://esigncomply.com/docs/api/errors.md): every error code, with what to do.
- [API conventions](https://esigncomply.com/docs/api.md): authentication, idempotency, rate limits and versioning.
