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

# Create API key

> Create a new API key in a workspace.



## OpenAPI

````yaml post /workspaces/{workspaceId}/api-keys
openapi: 3.0.3
info:
  contact:
    email: support@openlayer.com
    name: Openlayer
    url: https://openlayer.com/
  description: API for interacting with the Openlayer server.
  title: Openlayer API
  version: '1.0'
  x-logo:
    url: https://logo.clearbit.com/openlayer.com
servers:
  - url: https://api.openlayer.com/v1
    description: Our prod backend
security:
  - bearerAuth: []
paths:
  /workspaces/{workspaceId}/api-keys:
    post:
      summary: Create a new API key in a workspace.
      description: Create a new API key in a workspace.
      operationId: createApiKeyInWorkspace
      parameters:
        - $ref: '#/components/parameters/workspaceId'
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name: c93186a2-0b0a-4c5a-92f2-fbdcb174d0f3
      responses:
        '201':
          description: Status Created.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiKey'
      x-codeSamples:
        - lang: python
          source: |
            from openlayer import Openlayer

            client = Openlayer()
            api_key = client.workspaces.api_keys.create(
              workspace_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
              name="My API Key"
            )
        - lang: typescript
          source: |
            import Openlayer from 'openlayer';

            const openlayer = new Openlayer();
            apiKey = await openlayer.workspaces.apiKeys.create(
              {workspace_id: "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", name: "My API Key"}
            )
        - lang: go
          source: |
            package main

            import (
              "context"

              "github.com/openlayer-ai/openlayer-go"
              "github.com/openlayer-ai/openlayer-go/option"
            )

            client := openlayer.NewClient()
            apiKey, err := client.Workspaces.APIKeys.New(
              context.TODO(),
              "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
              openlayer.WorkspaceAPIKeyNewParams{
                Name: openlayer.F("My API Key"),
              },
            )
        - lang: java
          source: >
            import com.openlayer.api.client.OpenlayerClient;

            import com.openlayer.api.client.okhttp.OpenlayerOkHttpClient;

            import com.openlayer.api.models.WorkspaceAPIKeyNewParams;

            import com.openlayer.api.models.WorkspaceAPIKeyNewResponse;


            OpenlayerClient client = OpenlayerOkHttpClient.fromEnv();


            WorkspaceAPIKeyNewParams params =
            WorkspaceAPIKeyNewParams.builder().build();

            WorkspaceAPIKeyNewResponse response =
            client.workspaces().apiKeys().new(params);
        - lang: curl
          source: |
            curl --request POST \
              --url https://api.openlayer.com/v1/workspaces/182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e/api-keys \
              --header 'Authorization: Bearer <token>' \
              --data '{
                "name": "My API Key"
              }'
components:
  parameters:
    workspaceId:
      name: workspaceId
      in: path
      description: The workspace id.
      required: true
      schema:
        type: string
        format: uuid
  schemas:
    ApiKey:
      type: object
      properties:
        id:
          type: string
          format: uuid
          description: The API key id.
          readOnly: true
        name:
          type: string
          nullable: true
          maxLength: 120
          example: Secret Key
          description: The API key name.
        dateCreated:
          type: string
          format: date-time
          readOnly: true
          description: The API key creation date.
        dateUpdated:
          type: string
          format: date-time
          readOnly: true
          description: The API key last update date.
        dateLastUsed:
          type: string
          format: date-time
          readOnly: true
          nullable: true
          description: The API key last use date.
        secureKey:
          type: string
          example: sk-ol-*************************5PW0
          maxLength: 120
          readOnly: true
          description: The API key value.
      required:
        - id
        - dateCreated
        - dateUpdated
        - dateLastUsed
        - secureKey
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >
        Bearer authentication header of the form `Bearer <token>`, where
        `<token>` is your workspace API key. See [Find your API
        key](https://www.openlayer.com/docs/workspace-and-projects/find-your-api-key)
        for more information.

````