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

> ## Agent Instructions
> Unkey is two separate products. Compute builds, deploys, and runs apps behind a gateway. API Management issues API keys, enforces rate limits, manages identities and permissions, and reports usage. Say which product a page belongs to; a reader can use either without the other.
> Every Unkey API endpoint is an HTTP POST to https://api.unkey.com/v2/{service}.{procedure} with a root key in the Authorization: Bearer header. Root keys are workspace scoped.
> Error codes have the form err:{system}:{category}:{specific} and each has a page at /errors/{system}/{category}/{specific}.
> The word environment means production or preview in Compute. Rate limiting has four meanings on this site; the glossary lists them.

# Create connection

> Connect an environment to a resource, and set what the connection gives the deployments of the environment. `config` has one member, named after the type of the resource. `app` and `environment` take an id or a slug.

An environment has one connection to each resource. If the connection exists, you get a `409`. Change its config with `connections.updateConnection`.

Deployments that run do not change. Start a new deployment to give the environment the connection.

**`planetscale_database`**

The connection gives each deployment database URLs in environment variables. `config.planetscaleDatabase.branch` takes the branch id or its name, such as `main`. The connection stores the id, so a renamed branch keeps it. `envVars` names the variable of each URL:
- `url` is the read-write URL, and is required.
- `unpooledUrl` is the read-write URL that skips PgBouncer. Only Postgres databases have it.
- `replicaUrl` turns the read-only replica URL on.

Unkey sets names that start with `UNKEY`, and app connections set names that end with `_HOST`, so a variable cannot use either.

- The branch can still provision. Each deployment needs a ready branch to get its credentials, also a deployment that a Git push starts. A deployment that starts before `databases.listBranches` shows the branch `ready` can fail, and it does not restart when the branch becomes ready. Redeploy once the branch is `ready`.
- A read-only replica URL needs a branch with replicas. Without them you get a `412`.
- A variable name that the environment already has gets a `400` that names it.

The workspace must have the `databases`, `connections` and `app_v2` flags. Without them you get a `403`.

**Required Permissions**

Your root key must be able to read the resource. For a `planetscale_database`, that is one of these permissions:
- `unkey:v1:<workspace_id>:projects/*/databases/*#read` (to read the databases of any project)
- `unkey:v1:<workspace_id>:projects/<project_id>/databases/*#read` (to read the databases of one project)
- `unkey:v1:<workspace_id>:projects/<project_id>/databases/<database_id>#read` (to read one database)

It must also be able to write the credentials of the database, because Unkey creates a credential for each deployment of the connected environment. The caller never gets the credential. That is one of these permissions:
- `unkey:v1:<workspace_id>:projects/*/databases/*/credentials/*#write` (for the databases of any project)
- `unkey:v1:<workspace_id>:projects/<project_id>/databases/*/credentials/*#write` (for the databases of one project)
- `unkey:v1:<workspace_id>:projects/<project_id>/databases/<database_id>/credentials/*#write` (for one database)

And it must be able to write the connections of the environment, with one of these permissions:
- `unkey:v1:<workspace_id>:projects/*/apps/*/environments/*/connections/*#write` (to connect any environment)
- `unkey:v1:<workspace_id>:projects/<project_id>/apps/<app_id>/environments/<environment_id>/connections/*#write` (to connect one environment)

Replace `<workspace_id>` with the authenticated workspace ID.




## OpenAPI

````yaml https://spec.speakeasy.com/unkey/unkey/openapi-json-with-code-samples post /v2/connections.createConnection
openapi: 3.1.0
info:
  description: >-
    Unkey's API provides programmatic access for all resources within our
    platform.



    ### Authentication

    #

    This API accepts HTTP Bearer credentials. Public integrations use root keys.
    Dashboard-originated requests use a short-lived dashboard proxy JWT minted
    by the dashboard server. Most endpoints require permissions associated with
    the authenticated principal. When making public API requests, include your
    root key in the `Authorization` header:

    ```

    Authorization: Bearer unkey_xxxxxxxxxxx

    ```


    All responses follow a consistent envelope structure that separates
    operational metadata from actual data. This design provides several
    benefits:

    - Debugging: Every response includes a unique requestId for tracing issues

    - Consistency: Predictable response format across all endpoints

    - Extensibility: Easy to add new metadata without breaking existing
    integrations

    - Error Handling: Unified error format with actionable information


    ### Success Response Format:

    ```json

    {
      "meta": {
        "requestId": "req_123456"
      },
      "data": {
        // Actual response data here
      }
    }

    ```


    The meta object contains operational information:

    - `requestId`: Unique identifier for this request (essential for support)


    The data object contains the actual response data specific to each endpoint.


    ### Paginated Response Format:

    ```json

    {
      "meta": {
        "requestId": "req_123456"
      },
      "data": [
        // Array of results
      ],
      "pagination": {
        "cursor": "next_page_token",
        "hasMore": true
      }
    }

    ```


    The pagination object appears on list endpoints and contains:

    - `cursor`: Token for requesting the next page

    - `hasMore`: Whether more results are available


    ### Error Response Format:

    ```json

    {
      "meta": {
        "requestId": "req_2c9a0jf23l4k567"
      },
      "error": {
        "detail": "The resource you are attempting to modify is protected and cannot be changed",
        "status": 403,
        "title": "Forbidden",
        "type": "https://unkey.com/docs/errors/unkey/application/protected_resource"
      }
    }

    ```


    Error responses include comprehensive diagnostic information:

    - `title`: Human-readable error summary

    - `detail`: Specific description of what went wrong

    - `status`: HTTP status code

    - `type`: Link to error documentation

    - `errors`: Array of validation errors (for 400 responses)


    This structure ensures you always have the context needed to debug issues
    and take corrective action.
  title: Unkey API
  version: 2.0.0
servers:
  - url: https://api.unkey.com
security:
  - bearer: []
tags:
  - description: Analytics query operations
    name: analytics
  - description: API management operations
    name: apis
  - description: App management operations
    name: apps
  - description: Deployment operations
    name: deploy
  - description: Deployment operations
    name: deployments
  - description: Custom domain operations
    name: domains
  - description: Environment management operations
    name: environments
  - description: Identity management operations
    name: identities
  - description: API key management operations
    name: keys
  - description: Health check operations
    name: liveness
  - description: Log listing operations
    name: logs
  - description: Permission and role management operations
    name: permissions
  - description: Gateway policy operations
    name: gateway
  - description: Customer Portal session management
    name: portal
  - description: Rate limiting operations
    name: ratelimit
  - description: GitHub App installation operations
    name: github
  - description: Database operations
    name: databases
  - description: >-
      Operations on the third-party accounts connected to a workspace, such as
      PlanetScale
    name: integrations
  - description: Operations on the connections of an environment to a resource
    name: connections
  - description: Workspace limits and usage operations
    name: workspace
  - description: CLI device login
    name: cli
paths:
  /v2/connections.createConnection:
    post:
      tags:
        - connections
      summary: Create connection
      description: >
        Connect an environment to a resource, and set what the connection gives
        the deployments of the environment. `config` has one member, named after
        the type of the resource. `app` and `environment` take an id or a slug.


        An environment has one connection to each resource. If the connection
        exists, you get a `409`. Change its config with
        `connections.updateConnection`.


        Deployments that run do not change. Start a new deployment to give the
        environment the connection.


        **`planetscale_database`**


        The connection gives each deployment database URLs in environment
        variables. `config.planetscaleDatabase.branch` takes the branch id or
        its name, such as `main`. The connection stores the id, so a renamed
        branch keeps it. `envVars` names the variable of each URL:

        - `url` is the read-write URL, and is required.

        - `unpooledUrl` is the read-write URL that skips PgBouncer. Only
        Postgres databases have it.

        - `replicaUrl` turns the read-only replica URL on.


        Unkey sets names that start with `UNKEY`, and app connections set names
        that end with `_HOST`, so a variable cannot use either.


        - The branch can still provision. Each deployment needs a ready branch
        to get its credentials, also a deployment that a Git push starts. A
        deployment that starts before `databases.listBranches` shows the branch
        `ready` can fail, and it does not restart when the branch becomes ready.
        Redeploy once the branch is `ready`.

        - A read-only replica URL needs a branch with replicas. Without them you
        get a `412`.

        - A variable name that the environment already has gets a `400` that
        names it.


        The workspace must have the `databases`, `connections` and `app_v2`
        flags. Without them you get a `403`.


        **Required Permissions**


        Your root key must be able to read the resource. For a
        `planetscale_database`, that is one of these permissions:

        - `unkey:v1:<workspace_id>:projects/*/databases/*#read` (to read the
        databases of any project)

        - `unkey:v1:<workspace_id>:projects/<project_id>/databases/*#read` (to
        read the databases of one project)

        -
        `unkey:v1:<workspace_id>:projects/<project_id>/databases/<database_id>#read`
        (to read one database)


        It must also be able to write the credentials of the database, because
        Unkey creates a credential for each deployment of the connected
        environment. The caller never gets the credential. That is one of these
        permissions:

        - `unkey:v1:<workspace_id>:projects/*/databases/*/credentials/*#write`
        (for the databases of any project)

        -
        `unkey:v1:<workspace_id>:projects/<project_id>/databases/*/credentials/*#write`
        (for the databases of one project)

        -
        `unkey:v1:<workspace_id>:projects/<project_id>/databases/<database_id>/credentials/*#write`
        (for one database)


        And it must be able to write the connections of the environment, with
        one of these permissions:

        -
        `unkey:v1:<workspace_id>:projects/*/apps/*/environments/*/connections/*#write`
        (to connect any environment)

        -
        `unkey:v1:<workspace_id>:projects/<project_id>/apps/<app_id>/environments/<environment_id>/connections/*#write`
        (to connect one environment)


        Replace `<workspace_id>` with the authenticated workspace ID.
      operationId: connections.createConnection
      requestBody:
        content:
          application/json:
            examples:
              connect:
                description: >-
                  Deployments of the environment get PAYMENTS_URL and
                  PAYMENTS_UNPOOLED_URL
                summary: Connect an environment to a branch
                value:
                  app: payments-api
                  config:
                    planetscaleDatabase:
                      branch: main
                      envVars:
                        unpooledUrl: PAYMENTS_UNPOOLED_URL
                        url: PAYMENTS_URL
                  environment: production
                  project: payments-service
                  resourceId: psdb_1234abcd
                  resourceType: planetscale_database
              withReadOnlyUrl:
                description: Deployments of the environment also get PAYMENTS_REPLICA_URL
                summary: Connect with a read-only replica URL
                value:
                  app: payments-api
                  config:
                    planetscaleDatabase:
                      branch: main
                      envVars:
                        replicaUrl: PAYMENTS_REPLICA_URL
                        unpooledUrl: PAYMENTS_UNPOOLED_URL
                        url: PAYMENTS_URL
                  environment: production
                  project: payments-service
                  resourceId: psdb_1234abcd
                  resourceType: planetscale_database
            schema:
              $ref: '#/components/schemas/V2ConnectionsCreateConnectionRequestBody'
        required: true
      responses:
        '200':
          content:
            application/json:
              examples:
                connected:
                  description: The environment is connected to the resource
                  summary: Environment connected
                  value:
                    data:
                      connectionId: conn_1234abcd
                    meta:
                      requestId: req_1234abcd
              schema:
                $ref: '#/components/schemas/V2ConnectionsCreateConnectionResponseBody'
          description: |
            The environment is connected with the config of the request.
        '400':
          content:
            application/json:
              examples:
                keyTaken:
                  summary: Variable name taken
                  value:
                    error:
                      detail: >-
                        The environment already has the variable PAYMENTS_URL.
                        Remove or rename it first.
                      status: 400
                      title: Bad Request
                      type: >-
                        https://unkey.com/docs/errors/unkey/application/invalid_input
                    meta:
                      requestId: req_1234abcd
              schema:
                $ref: '#/components/schemas/BadRequestErrorResponse'
          description: >-
            Bad request - The config is not valid for the resource, or the
            environment already has a variable with one of the names
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UnauthorizedErrorResponse'
          description: Unauthorized
        '403':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ForbiddenErrorResponse'
          description: >-
            Forbidden - Insufficient permissions (requires
            `unkey:v1:<workspace_id>:projects/<project_id>/databases/<database_id>/credentials/*#write`
            and
            `unkey:v1:<workspace_id>:projects/<project_id>/apps/<app_id>/environments/<environment_id>/connections/*#write`),
            the workspace does not have the `databases`, `connections` and
            `app_v2` flags, or the provider of the resource refuses access, such
            as PlanetScale for a database the connected account cannot read
        '404':
          content:
            application/json:
              examples:
                branchNotFound:
                  summary: Branch not found
                  value:
                    error:
                      detail: >-
                        PlanetScale has no branch with this id or name in this
                        database, or the database is gone.
                      status: 404
                      title: Not Found
                      type: >-
                        https://unkey.com/docs/errors/unkey/data/database_branch_not_found
                    meta:
                      requestId: req_1234abcd
                databaseNotFound:
                  summary: Database not found
                  value:
                    error:
                      detail: The requested database does not exist.
                      status: 404
                      title: Not Found
                      type: >-
                        https://unkey.com/docs/errors/unkey/data/database_not_found
                    meta:
                      requestId: req_1234abcd
                environmentNotFound:
                  summary: Environment not found
                  value:
                    error:
                      detail: The requested environment does not exist.
                      status: 404
                      title: Not Found
                      type: >-
                        https://unkey.com/docs/errors/unkey/data/environment_not_found
                    meta:
                      requestId: req_1234abcd
              schema:
                $ref: '#/components/schemas/NotFoundErrorResponse'
          description: >-
            Not Found - The resource is not in the project or is gone at its
            provider, the app or the environment does not exist in the project,
            a part of the config does not exist (such as the branch of a
            database), or the root key cannot read the resource or the
            connections of the environment
        '409':
          content:
            application/json:
              examples:
                connectionExists:
                  summary: Connection exists
                  value:
                    error:
                      detail: >-
                        The environment is already connected to this database.
                        Change the config of the connection with
                        connections.updateConnection.
                      status: 409
                      title: Conflicting Resource
                      type: >-
                        https://unkey.com/docs/errors/unkey/data/connection_already_exists
                    meta:
                      requestId: req_1234abcd
              schema:
                $ref: '#/components/schemas/ConflictErrorResponse'
          description: Conflict - The environment is already connected to the resource
        '412':
          content:
            application/json:
              examples:
                noReplicas:
                  summary: No replicas
                  value:
                    error:
                      detail: >-
                        This branch has no replicas that a read-only URL can
                        reach.
                      status: 412
                      title: Precondition Failed
                      type: >-
                        https://unkey.com/docs/errors/unkey/application/precondition_failed
                    meta:
                      requestId: req_1234abcd
              schema:
                $ref: '#/components/schemas/PreconditionFailedErrorResponse'
          description: >-
            Precondition Failed - The resource cannot take the config yet (for a
            database, the branch has no replicas for a read-only URL), or the
            provider must be connected again
        '429':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TooManyRequestsErrorResponse'
          description: >-
            Too Many Requests - Unkey or the provider of the resource rate
            limited the request
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InternalServerErrorResponse'
          description: Internal server error
        '503':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ServiceUnavailableErrorResponse'
          description: >-
            Service Unavailable - The provider of the resource did not answer or
            answered with an error
      security:
        - bearer: []
      x-codeSamples:
        - lang: go
          label: Go (SDK)
          source: "package main\n\nimport(\n\t\"context\"\n\t\"os\"\n\tunkey \"github.com/unkeyed/sdks/api/go/v4\"\n\t\"github.com/unkeyed/sdks/api/go/v4/models/components\"\n\t\"log\"\n)\n\nfunc main() {\n    ctx := context.Background()\n\n    s := unkey.New(\n        unkey.WithSecurity(os.Getenv(\"UNKEY_ROOT_KEY\")),\n    )\n\n    res, err := s.Connections.CreateConnection(ctx, components.V2ConnectionsCreateConnectionRequestBody{\n        Project: \"payments-service\",\n        ResourceID: \"psdb_1234abcd\",\n        ResourceType: components.ConnectionResourceTypePlanetscaleDatabase,\n        App: \"payments-api\",\n        Environment: \"production\",\n        Config: components.ConnectionConfig{\n            PlanetscaleDatabase: &components.PlanetscaleDatabaseConnectionConfig{\n                Branch: \"main\",\n                EnvVars: components.PlanetscaleConnectionEnvVars{\n                    URL: \"PAYMENTS_URL\",\n                    UnpooledURL: unkey.Pointer(\"PAYMENTS_UNPOOLED_URL\"),\n                },\n            },\n        },\n    })\n    if err != nil {\n        log.Fatal(err)\n    }\n    if res.V2ConnectionsCreateConnectionResponseBody != nil {\n        // handle response\n    }\n}"
        - lang: python
          label: Python (SDK)
          source: |-
            from unkey.py import Unkey, models


            with Unkey(
                root_key="<YOUR_BEARER_TOKEN_HERE>",
            ) as unkey:

                res = unkey.connections.create_connection(project="payments-service", resource_id="psdb_1234abcd", resource_type=models.ConnectionResourceType.PLANETSCALE_DATABASE, app="payments-api", environment="production", config={
                    "planetscale_database": {
                        "branch": "main",
                        "env_vars": {
                            "url": "PAYMENTS_URL",
                            "unpooled_url": "PAYMENTS_UNPOOLED_URL",
                        },
                    },
                })

                # Handle response
                print(res)
        - lang: typescript
          label: Typescript (SDK)
          source: |-
            import { Unkey } from "@unkey/api";

            const unkey = new Unkey({
              rootKey: process.env["UNKEY_ROOT_KEY"] ?? "",
            });

            async function run() {
              const result = await unkey.connections.createConnection({
                project: "payments-service",
                resourceId: "psdb_1234abcd",
                resourceType: "planetscale_database",
                app: "payments-api",
                environment: "production",
                config: {
                  planetscaleDatabase: {
                    branch: "main",
                    envVars: {
                      url: "PAYMENTS_URL",
                      unpooledUrl: "PAYMENTS_UNPOOLED_URL",
                    },
                  },
                },
              });

              console.log(result);
            }

            run();
components:
  schemas:
    V2ConnectionsCreateConnectionRequestBody:
      type: object
      required:
        - project
        - resourceId
        - resourceType
        - app
        - environment
        - config
      properties:
        project:
          $ref: '#/components/schemas/ResourceIdentifier'
        resourceId:
          $ref: '#/components/schemas/ResourceIdentifier'
        resourceType:
          $ref: '#/components/schemas/ConnectionResourceType'
        app:
          $ref: '#/components/schemas/ResourceIdentifier'
        environment:
          $ref: '#/components/schemas/ResourceIdentifier'
        config:
          $ref: '#/components/schemas/ConnectionConfig'
      additionalProperties: false
    V2ConnectionsCreateConnectionResponseBody:
      type: object
      required:
        - meta
        - data
      properties:
        meta:
          $ref: '#/components/schemas/Meta'
        data:
          $ref: '#/components/schemas/V2ConnectionsCreateConnectionResponseData'
      additionalProperties: false
    BadRequestErrorResponse:
      type: object
      required:
        - meta
        - error
      properties:
        meta:
          $ref: '#/components/schemas/Meta'
        error:
          $ref: '#/components/schemas/BadRequestErrorDetails'
      description: >-
        Error response for invalid requests that cannot be processed due to
        client-side errors. This typically occurs when request parameters are
        missing, malformed, or fail validation rules. The response includes
        detailed information about the specific errors in the request, including
        the location of each error and suggestions for fixing it. When receiving
        this error, check the 'errors' array in the response for specific
        validation issues that need to be addressed before retrying.
    UnauthorizedErrorResponse:
      type: object
      required:
        - meta
        - error
      properties:
        meta:
          $ref: '#/components/schemas/Meta'
        error:
          $ref: '#/components/schemas/BaseError'
      description: >-
        Error response when authentication has failed or credentials are
        missing. This occurs when:

        - No authentication token is provided in the request

        - The provided token is invalid, expired, or malformed

        - The token format doesn't match expected patterns


        To resolve this error, ensure you're including a valid root key in the
        Authorization header.
    ForbiddenErrorResponse:
      type: object
      required:
        - meta
        - error
      properties:
        meta:
          $ref: '#/components/schemas/Meta'
        error:
          $ref: '#/components/schemas/BaseError'
      description: >-
        Error response when the provided credentials are valid but lack
        sufficient permissions for the requested operation. This occurs when:

        - The root key doesn't have the required permissions for this endpoint

        - The operation requires elevated privileges that the current key lacks

        - Access to the requested resource is restricted based on workspace
        settings


        To resolve this error, ensure your root key has the necessary
        permissions or contact your workspace administrator.
    NotFoundErrorResponse:
      type: object
      required:
        - meta
        - error
      properties:
        meta:
          $ref: '#/components/schemas/Meta'
        error:
          $ref: '#/components/schemas/BaseError'
      description: >-
        Error response when the requested resource cannot be found. This occurs
        when:

        - The specified resource ID doesn't exist in your workspace

        - The resource has been deleted or moved

        - The resource exists but is not accessible with current permissions


        To resolve this error, verify the resource ID is correct and that you
        have access to it.
    ConflictErrorResponse:
      type: object
      required:
        - meta
        - error
      properties:
        meta:
          $ref: '#/components/schemas/Meta'
        error:
          $ref: '#/components/schemas/BaseError'
      description: >-
        Error response when the request conflicts with the current state of the
        resource. This occurs when:

        - Attempting to create a resource that already exists

        - Modifying a resource that has been changed by another operation

        - Violating unique constraints or business rules


        To resolve this error, check the current state of the resource and
        adjust your request accordingly.
    PreconditionFailedErrorResponse:
      type: object
      required:
        - meta
        - error
      properties:
        meta:
          $ref: '#/components/schemas/Meta'
        error:
          $ref: '#/components/schemas/BaseError'
      description: >-
        Error response when one or more conditions specified in the request
        headers are not met. This typically occurs when:

        - Using conditional requests with If-Match or If-None-Match headers

        - The resource version doesn't match the expected value

        - Optimistic concurrency control detects a conflict


        To resolve this error, fetch the latest version of the resource and
        retry with updated conditions.
    TooManyRequestsErrorResponse:
      type: object
      required:
        - meta
        - error
      properties:
        meta:
          $ref: '#/components/schemas/Meta'
        error:
          $ref: '#/components/schemas/BaseError'
      description: >-
        Error response when the client has sent too many requests in a given
        time period. This occurs when you've exceeded a rate limit or quota for
        the resource you're accessing.


        The rate limit resets automatically after the time window expires. To
        avoid this error:

        - Implement exponential backoff when retrying requests

        - Cache results where appropriate to reduce request frequency

        - Check the error detail message for specific quota information

        - Contact support if you need a higher quota for your use case
    InternalServerErrorResponse:
      type: object
      required:
        - meta
        - error
      properties:
        meta:
          $ref: '#/components/schemas/Meta'
        error:
          $ref: '#/components/schemas/BaseError'
      description: >-
        Error response when an unexpected error occurs on the server. This
        indicates a problem with Unkey's systems rather than your request.


        When you encounter this error:

        - The request ID in the response can help Unkey support investigate the
        issue

        - The error is likely temporary and retrying may succeed

        - If the error persists, contact Unkey support with the request ID
    ServiceUnavailableErrorResponse:
      type: object
      required:
        - meta
        - error
      properties:
        meta:
          $ref: '#/components/schemas/Meta'
        error:
          $ref: '#/components/schemas/BaseError'
      description: >-
        Error response when a required service is temporarily unavailable. This
        indicates that the service exists but cannot be reached or is not
        responding.


        When you encounter this error:

        - The service is likely experiencing temporary issues

        - Retrying the request after a short delay may succeed

        - If the error persists, the service may be undergoing maintenance

        - Contact Unkey support if the issue continues
    ResourceIdentifier:
      type: string
      minLength: 3
      maxLength: 255
      pattern: ^[a-zA-Z0-9_-]+$
      description: |
        Identifies a resource by either its unique ID or its slug.
        Accepts a prefixed ID (such as 'proj_' or 'app_') or a slug.
      example: proj_1234abcd
    ConnectionResourceType:
      type: string
      enum:
        - planetscale_database
      x-enum-varnames:
        - ConnectionResourceTypePlanetscaleDatabase
      description: The type of the resource that an environment connects to.
      example: planetscale_database
    ConnectionConfig:
      type: object
      description: >-
        The config of a connection. It has one member, named after the type of
        the resource.
      properties:
        planetscaleDatabase:
          $ref: '#/components/schemas/PlanetscaleDatabaseConnectionConfig'
      additionalProperties: false
    Meta:
      type: object
      required:
        - requestId
      properties:
        requestId:
          description: >-
            A unique id for this request. Always include this ID when contacting
            support about a specific API request. This identifier allows Unkey's
            support team to trace the exact request through logs and diagnostic
            systems to provide faster assistance.
          example: req_123
          type: string
      additionalProperties: false
      description: >-
        Metadata object included in every API response. This provides context
        about the request and is essential for debugging, audit trails, and
        support inquiries. The `requestId` is particularly important when
        troubleshooting issues with the Unkey support team.
    V2ConnectionsCreateConnectionResponseData:
      type: object
      required:
        - connectionId
      properties:
        connectionId:
          type: string
          description: >-
            The id of the new connection. Use it with
            `connections.updateConnection`.
          example: conn_1234abcd
      additionalProperties: false
    BadRequestErrorDetails:
      allOf:
        - $ref: '#/components/schemas/BaseError'
        - type: object
          properties:
            errors:
              description: >-
                List of individual validation errors that occurred in the
                request. Each error provides specific details about what failed
                validation, where the error occurred in the request, and
                suggestions for fixing it. This granular information helps
                developers quickly identify and resolve multiple issues in a
                single request without having to make repeated API calls.
              items:
                $ref: '#/components/schemas/ValidationError'
              type: array
          required:
            - errors
      description: >-
        Extended error details specifically for bad request (400) errors. This
        builds on the BaseError structure by adding an array of individual
        validation errors, making it easy to identify and fix multiple issues at
        once.
    BaseError:
      properties:
        detail:
          description: >-
            A human-readable explanation specific to this occurrence of the
            problem. This provides detailed information about what went wrong
            and potential remediation steps. The message is intended to be
            helpful for developers troubleshooting the issue.
          example: Property foo is required but is missing.
          type: string
        status:
          description: >-
            HTTP status code that corresponds to this error. This will match the
            status code in the HTTP response. Common codes include `400` (Bad
            Request), `401` (Unauthorized), `403` (Forbidden), `404` (Not
            Found), `409` (Conflict), and `500` (Internal Server Error).
          example: 404
          format: int
          type: integer
        title:
          description: >-
            A short, human-readable summary of the problem type. This remains
            constant from occurrence to occurrence of the same problem and
            should be used for programmatic handling.
          example: Not Found
          type: string
        type:
          description: >-
            A URI reference that identifies the problem type. This provides a
            stable identifier for the error that can be used for documentation
            lookups and programmatic error handling. When followed, this URI
            should provide human-readable documentation for the problem type.
          example: https://unkey.com/docs/errors/unkey/resource/not_found
          type: string
      required:
        - title
        - detail
        - status
        - type
      type: object
      additionalProperties: false
      description: >-
        Base error structure following Problem Details for HTTP APIs (RFC 7807).
        This provides a standardized way to carry machine-readable details of
        errors in HTTP response content.
    PlanetscaleDatabaseConnectionConfig:
      type: object
      description: How an environment connects to a PlanetScale database.
      required:
        - branch
        - envVars
      properties:
        branch:
          type: string
          minLength: 1
          maxLength: 256
          pattern: ^[A-Za-z0-9][A-Za-z0-9._-]*$
          description: >
            The branch in PlanetScale that the environment connects to. A
            request takes its id or its name, such as `main`. A response has its
            id, so a renamed branch keeps its connection.
            `databases.listBranches` has both.
          example: b4n8w2yc6rtv
        envVars:
          $ref: '#/components/schemas/PlanetscaleConnectionEnvVars'
      additionalProperties: false
    ValidationError:
      additionalProperties: false
      properties:
        location:
          description: >-
            JSON path indicating exactly where in the request the error
            occurred. This helps pinpoint the problematic field or parameter.
            Examples include:

            - 'body.name' (field in request body)

            - 'body.items[3].tags' (nested array element)

            - 'path.apiId' (path parameter)

            - 'query.limit' (query parameter)

            Use this location to identify exactly which part of your request
            needs correction.
          type: string
          example: body.permissions[0].name
        message:
          description: >-
            Detailed error message explaining what validation rule was violated.
            This provides specific information about why the field or parameter
            was rejected, such as format errors, invalid values, or constraint
            violations.
          type: string
          example: Must be at least 3 characters long
        fix:
          description: >-
            A human-readable suggestion describing how to fix the error. This
            provides practical guidance on what changes would satisfy the
            validation requirements. Not all validation errors include fix
            suggestions, but when present, they offer specific remediation
            advice.
          type: string
          example: >-
            Ensure the name uses only alphanumeric characters, underscores, and
            hyphens
      required:
        - location
        - message
      type: object
      description: >-
        Individual validation error details. Each validation error provides
        precise information about what failed, where it failed, and how to fix
        it, enabling efficient error resolution.
    PlanetscaleConnectionEnvVars:
      type: object
      description: >
        The names of the environment variables that each deployment of the
        environment gets. Each one has a connection URL. Leave out an optional
        member and deployments do not get that URL.
      required:
        - url
      properties:
        url:
          type: string
          minLength: 1
          maxLength: 256
          pattern: ^[A-Za-z_][A-Za-z0-9_]*$
          description: >-
            The variable with the read-write URL. On Postgres it goes through
            PgBouncer.
          example: PAYMENTS_URL
        unpooledUrl:
          type: string
          minLength: 1
          maxLength: 256
          pattern: ^[A-Za-z_][A-Za-z0-9_]*$
          description: >-
            The variable with the read-write URL that skips PgBouncer. Only
            Postgres databases have it.
          example: PAYMENTS_UNPOOLED_URL
        replicaUrl:
          type: string
          minLength: 1
          maxLength: 256
          pattern: ^[A-Za-z_][A-Za-z0-9_]*$
          description: >-
            The variable with the read-only URL that reads from the replicas.
            The branch must have replicas.
          example: PAYMENTS_REPLICA_URL
      additionalProperties: false
  securitySchemes:
    bearer:
      bearerFormat: bearer token
      description: >-
        Unkey uses bearer tokens for authentication. Public integrations use
        root keys, while the dashboard proxy uses short-lived JWTs.

        To authenticate, include the token in the Authorization header of each
        request:

        ```

        Authorization: Bearer unkey_123

        ```

        Root keys have specific permissions attached to them, controlling what
        operations they can perform. Resource permissions use Unkey Resource
        Names plus actions, like
        `unkey:v1:ws_123:projects/*/keyspaces/*/keys/*#write`.

        Security best practices:

        - Keep root keys secure and never expose them in client-side code

        - Use different root keys for different environments

        - Rotate keys periodically, especially after team member departures

        - Create keys with minimal necessary permissions following least
        privilege principle

        - Monitor key usage with audit logs.
      scheme: bearer
      type: http
      x-speakeasy-name-override: rootKey

````

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