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

# Create API key

> Create a scoped API key for your Darwin account.

<Warning>
  The response shows the plaintext key once. Store it securely before leaving the response; Darwin cannot retrieve it
  later.
</Warning>

<Card title="Manage API keys in Darwin" icon="key" horizontal href="https://darwin.so/settings?tab=api-keys">
  Create and revoke keys from Developer settings.
</Card>


## OpenAPI

````yaml openapi-v2.json POST /account/api-keys
openapi: 3.1.0
info:
  title: Darwin API
  version: 2.0.0
  description: >-
    Search executable capabilities, manage durable work through explicit Action
    operations, and administer developer credentials for the signed-in account.
    Operations marked planned-preview are contract scaffolding and are not
    callable in production.
servers:
  - url: https://api.darwin.so/api/v2
security:
  - apiKey: []
  - bearer: []
paths:
  /account/api-keys:
    post:
      summary: Create API key
      description: >-
        Create a user API key for the signed-in Darwin account. The plaintext
        apiKey is returned once and cannot be retrieved later. Requires an
        authenticated account session.
      operationId: create_api_key
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateApiKeyRequest'
      responses:
        '201':
          description: >-
            The API key was created. Store apiKey securely because Darwin will
            not return it again.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreatedApiKey'
        '400':
          description: The request failed.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: The request failed.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: The request failed.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '503':
          description: The request failed.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - AccountSession: []
components:
  schemas:
    CreateApiKeyRequest:
      type: object
      additionalProperties: false
      required:
        - name
      properties:
        name:
          type: string
          minLength: 1
          maxLength: 120
          description: >-
            A recognizable name for the environment or integration that will use
            this key.
          example: Production server
        scopes:
          type: array
          minItems: 1
          uniqueItems: true
          items:
            type: string
          description: >-
            Optional permissions for the key. Omit this field to grant the
            current default developer scopes; prefer the narrowest scopes your
            integration needs.
          example:
            - directory:read
            - agent:write
        expiresAt:
          type:
            - string
            - 'null'
          format: date-time
          description: >-
            Optional future ISO 8601 expiration. Omit or set null for no
            scheduled expiration.
          example: '2027-09-21T00:00:00.000Z'
    CreatedApiKey:
      type: object
      additionalProperties: false
      required:
        - id
        - name
        - prefix
        - scopes
        - requestCount
        - lastUsedAt
        - expiresAt
        - revokedAt
        - createdAt
        - apiKey
      properties:
        id:
          type: string
          description: Stable non-secret identifier for the API key.
        name:
          type: string
          description: Human-readable key name supplied at creation.
        prefix:
          type: string
          description: >-
            Non-secret prefix you can use to identify the key in logs and
            settings.
        scopes:
          type: array
          items:
            type: string
          description: >-
            Permissions granted to the key. Every API operation still enforces
            its required scope.
        requestCount:
          type: integer
          minimum: 0
          description: Lifetime number of requests authenticated with this key.
        lastUsedAt:
          type:
            - string
            - 'null'
          format: date-time
          description: >-
            When Darwin most recently authenticated a request with this key, or
            null if unused.
        expiresAt:
          type:
            - string
            - 'null'
          format: date-time
          description: When the key expires, or null when it has no scheduled expiration.
        revokedAt:
          type:
            - string
            - 'null'
          format: date-time
          description: When the key was revoked, or null while it has not been revoked.
        createdAt:
          type: string
          format: date-time
          description: When the key was created.
        apiKey:
          type: string
          readOnly: true
          description: >-
            Plaintext API key. Darwin returns this value only in the create
            response.
    Error:
      type: object
      additionalProperties: true
      properties:
        error:
          type: string
        message:
          type: string
        fields:
          type: array
          items:
            type: object
            additionalProperties: true
  securitySchemes:
    apiKey:
      type: apiKey
      in: header
      name: x-api-key
      x-fern-header:
        name: apiKey
        env: DARWIN_API_KEY
      description: >-
        Pass your Darwin API key in the x-api-key header. You can also
        authenticate with Authorization: Bearer <apiKey>.
    bearer:
      type: http
      scheme: bearer
      bearerFormat: Darwin API key or OAuth access token
      x-fern-bearer:
        name: token
        env: DARWIN_API_KEY
      description: >-
        Pass a Darwin API key or OAuth access token as Authorization: Bearer
        <token>. You can also pass a Darwin API key in x-api-key.
    AccountSession:
      type: apiKey
      in: cookie
      name: __Secure-better-auth.session_token
      description: >-
        The HTTP-only Darwin account session cookie set after sign-in. Local
        development uses better-auth.session_token without the __Secure- prefix.

````