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

# Create a sub-custodian API key

> Creates an environment-scoped Portal API key for a sub-custodian owned
by the authenticated reseller. The raw API key value is returned only in
this creation response.




## OpenAPI

````yaml /openapi/reseller-api.yaml post /resellers/custodians/{custodianId}/environments/{environmentId}/api-keys
openapi: 3.1.0
info:
  title: Portal Reseller API
  version: '3.0'
  description: >
    The Portal Reseller API lets approved reseller custodians create and manage

    sub-custodians. Reseller API keys are environment-agnostic and authenticate

    the reseller custodian. Sub-custodian Portal API keys created through this
    API

    are scoped to a specific sub-custodian environment.


    ## Base URL

    `https://api.portalhq.io/api/v3`


    ## Authentication

    Include your Reseller API key as a Bearer token in the `Authorization`
    header

    of every request.
servers:
  - url: https://api.portalhq.io/api/v3
    description: Production
security:
  - bearerAuth: []
tags:
  - name: Sub-Custodians
    description: Create, list, and suspend sub-custodians
  - name: Sub-Custodian Environments
    description: View environments for sub-custodians
  - name: Sub-Custodian API Keys
    description: Create and delete sub-custodian Portal API keys
paths:
  /resellers/custodians/{custodianId}/environments/{environmentId}/api-keys:
    post:
      tags:
        - Sub-Custodian API Keys
      summary: Create a sub-custodian API key
      description: |
        Creates an environment-scoped Portal API key for a sub-custodian owned
        by the authenticated reseller. The raw API key value is returned only in
        this creation response.
      operationId: createSubCustodianApiKey
      parameters:
        - $ref: '#/components/parameters/custodianId'
        - $ref: '#/components/parameters/environmentId'
      requestBody:
        required: false
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateSubCustodianApiKeyRequest'
            example:
              name: Production API key
      responses:
        '200':
          description: Sub-custodian API key created successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SubCustodianApiKeyResponse'
              example:
                apiKey:
                  id: api_key_123
                  custodianId: custodian_123
                  environmentId: env_prod_123
                  name: Production API key
                  value: 7b7f27c4-6a73-4d93-a703-0d2f22b63e64
                  createdAt: '2026-07-08T18:00:00.000Z'
                  updatedAt: '2026-07-08T18:00:00.000Z'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
components:
  parameters:
    custodianId:
      name: custodianId
      in: path
      required: true
      description: The ID of a sub-custodian owned by the authenticated reseller.
      schema:
        type: string
    environmentId:
      name: environmentId
      in: path
      required: true
      description: The ID of an environment that belongs to the sub-custodian.
      schema:
        type: string
  schemas:
    CreateSubCustodianApiKeyRequest:
      type: object
      properties:
        name:
          type: string
          description: Optional name for the sub-custodian Portal API key.
    SubCustodianApiKeyResponse:
      type: object
      required:
        - apiKey
      properties:
        apiKey:
          $ref: '#/components/schemas/SubCustodianApiKey'
    SubCustodianApiKey:
      type: object
      properties:
        id:
          type: string
        custodianId:
          type: string
        environmentId:
          type: string
        name:
          type: string
        value:
          type: string
          description: Raw Portal API key value. Returned only when the key is created.
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
    ErrorResponse:
      type: object
      properties:
        error:
          type: string
  responses:
    BadRequest:
      description: Bad request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Unauthorized:
      description: Unauthorized - invalid or missing Reseller API key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Forbidden:
      description: >-
        Forbidden - the authenticated custodian is not allowed to perform this
        action
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    NotFound:
      description: Resource not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Conflict:
      description: Resource conflict
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: Reseller API Key
      description: Reseller API key created in the Portal dashboard.

````