---
title: "Create function secret"
method: POST
path: "/functions/{function_id}/secrets"
tags: ["Functions"]
---

# Create function secret

`POST /functions/{function_id}/secrets`

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.

## Request body

- FunctionSecretCreateRequest — 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.
  - `secret` object, required
    - `name` string, required — Secret name (used as environment variable in function). Must be uppercase alphanumeric with underscores. Will be available in your function as an environment variable.
    - `value` union, required — 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.
      - string
      - object

## Response `201`

Secret created successfully

- SimpleMessageResponse — Simple message response for operations that don't return resource data
  - `message` string, required — Success or confirmation message

## Other responses

- `401` — Missing or invalid API key
- `404` — Resource not found
- `422` — Validation error or function not deployed
- `502` — Error communicating with Cloudflare API

---

[API](https://skmtc.net/kapso/apis/kapso-platform-api.md) · [All operations](https://skmtc.net/kapso/apis/kapso-platform-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/kapso/kapso-platform-api/versions/18ff5548a33f/schema)
