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

# Create Tool Env Var

Create a tool-scoped environment variable. Tool-level variables take precedence over workspace-level variables with the same key when the tool executes.


## OpenAPI

````yaml POST /api/public/v2/tool-registry/{identifier}/env-vars
openapi: 3.1.0
info:
  title: FastAPI
  version: 0.1.0
servers: []
security:
  - ApiKeyAuth: []
paths:
  /api/public/v2/tool-registry/{identifier}/env-vars:
    post:
      tags:
        - env-vars
        - tool-registry
      summary: Create Tool Env Var
      operationId: create_tool_env_var
      parameters:
        - name: identifier
          in: path
          required: true
          schema:
            type: string
            description: Tool ID (numeric) or name
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - key
              properties:
                key:
                  type: string
                  minLength: 1
                  maxLength: 255
                  pattern: ^[A-Za-z_][A-Za-z0-9_]*$
                  description: >-
                    Environment variable name. Must start with a letter or
                    underscore and contain only letters, digits, and
                    underscores.
                value:
                  type: string
                  maxLength: 8192
                  description: >-
                    Value to store. May be empty to create a placeholder that
                    the user will fill in later.
      responses:
        '201':
          description: Successful Response
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  tool_env_var:
                    type: object
                    properties:
                      id:
                        type: integer
                      key:
                        type: string
                      value_suffix:
                        type: string
                        nullable: true
                        description: >-
                          Last 4 characters of the stored value. Null or empty
                          when the value is empty.
                      is_empty:
                        type: boolean
                        description: >-
                          True when the value has not been set yet (placeholder
                          created by the AI assistant).
                      created_at:
                        type: string
                        format: date-time
                      updated_at:
                        type: string
                        format: date-time
                      workspace_id:
                        type: integer
                        description: Present on workspace-scoped env vars.
                      tool_registry_id:
                        type: integer
                        description: Present on tool-scoped env vars.
        '401':
          $ref: '#/components/responses/UnauthorizedError'
        '404':
          description: Tool not found.
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
        '409':
          description: An environment variable with that key already exists on this tool.
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
        '422':
          $ref: '#/components/responses/ValidationError'
components:
  responses:
    UnauthorizedError:
      description: Unauthorized - missing or invalid API key.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    ValidationError:
      description: Validation error - request parameters or body are invalid.
      content:
        application/json:
          schema:
            oneOf:
              - $ref: '#/components/schemas/HTTPValidationError'
              - $ref: '#/components/schemas/ErrorResponse'
  schemas:
    ErrorResponse:
      type: object
      properties:
        success:
          type: boolean
          default: false
          description: Indicates that the request failed.
        message:
          type: string
          description: Human-readable error message.
        error:
          type: string
          description: Machine-readable or fallback error message.
      additionalProperties: true
      description: >-
        Standard error response. Some legacy endpoints may return either message
        or error.
    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
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-KEY

````