---
title: "Create a new API key"
method: POST
path: "/secrets/api/keys"
tags: ["Secrets"]
---

# Create a new API key

`POST /secrets/api/keys`

Use when issuing a new API key (e.g. for a service account or for the current user). Provide service_account_id to create for a service account.

## Request body

- CreateAPIKeyRequest
  - `expires_at` string, date-time
  - `name` string, required
  - `service_account_id` string
  - `type` 'private_key' | 'publishable_key' | 'integration', required

## Response `201`

Created

- CreateAPIKeyResponse
  - `api_key` string
  - `secret` SecretResponse
    - `created_at` string, date-time
    - `display_id` string
    - `expires_at` string, date-time
    - `id` string
    - `last_used_at` string, date-time
    - `name` string
    - `provider` 'flexprice' | 'stripe' | 's3' | 'hubspot' | 'razorpay' | 'chargebee' | 'quickbooks' | 'zoho_books' | 'nomod' | 'moyasar' | 'paddle' | 'whop' | 'tabs' | 'aws_marketplace'
    - `roles` string[] — RBAC roles
    - `service_account_name` string — name of the service account (populated for service_account user_type)
    - `status` 'published' | 'deleted' | 'archived'
    - `type` 'private_key' | 'publishable_key' | 'integration'
    - `updated_at` string, date-time
    - `user_id` string — user or service account this key belongs to
    - `user_type` 'user' | 'service_account'

## Other responses

- `400` — Invalid request
- `500` — Server error

## Changes

- **2026-07-15** `f8ecf435d25d` — 4 warning
  - added the new `aws_marketplace` enum value to the `secret/provider` response property for the response status `201`
  - added the new `not_implemented` enum value to the `code` response property for the response status `400`
  - added the new `not_implemented` enum value to the `code` response property for the response status `500`
  - added the new `tabs` enum value to the `secret/provider` response property for the response status `201`
- **2026-07-09** `646d6658479b` — 1 breaking
  - the `expires_at` request property type/format changed from `string`/`` to `string`/`date-time`
- **2026-07-09** `7d57386313c7` — 6 breaking, 20 warning, 3 info
  - request property `type` was restricted to a list of enum values
  - the `type` request property type/format changed from ``/`` to `string`/``
  - the `secret/provider` response's property type/format changed from ``/`` to `string`/`` for status `201`
  - the `secret/status` response's property type/format changed from ``/`` to `string`/`` for status `201`
  - …25 more
- **2026-07-09** `4b1a811c4179` — 12 breaking, 21 info
  - removed the enum value `integration` of the request property `type`
  - removed the enum value `private_key` of the request property `type`
  - removed the enum value `publishable_key` of the request property `type`
  - the `type` request property type/format changed from `string`/`` to ``/``
  - …29 more
- …earlier changes not shown

[Full history](https://skmtc.dev/flexprice/apis/flexprice-api/changes/secrets/api/keys/post.md)

---

[API](https://skmtc.dev/flexprice/apis/flexprice-api.md) · [All operations](https://skmtc.dev/flexprice/apis/flexprice-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/flexprice/flexprice-api/revisions/f8ecf435d25d/schema)
