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

# Create a personal API key

> Create a personal API key for the authenticated user. The key value is only
returned once. A key created with another API key is revoked along with it,
and expires no later than it.



## OpenAPI

````yaml https://app.kosli.com/api/v2/openapi.json post /user/api-keys
openapi: 3.1.0
info:
  title: Kosli API
  summary: The API for communicating with Kosli
  description: >

    # Authentication 


    When making requests against Kosli API, you can authenticate your requests
    using a bearer token. 

    Set the bearer token in the request Authorization header to a valid API
    key. 

    API Keys can be personal or for service accounts. Check the [service
    accounts
    documentation](https://docs.kosli.com/getting_started/service-accounts/) for
    details. 


    ## Curl example


    ```shell

    curl -H "Authorization: Bearer <<your-api-key>>"
    https://app.kosli.com/api/v2/environments/<<your-org-name>>

    ```
  version: '2.0'
servers:
  - url: https://app.kosli.com/api/v2
    description: EU
  - url: https://app.us.kosli.com/api/v2
    description: US
security:
  - HTTPBearer: []
paths:
  /user/api-keys:
    post:
      tags:
        - User
      summary: Create a personal API key
      description: >-
        Create a personal API key for the authenticated user. The key value is
        only

        returned once. A key created with another API key is revoked along with
        it,

        and expires no later than it.
      operationId: create_personal_api_key
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ApiKeyPostInput'
      responses:
        '201':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiKeyCreatedResponse'
        '400':
          description: Invalid expiry date
          content:
            application/json:
              example:
                message: expires_at cannot be in the past
                errors:
                  email: Field must be a valid email address
                  name: Field cannot be empty
              schema:
                $ref: '#/components/schemas/BadRequestResponseModel'
      security:
        - HTTPBearer: []
        - HTTPBasic: []
components:
  schemas:
    ApiKeyPostInput:
      properties:
        description:
          type: string
          maxLength: 256
          minLength: 1
          title: Description
        expires_at:
          anyOf:
            - type: integer
              maximum: 4102444800
              minimum: -9223372036854776000
            - type: 'null'
          title: Expires At
          description: >-
            Unix timestamp for key expiry. Must not be in the past. Omit or pass
            0 for the maximum; every key expires at most 365 days from creation.
      type: object
      required:
        - description
      title: ApiKeyPostInput
    ApiKeyCreatedResponse:
      properties:
        id:
          type: string
          title: Id
        key:
          type: string
          title: Key
        description:
          type: string
          title: Description
        created_at:
          type: number
          title: Created At
        expires_at:
          type: integer
          title: Expires At
      type: object
      required:
        - id
        - key
        - description
        - created_at
        - expires_at
      title: ApiKeyCreatedResponse
    BadRequestResponseModel:
      properties:
        message:
          type: string
          title: Message
          description: Error message
        errors:
          anyOf:
            - additionalProperties:
                type: string
              type: object
            - type: 'null'
          title: Errors
          description: Validation errors by field
      type: object
      required:
        - message
      title: BadRequestResponseModel
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

````

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