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

# Create a new API key

> 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.



## OpenAPI

````yaml /api-reference/openapi.json post /secrets/api/keys
openapi: 3.0.1
info:
  title: Flexprice API
  description: Flexprice API Service
  contact:
    name: API Support
  license:
    name: AGPL-3.0
    url: https://www.gnu.org/licenses/agpl-3.0.html
  version: '1.0'
servers:
  - url: https://us.api.flexprice.io/v1
    description: US Region
  - url: https://api.cloud.flexprice.io/v1
    description: India Region
security: []
paths:
  /secrets/api/keys:
    post:
      tags:
        - Secrets
      summary: Create a new API key
      description: >-
        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.
      operationId: createApiKey
      requestBody:
        description: API key creation request
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateAPIKeyRequest'
        required: true
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateAPIKeyResponse'
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/errors.ErrorResponse'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/errors.ErrorResponse'
      security:
        - ApiKeyAuth: []
components:
  schemas:
    CreateAPIKeyRequest:
      required:
        - name
        - type
      type: object
      properties:
        expires_at:
          type: string
          format: date-time
        name:
          type: string
        service_account_id:
          type: string
        type:
          $ref: '#/components/schemas/types.SecretType'
    CreateAPIKeyResponse:
      type: object
      properties:
        api_key:
          type: string
        secret:
          $ref: '#/components/schemas/SecretResponse'
    errors.ErrorResponse:
      type: object
      properties:
        code:
          type: string
          enum:
            - not_found
            - already_exists
            - version_conflict
            - validation_error
            - invalid_operation
            - permission_denied
            - http_client_error
            - database_error
            - system_error
            - internal_error
            - service_unavailable
        details:
          type: object
          additionalProperties:
            type: object
        http_status_code:
          type: integer
        message:
          type: string
      x-speakeasy-name-override: ErrorResponse
    types.SecretType:
      type: string
      enum:
        - private_key
        - publishable_key
        - integration
      x-enum-varnames:
        - SecretTypePrivateKey
        - SecretTypePublishableKey
        - SecretTypeIntegration
      x-speakeasy-name-override: SecretType
    SecretResponse:
      type: object
      properties:
        created_at:
          type: string
          format: date-time
        display_id:
          type: string
        expires_at:
          type: string
          format: date-time
        id:
          type: string
        last_used_at:
          type: string
          format: date-time
        name:
          type: string
        provider:
          $ref: '#/components/schemas/types.SecretProvider'
        roles:
          type: array
          description: RBAC roles
          items:
            type: string
        status:
          $ref: '#/components/schemas/types.Status'
        type:
          $ref: '#/components/schemas/types.SecretType'
        updated_at:
          type: string
          format: date-time
        user_type:
          $ref: '#/components/schemas/types.UserType'
    types.SecretProvider:
      type: string
      enum:
        - flexprice
        - stripe
        - s3
        - hubspot
        - razorpay
        - chargebee
        - quickbooks
        - zoho_books
        - nomod
        - moyasar
        - paddle
      x-enum-varnames:
        - SecretProviderFlexPrice
        - SecretProviderStripe
        - SecretProviderS3
        - SecretProviderHubSpot
        - SecretProviderRazorpay
        - SecretProviderChargebee
        - SecretProviderQuickBooks
        - SecretProviderZohoBooks
        - SecretProviderNomod
        - SecretProviderMoyasar
        - SecretProviderPaddle
      x-speakeasy-name-override: SecretProvider
    types.Status:
      type: string
      enum:
        - published
        - deleted
        - archived
      x-enum-varnames:
        - StatusPublished
        - StatusDeleted
        - StatusArchived
      x-speakeasy-name-override: Status
    types.UserType:
      type: string
      enum:
        - user
        - service_account
      x-enum-varnames:
        - UserTypeUser
        - UserTypeServiceAccount
      x-speakeasy-name-override: UserType
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      description: Enter your API key in the format *x-api-key &lt;api-key&gt;**
      name: x-api-key
      in: header

````