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

# Create an environment

> Create a new environment

> [!NOTE]
>
> Requires an [Account API key](https://nango.dev/docs/reference/backend/http-api/api-keys.md#account-api-keys) with the `account:environments:create` scope. Create one from [Account API keys](https://app.nango.dev/api-keys) in the dashboard.

Creates a new environment. Additional environments are limited by your [pricing plan](https://www.nango.dev/pricing).

Set `is_production: true` to create a production environment. This also requires `account:environments:set_production`. The reserved name `prod` is always production and cannot be combined with `is_production: false`.

Pass `webhooks` to configure URLs and subscriptions. Set `webhooks.signing_key` to choose the environment's webhook signing key. See [Receive webhooks from Nango](https://nango.dev/docs/guides/platform/webhooks-from-nango.md) for delivery behavior, event types, and signature verification.

`webhooks.signing_key` must be a UUID v4. You should generate it using a cryptographically secure random generator, such as `crypto.randomUUID()`. The security of a supplied key depends on how you generate and protect it; Nango validates its format but cannot verify its randomness.

If omitted, Nango generates a secure random signing key.

The response returns the complete environment settings, including the plaintext webhook signing key and environment `uuid`. Use the `uuid` to [create an Environment API key](https://nango.dev/docs/reference/backend/http-api/environments/create-api-key.md) or [delete the environment](https://nango.dev/docs/reference/backend/http-api/environments/delete.md). Creating an environment also creates a default full-access Environment API key, but the secret is not returned.

```bash cURL theme={null}
curl --request POST \
  --url https://api.nango.dev/environments \
  --header 'Authorization: Bearer <NANGO-ACCOUNT-API-KEY>' \
  --header 'Content-Type: application/json' \
  --data '{
    "name": "staging",
    "webhooks": {
      "primary_url": "https://app.example.com/webhooks/nango",
      "on_sync_completion_always": false
    }
  }'
```

```json Example Response theme={null}
{
  "data": {
    "id": 123,
    "uuid": "123e4567-e89b-12d3-a456-426614174000",
    "name": "staging",
    "is_production": false,
    "callback_url": "https://api.nango.dev/oauth/callback",
    "slack_notifications": false,
    "otlp_endpoint": null,
    "otlp_headers": [],
    "webhooks": {
      "primary_url": "https://app.example.com/webhooks/nango",
      "secondary_url": null,
      "on_sync_completion_always": false,
      "on_auth_creation": true,
      "on_auth_refresh_error": true,
      "on_sync_error": true,
      "on_async_action_completion": true,
      "on_connection_deletion": true,
      "signing_key": "5f1c0d2e-6a1b-4f3c-9d8e-7b6a5c4d3e2f"
    }
  }
}
```


## OpenAPI

````yaml POST /environments
openapi: 3.1.0
info:
  title: Nango API
  description: Nango API specs used to authorize & sync data with external APIs.
  version: 1.0.0
servers:
  - url: https://api.nango.dev
    description: Production server
  - url: http://localhost:3003
    description: Local server
security:
  - bearerAuth: []
externalDocs:
  url: https://nango.dev/docs/reference/backend/http-api/authentication
paths:
  /environments:
    post:
      summary: Create an environment
      description: Create a new environment
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required:
                - name
              properties:
                name:
                  type: string
                  description: >-
                    Environment name. Lowercase letters, digits, hyphens, and
                    underscores only. Max 255 characters. The reserved name
                    `prod` is always treated as production.
                  pattern: ^[a-z0-9_-]+$
                  maxLength: 255
                  example: staging
                is_production:
                  type: boolean
                  description: >-
                    Whether to mark the environment as production. Defaults to
                    false, except for the reserved name `prod`.
                callback_url:
                  type: string
                  format: uri
                  description: Custom OAuth callback URL for this environment.
                hmac_key:
                  type: string
                  deprecated: true
                  description: >-
                    Legacy public-key authorization HMAC key. Use [Connect
                    sessions](/guides/auth/auth-guide#guide) instead.
                  maxLength: 1000
                hmac_enabled:
                  type: boolean
                  deprecated: true
                  description: >-
                    Whether legacy public-key authorization HMAC verification is
                    enabled. Use [Connect
                    sessions](/guides/auth/auth-guide#guide) instead.
                slack_notifications:
                  type: boolean
                  description: >-
                    Whether Slack notifications are enabled for this
                    environment.
                otlp_endpoint:
                  type: string
                  description: >-
                    OpenTelemetry collector endpoint. Requires a plan with
                    OpenTelemetry export. Pass an empty string to set an empty
                    endpoint.
                otlp_headers:
                  type: array
                  description: >-
                    Headers sent with OpenTelemetry export requests. Requires a
                    plan with OpenTelemetry export. Maximum 100 headers.
                  maxItems: 100
                  items:
                    type: object
                    additionalProperties: false
                    required:
                      - name
                      - value
                    properties:
                      name:
                        type: string
                        minLength: 1
                        maxLength: 256
                      value:
                        type: string
                        minLength: 1
                        maxLength: 4000
                webhooks:
                  type: object
                  additionalProperties: false
                  description: >-
                    Initial webhook settings. Omitted URLs default to null;
                    omitted subscription flags default to true.
                  properties:
                    primary_url:
                      type: string
                      description: >-
                        First webhook destination. Use an empty string for no
                        destination.
                    secondary_url:
                      type: string
                      description: >-
                        Second webhook destination. Webhooks are sent to both
                        configured URLs. Use an empty string for no destination.
                    on_sync_completion_always:
                      type: boolean
                      default: true
                      description: >-
                        Send sync completion webhooks even when no records were
                        added, updated, or deleted.
                    on_auth_creation:
                      type: boolean
                      default: true
                      description: Send webhooks when connections are created.
                    on_auth_refresh_error:
                      type: boolean
                      default: true
                      description: >-
                        Send webhooks when refreshing connection credentials
                        fails.
                    on_sync_error:
                      type: boolean
                      default: true
                      description: Send webhooks when sync functions fail.
                    on_async_action_completion:
                      type: boolean
                      default: true
                      description: >-
                        Send webhooks when deprecated asynchronous action
                        functions complete.
                    on_connection_deletion:
                      type: boolean
                      default: true
                      description: Send webhooks when connections are deleted.
                    signing_key:
                      type: string
                      format: uuid
                      description: >-
                        Key used to sign webhooks sent from this environment.
                        Must be a UUID. Defaults to a randomly generated UUID.
                      example: 5f1c0d2e-6a1b-4f3c-9d8e-7b6a5c4d3e2f
      responses:
        '200':
          description: Successfully created an environment
          content:
            application/json:
              schema:
                type: object
                required:
                  - data
                properties:
                  data:
                    type: object
                    required:
                      - id
                      - uuid
                      - name
                      - is_production
                      - callback_url
                      - slack_notifications
                      - otlp_endpoint
                      - otlp_headers
                      - webhooks
                    properties:
                      id:
                        type: integer
                        example: 123
                      uuid:
                        type: string
                        format: uuid
                        example: 123e4567-e89b-12d3-a456-426614174000
                      name:
                        type: string
                        example: staging
                      is_production:
                        type: boolean
                      callback_url:
                        type: string
                        format: uri
                      slack_notifications:
                        type: boolean
                      otlp_endpoint:
                        type:
                          - string
                          - 'null'
                      otlp_headers:
                        type: array
                        items:
                          type: object
                          required:
                            - name
                            - value
                          properties:
                            name:
                              type: string
                            value:
                              type: string
                      webhooks:
                        type: object
                        required:
                          - primary_url
                          - secondary_url
                          - on_sync_completion_always
                          - on_auth_creation
                          - on_auth_refresh_error
                          - on_sync_error
                          - on_async_action_completion
                          - on_connection_deletion
                          - signing_key
                        properties:
                          primary_url:
                            type:
                              - string
                              - 'null'
                          secondary_url:
                            type:
                              - string
                              - 'null'
                          on_sync_completion_always:
                            type: boolean
                            default: true
                          on_auth_creation:
                            type: boolean
                            default: true
                          on_auth_refresh_error:
                            type: boolean
                            default: true
                          on_sync_error:
                            type: boolean
                            default: true
                          on_async_action_completion:
                            type: boolean
                            default: true
                          on_connection_deletion:
                            type: boolean
                            default: true
                          signing_key:
                            type: string
                            format: uuid
                            example: 5f1c0d2e-6a1b-4f3c-9d8e-7b6a5c4d3e2f
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '409':
          description: An environment with this name already exists.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StdError'
        '500':
          $ref: '#/components/responses/ServerError'
components:
  responses:
    BadRequest:
      description: Bad request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/StdError'
    Unauthorized:
      description: Unauthorized
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/StdError'
    Forbidden:
      description: Forbidden
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/StdError'
    ServerError:
      description: Server error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/StdError'
  schemas:
    StdError:
      type: object
      additionalProperties: false
      properties:
        error:
          type: object
          additionalProperties: false
          required:
            - code
          properties:
            code:
              type: string
            message:
              type: string
            errors:
              type: array
              items:
                type: object
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        An Environment API key from your Nango environment, or an Account API
        key for account-level endpoints.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.