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

# Create Workspace API Key

> Mint a new API key for this workspace.

**The value is returned once, here, and cannot be retrieved again** -- store it before
discarding the response. A workspace may hold several keys, any of which
authenticates, so a key is replaced by creating its successor and revoking it after
the new one is deployed.



## OpenAPI

````yaml https://api.usetuner.ai/public/openapi.json post /api/v1/workspaces/{workspace_id}/api-keys
openapi: 3.1.0
info:
  title: My Public API
  version: 1.0.0
servers:
  - url: https://api.usetuner.ai
security: []
tags:
  - name: calls
    x-group: Calls
  - name: workspaces
    x-group: Workspaces
  - name: agent-settings
    x-group: Agent Settings
  - name: agents
    x-group: Agents
  - name: simulation
    x-group: Simulation
  - name: traces
    x-group: Traces
  - name: providers
    x-group: Providers
paths:
  /api/v1/workspaces/{workspace_id}/api-keys:
    post:
      tags:
        - workspaces
      summary: Create Workspace API Key
      description: >-
        Mint a new API key for this workspace.


        **The value is returned once, here, and cannot be retrieved again** --
        store it before

        discarding the response. A workspace may hold several keys, any of which

        authenticates, so a key is replaced by creating its successor and
        revoking it after

        the new one is deployed.
      operationId: create_workspace_api_key_api_v1_workspaces__workspace_id__api_keys_post
      parameters:
        - name: workspace_id
          in: path
          required: true
          schema:
            type: integer
            description: Workspace ID. Find this in Workspace > General Settings.
            title: Workspace Id
          description: Workspace ID. Find this in Workspace > General Settings.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/WorkspaceApiKeyCreateRequest'
      responses:
        '201':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WorkspaceApiKeyCreatedResponse'
        '401':
          description: Missing or invalid API key.
          content:
            application/json:
              example:
                detail: Not authenticated
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: You do not have access to this workspace.
          content:
            application/json:
              example:
                detail: User does not have access to workspace 42
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Workspace not found.
          content:
            application/json:
              example:
                detail: Workspace with ID 42 not found
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '409':
          description: A live key of that name already exists.
          content:
            application/json:
              example:
                detail: Duplicate name
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - Bearer: []
components:
  schemas:
    WorkspaceApiKeyCreateRequest:
      properties:
        name:
          type: string
          maxLength: 100
          minLength: 1
          title: Name
          description: >-
            Names where the key runs, e.g. 'prod'. Unique among the workspace's
            live keys.
          examples:
            - prod
      type: object
      required:
        - name
      title: WorkspaceApiKeyCreateRequest
      description: Request schema for minting a workspace API key.
    WorkspaceApiKeyCreatedResponse:
      properties:
        id:
          type: integer
          title: Id
        name:
          type: string
          title: Name
        last_four:
          type: string
          title: Last Four
        created_at:
          type: string
          format: date-time
          title: Created At
        last_used_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Last Used At
        api_key:
          type: string
          title: Api Key
          description: The full key. Shown once and never retrievable again.
      type: object
      required:
        - id
        - name
        - last_four
        - created_at
        - api_key
      title: WorkspaceApiKeyCreatedResponse
      description: >-
        A newly minted key, carrying its plaintext value.


        Separate from ``WorkspaceApiKeyResponse`` so the value cannot leak into
        the list

        endpoint by accident. This is the only response in the system that
        contains one.
    ErrorResponse:
      properties:
        detail:
          type: string
          title: Detail
          description: Human-readable description of what went wrong.
      type: object
      required:
        - detail
      title: ErrorResponse
      description: Error body returned when a request fails.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    Bearer:
      type: http
      description: >-
        Use Tuner API key (tr_api_...) or user session token. Find your API key
        in Workspace Settings > API Keys.
      scheme: bearer

````