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

# Create function secret

> Create a secret for this function. Secrets are injected as environment variables when your function executes.

Use secrets to store sensitive data without hardcoding in function code:
- API keys (Stripe, OpenAI, Twilio, etc.)
- External service connection strings
- OAuth credentials
- Service account tokens

Requirements:
- Function must be in 'deployed' status (422 if not)
- Secret name must be uppercase alphanumeric with underscores (e.g., STRIPE_API_KEY)
- Secret name must be unique within the function

Secret types are automatically detected:
- String values → text type
- Object/array values → json type

Important: The secret value is only returned in the creation response. It cannot be retrieved later. Store the value securely after creation if needed.

After creating a secret, it's immediately available in your function as an environment variable with the specified name.




## OpenAPI

````yaml /api/platform/v1/openapi-workflows.yaml post /functions/{function_id}/secrets
openapi: 3.1.0
info:
  title: Kapso Platform API – Advanced Resources
  version: 0.1.0
  description: >
    Build WhatsApp automation workflows and serverless functions. Create
    multi-step conversation flows, inspect executions, and deploy custom logic.
servers:
  - url: https://api.kapso.ai/platform/v1
    description: Production
security:
  - ApiKeyAuth: []
tags:
  - name: Workflows
    description: Create and manage conversation workflows and executions
  - name: Workflow Triggers
    description: Configure workflow triggers to automate execution
  - name: Functions
    description: Manage serverless functions, deployments, and secrets
  - name: WhatsApp Conversations
    description: Query WhatsApp conversation data and related resources
paths:
  /functions/{function_id}/secrets:
    parameters:
      - name: function_id
        in: path
        required: true
        schema:
          type: string
          format: uuid
        description: Function identifier
    post:
      tags:
        - Functions
      summary: Create function secret
      description: >
        Create a secret for this function. Secrets are injected as environment
        variables when your function executes.


        Use secrets to store sensitive data without hardcoding in function code:

        - API keys (Stripe, OpenAI, Twilio, etc.)

        - External service connection strings

        - OAuth credentials

        - Service account tokens


        Requirements:

        - Function must be in 'deployed' status (422 if not)

        - Secret name must be uppercase alphanumeric with underscores (e.g.,
        STRIPE_API_KEY)

        - Secret name must be unique within the function


        Secret types are automatically detected:

        - String values → text type

        - Object/array values → json type


        Important: The secret value is only returned in the creation response.
        It cannot be retrieved later. Store the value securely after creation if
        needed.


        After creating a secret, it's immediately available in your function as
        an environment variable with the specified name.
      operationId: createFunctionSecret
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/FunctionSecretCreateRequest'
            examples:
              api_key:
                summary: API key secret
                value:
                  secret:
                    name: STRIPE_API_KEY
                    value: sk_test_abc123xyz
              json_config:
                summary: JSON configuration secret
                value:
                  secret:
                    name: DATABASE_CONFIG
                    value:
                      host: db.example.com
                      port: 5432
                      database: production
      responses:
        '201':
          description: Secret created successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SimpleMessageResponse'
              example:
                message: Secret created successfully
        '401':
          $ref: '#/components/responses/UnauthorizedError'
        '404':
          $ref: '#/components/responses/NotFoundError'
        '422':
          description: Validation error or function not deployed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                not_deployed:
                  summary: Function not deployed
                  value:
                    error: Function must be deployed before creating secrets
                invalid_name:
                  summary: Invalid secret name format
                  value:
                    error: >-
                      Secret name must be uppercase alphanumeric with
                      underscores
        '502':
          description: Error communicating with Cloudflare API
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                error: Failed to create secret in Cloudflare
components:
  schemas:
    FunctionSecretCreateRequest:
      type: object
      required:
        - secret
      properties:
        secret:
          type: object
          required:
            - name
            - value
          properties:
            name:
              type: string
              description: >
                Secret name (used as environment variable in function). Must be
                uppercase alphanumeric with underscores. Will be available in
                your function as an environment variable.
              pattern: ^[A-Z0-9_]+$
              example: STRIPE_API_KEY
            value:
              type:
                - string
                - object
              description: >
                Secret value. For text secrets: provide a string. For JSON
                secrets: provide an object or array. The type will be
                automatically detected based on the value structure.
              example: sk_test_abc123xyz
      description: >
        Request to create a function secret. Secrets are injected as environment
        variables when your function executes. Use this to store API keys,
        credentials, or configuration without hardcoding them in your function
        code.
    SimpleMessageResponse:
      type: object
      required:
        - message
      properties:
        message:
          type: string
          description: Success or confirmation message
      description: Simple message response for operations that don't return resource data
    ErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          type: string
          description: Human-readable error message
  responses:
    UnauthorizedError:
      description: Missing or invalid API key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    NotFoundError:
      description: Resource not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key

````