# Create an API key

API keys

POST `/v1/api_keys`

Creates a key with the given scopes, spend limit, expiry and IP allowlist. The secret is in this answer only: store it now. A key never gets a scope its creator lacks. Free.

**Auth:** an API key with the `admin` scope, or the dashboard session.

**Test mode:** A test key sees and manages test keys only.

Send an `idempotency-key` header to retry safely: the same key and body within 1 day never repeat the work.

## Example

cURL:

```shell
curl -X POST 'https://staging.socialtap.dev/v1/api_keys' \
  -H "x-api-key: $SOCIALTAP_API_KEY" \
  -H "content-type: application/json" \
  -d '{
  "expires_at": "2026-10-27T12:00:00Z",
  "ip_allowlist": [
    "string"
  ],
  "mode": "live",
  "name": "string",
  "scopes": [
    "endpoints"
  ],
  "spend_limit": {
    "amount": 1,
    "interval": "day"
  }
}'
```

## Authorizations

`x-api-key`stringheaderrequired

Your API key, with the `admin` scope. [Authentication](https://staging.socialtap.dev/docs/authentication/index.md)

## Headers

| Name | Type | Description | Example |
| --- | --- | --- | --- |
| `idempotency-key` optional | `string`<br>max 255 chars | On any POST: your unique key for the request (1–255 printable ASCII characters; a UUID is ideal), kept 24 hours. Retrying with the same key and body never repeats the work: the answer is the first request's result, in its current state. | — |

## Body

JSON. Fields marked nullable may be `null`; optional ones may be left out.

| Field | Type | Description |
| --- | --- | --- |
| `expires_at?` | `string` (date-time) or `null` | RFC 3339, in the future. Default: never; made with an API key, that key's expiry (never later). |
| `ip_allowlist?` | `string[]` | IP addresses or CIDR ranges (203.0.113.0/24, 2001:db8::/32). Default: \[\] (any); made with an API key, that key's allowlist (every entry within it). |
| `mode?` | `string` | Default: the mode of the credential creating it. A test key can only create test keys.<br>One of `live`, `test` |
| `name?` | `string` | Your label for the key. Default: "API key". |
| `scopes?` | `string[]` | Default: endpoints, jobs and account:read. Only an admin credential creates keys, and a key never gets a scope its creator lacks.<br>One of `endpoints`, `jobs`, `account:read`, `admin` |
| `spend_limit?` | `object` or `null` | Default: none; made with an API key, that key's own (never looser: ADR 0011 §9 key restrictions). |
| `spend_limit.amount` | `integer` | Most credits the key may spend per interval; above it, requests fail with spend_limit_reached. |
| `spend_limit.interval` | `string` | Calendar day or month, UTC.<br>One of `day`, `month` |

## Response

### 201

Create an API key

| Field | Type | Description |
| --- | --- | --- |
| `data` | `object` |  |
| `data.created_at` | `string` (date-time) | When the key was created, RFC 3339 UTC. |
| `data.expires_at` | `string` (date-time) or `null` | When the key stops working, RFC 3339 UTC; null when it never expires. |
| `data.id` | `string` | Key ID (key_…): manage the key with it. It is not the secret. |
| `data.ip_allowlist` | `string[]` | IP addresses or CIDR ranges (IPv4 or IPv6) the key works from; \[\] = any. |
| `data.last_used_at` | `string` (date-time) or `null` | About when the key was last used (updated at most hourly); null when never. |
| `data.mode` | `string` | live keys spend credits on real requests; test keys answer from recorded responses, free.<br>One of `live`, `test` |
| `data.name` | `string` | Your label for the key. |
| `data.object` | `string` | Always api_key.<br>One of `api_key` |
| `data.prefix` | `string` | The secret's first characters, to recognize it. |
| `data.revoked_at` | `string` (date-time) or `null` | When the key was revoked; null while it is not. |
| `data.scopes` | `string[]` | What the key may call: endpoints (data endpoints), jobs, account:read (account, usage, ledger, keys), admin (account settings and key management; includes account:read).<br>One of `endpoints`, `jobs`, `account:read`, `admin` |
| `data.secret` | `string` | The key itself: send it in the x-api-key header. Shown only once: store it now. |
| `data.spend_limit` | `object` or `null` | The key's spend limit and what it used this interval; null when the key has none. |
| `data.spend_limit.amount` | `integer` | Most credits the key may spend per interval. |
| `data.spend_limit.interval` | `string` | Calendar day or month, UTC.<br>One of `day`, `month` |
| `data.spend_limit.resets_at` | `string` (date-time) | Start of the next interval, RFC 3339 UTC. |
| `data.spend_limit.used` | `integer` | Credits the key spent this interval, plus what its requests in flight hold. |
| `data.status` | `string` | pending: created by an agent signup and waiting for the owner's email confirmation (it can only read GET /v1/account). expired: past expires_at.<br>One of `active`, `pending`, `expired`, `revoked` |
| `meta` | `object` | The shared route meta (see the API reference introduction). |

### 400

400 Bad Request.

| Code | HTTP | Retry | Meaning | What to do |
| --- | --- | --- | --- | --- |
| `invalid_input` | 400 | No | The request parameters are missing or malformed, or the URL is not a supported link for this endpoint. | Fix the parameter named in param (the message says how); for a link of the wrong kind, call the endpoint the message names. |

### 401

401 Unauthorized.

| Code | HTTP | Retry | Meaning | What to do |
| --- | --- | --- | --- | --- |
| `unauthorized` | 401 | No | The x-api-key header is missing, unknown or revoked (or, on the dashboard's routes, the session cookie is missing or expired). | Send a valid API key in the x-api-key header; without one, get a key at details.signup_url (AI agents: POST details.agent_signup_url). |

### 403

403 Forbidden.

| Code | HTTP | Retry | Meaning | What to do |
| --- | --- | --- | --- | --- |
| `forbidden` | 403 | No | The API key is valid but may not make this request: its account is suspended, its scopes do not include the route, it is waiting for its owner's email confirmation, it is past its expiry, or the request came from an IP its allowlist does not include. A running job stops the same way when its account is suspended or the key that created it is revoked or expires. It is about the key, never the item (a private item is private_or_unavailable, also 403): branch on the code. | Do what details.reason says: if suspended, contact [support](https://staging.socialtap.dev/docs/index.md); otherwise use a key whose scopes cover the route (details.required_scope), have the owner confirm the emailed link, create a new key, or call from an allowed IP. |

### 409

409 Conflict.

| Code | HTTP | Retry | Meaning | What to do |
| --- | --- | --- | --- | --- |
| `idempotency_key_in_progress` | 409 | Yes, later | A request with this Idempotency-Key is still running. | Retry after the number of seconds in the retry-after header to get that request's result. |

### 422

422 Unprocessable.

| Code | HTTP | Retry | Meaning | What to do |
| --- | --- | --- | --- | --- |
| `idempotency_key_reused` | 422 | No | The Idempotency-Key was already used with a different request (another route, or another body). | Send a new Idempotency-Key for a different request; reuse a key only to retry the identical request. |

### 429

429 Too Many Requests.

| Code | HTTP | Retry | Meaning | What to do |
| --- | --- | --- | --- | --- |
| `rate_limited` | 429 | Yes, later | The account exceeded its runaway-protection ceiling: plans do not limit request rate, but a high per-account safety ceiling stops broken client loops. Support raises it on request. Without an API key (signup, the MCP server's tool listing and find_endpoint), requests are limited per IP address instead. | Wait for the number of seconds in the retry-after header, then retry; ask [support](https://staging.socialtap.dev/docs/index.md) to raise the ceiling if your sustained traffic needs more (calls without an API key: use one). |

## Test mode

A test key sees and manages test keys only.

operationId `api_keys.create`

---

[HTML version](https://staging.socialtap.dev/docs/reference/api-keys/create/) · [Docs index for AI agents](https://staging.socialtap.dev/llms.txt) · [All docs in one file](https://staging.socialtap.dev/llms-full.txt)
