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

# Update policy

> Update a single policy in place without resending the environment's full
policy list. The policy keeps its id and its position in the evaluation
order, and all other policies are untouched.

Omitted fields keep their stored values; at least one updatable field
must be provided. Setting `match` to null removes all match expressions
so the policy applies to every request. Providing one of `keyauth`,
`ratelimit`, `firewall` or `openapi` replaces the policy's rule
entirely, including switching its type; at most one may be set.

Policy ids are regenerated whenever `gateway.setPolicies` replaces the
list, so fetch current ids via `gateway.listPolicies` first.

**Required Permissions**

Your root key must have one of the following permissions:
- `environment.*.update_policy` (for any environment)
- `environment.<environment_id>.update_policy` (for a specific environment)




## OpenAPI

````yaml https://spec.speakeasy.com/unkey/unkey/openapi-json-with-code-samples post /v2/gateway.updatePolicy
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: 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: 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
paths:
  /v2/gateway.updatePolicy:
    post:
      tags:
        - gateway
      summary: Update policy
      description: >
        Update a single policy in place without resending the environment's full

        policy list. The policy keeps its id and its position in the evaluation

        order, and all other policies are untouched.


        Omitted fields keep their stored values; at least one updatable field

        must be provided. Setting `match` to null removes all match expressions

        so the policy applies to every request. Providing one of `keyauth`,

        `ratelimit`, `firewall` or `openapi` replaces the policy's rule

        entirely, including switching its type; at most one may be set.


        Policy ids are regenerated whenever `gateway.setPolicies` replaces the

        list, so fetch current ids via `gateway.listPolicies` first.


        **Required Permissions**


        Your root key must have one of the following permissions:

        - `environment.*.update_policy` (for any environment)

        - `environment.<environment_id>.update_policy` (for a specific
        environment)
      operationId: gateway.updatePolicy
      requestBody:
        content:
          application/json:
            examples:
              clearMatch:
                summary: Remove all match expressions
                value:
                  app: payments-api
                  environment: production
                  match: null
                  policyId: pol_9d2Fk1LmQ
                  project: payments
              disable:
                summary: Disable a policy without touching its rule
                value:
                  app: payments-api
                  enabled: false
                  environment: production
                  policyId: pol_9d2Fk1LmQ
                  project: payments
              rename:
                summary: Rename a policy
                value:
                  app: payments-api
                  environment: production
                  name: Require API key (v2)
                  policyId: pol_9d2Fk1LmQ
                  project: payments
              switchRule:
                summary: Replace the policy's rule with a firewall deny
                value:
                  app: payments-api
                  environment: production
                  firewall:
                    action: ACTION_DENY
                  policyId: pol_9d2Fk1LmQ
                  project: payments
            schema:
              $ref: '#/components/schemas/V2GatewayUpdatePolicyRequestBody'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/V2GatewayUpdatePolicyResponseBody'
          description: |
            Successfully updated the policy.
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BadRequestErrorResponse'
          description: Bad request
        '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
            `environment.*.update_policy`)
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NotFoundErrorResponse'
          description: >-
            Not Found - The environment, policy, or a referenced keyspace does
            not exist in your workspace
        '429':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/TooManyRequestsErrorResponse'
          description: Too Many Requests
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InternalServerErrorResponse'
          description: Internal server error
      security:
        - bearer: []
      x-codeSamples:
        - lang: python
          label: Python (SDK)
          source: |-
            from unkey.py import Unkey, models


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

                res = unkey.gateway.update_policy(project="payments", app="payments-api", environment="production", policy_id="pol_9d2Fk1LmQ", match=None, keyauth={
                    "keyspaces": [
                        "ks_1234abcd",
                    ],
                }, ratelimit={
                    "limit": 100,
                    "window_ms": 60000,
                    "identifier": {
                        "remote_ip": {},
                    },
                }, firewall={
                    "action": models.Action.ACTION_DENY,
                }, openapi={})

                # 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.gateway.updatePolicy({
                project: "payments",
                app: "payments-api",
                environment: "production",
                policyId: "pol_9d2Fk1LmQ",
                match: null,
              });

              console.log(result);
            }

            run();
        - lang: go
          label: Go (SDK)
          source: "package main\n\nimport(\n\t\"context\"\n\t\"os\"\n\tunkey \"github.com/unkeyed/sdks/api/go/v2\"\n\t\"github.com/unkeyed/sdks/api/go/v2/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.Gateway.UpdatePolicy(ctx, components.V2GatewayUpdatePolicyRequestBody{\n        Project: \"payments\",\n        App: \"payments-api\",\n        Environment: \"production\",\n        PolicyID: \"pol_9d2Fk1LmQ\",\n        Match: nil,\n    })\n    if err != nil {\n        log.Fatal(err)\n    }\n    if res.V2GatewayUpdatePolicyResponseBody != nil {\n        // handle response\n    }\n}"
components:
  schemas:
    V2GatewayUpdatePolicyRequestBody:
      type: object
      required:
        - project
        - app
        - environment
        - policyId
      properties:
        project:
          $ref: '#/components/schemas/ResourceIdentifier'
        app:
          $ref: '#/components/schemas/ResourceIdentifier'
        environment:
          $ref: '#/components/schemas/ResourceIdentifier'
        policyId:
          type: string
          minLength: 1
          maxLength: 512
          description: >-
            Id of the policy to update, as returned by `gateway.listPolicies`.

            Ids are regenerated whenever `gateway.setPolicies` replaces the
            list,

            so list the policies first if you are unsure the id is current.
          example: pol_9d2Fk1LmQ
        name:
          type: string
          minLength: 1
          maxLength: 256
          description: New human-readable name. Omit to keep the current name.
        enabled:
          type: boolean
          description: >-
            Enable or disable the policy. Disabled policies are stored but
            skipped

            during evaluation. Omit to keep the current setting.
        match:
          type:
            - array
            - 'null'
          maxItems: 10
          items:
            $ref: '#/components/schemas/MatchExpr'
          description: >-
            Replaces all match expressions. Set null to remove them so the
            policy

            applies to every request. Omit to keep the current expressions.
        keyauth:
          $ref: '#/components/schemas/KeyauthPolicy'
        ratelimit:
          $ref: '#/components/schemas/RatelimitPolicy'
        firewall:
          $ref: '#/components/schemas/FirewallPolicy'
        openapi:
          $ref: '#/components/schemas/OpenapiPolicy'
      additionalProperties: false
      description: |-
        Partial update of a single policy. Omitted fields keep their stored
        values; at least one updatable field must be provided. Providing one of
        `keyauth`, `ratelimit`, `firewall` or `openapi` replaces the policy's
        rule entirely, including switching its type; at most one may be set.
    V2GatewayUpdatePolicyResponseBody:
      type: object
      required:
        - meta
        - data
      properties:
        meta:
          $ref: '#/components/schemas/Meta'
        data:
          $ref: '#/components/schemas/EmptyResponse'
      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.
    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
    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
    MatchExpr:
      type: object
      properties:
        path:
          $ref: '#/components/schemas/PathMatch'
        method:
          $ref: '#/components/schemas/MethodMatch'
        header:
          $ref: '#/components/schemas/FieldMatch'
        queryParam:
          $ref: '#/components/schemas/FieldMatch'
      additionalProperties: false
      description: |-
        A single request match expression. Exactly one of `path`, `method`,
        `header` or `queryParam` must be set.
      example:
        path:
          path:
            prefix: /api/
    KeyauthPolicy:
      type: object
      required:
        - keyspaces
      properties:
        keyspaces:
          type: array
          minItems: 1
          maxItems: 5
          items:
            type: string
            minLength: 1
            maxLength: 256
          description: >-
            Keyspaces to verify keys against, referenced by id. All keyspaces
            must

            belong to your workspace.
        locations:
          type: array
          items:
            $ref: '#/components/schemas/KeyLocation'
          description: >-
            Where to look for the key on incoming requests, tried in order.
            Defaults

            to the `Authorization Bearer` header when omitted.
        permissionQuery:
          type: string
          maxLength: 1000
          description: |-
            Optional permission query the verified key must satisfy, e.g.
            `documents.read AND documents.write`.
        ratelimits:
          type: array
          maxItems: 10
          items:
            $ref: '#/components/schemas/KeyRatelimit'
          description: Rate limits applied during key verification.
      additionalProperties: false
      description: Verifies Unkey API keys on matching requests.
      example:
        keyspaces:
          - ks_1234abcd
    RatelimitPolicy:
      type: object
      required:
        - limit
        - windowMs
        - identifier
      properties:
        limit:
          type: integer
          format: int64
          minimum: 1
          description: Maximum number of requests per window.
        windowMs:
          type: integer
          format: int64
          minimum: 1
          description: Window duration in milliseconds.
        identifier:
          $ref: '#/components/schemas/RatelimitIdentifier'
      additionalProperties: false
      description: Rate limits matching requests.
      example:
        limit: 100
        windowMs: 60000
        identifier:
          remoteIp: {}
    FirewallPolicy:
      type: object
      required:
        - action
      properties:
        action:
          type: string
          enum:
            - ACTION_DENY
          description: What to do with matching requests.
      additionalProperties: false
      description: Blocks matching requests.
      example:
        action: ACTION_DENY
    OpenapiPolicy:
      type: object
      additionalProperties: false
      description: >-
        Validates matching requests against the app's uploaded OpenAPI spec. Has
        no

        configuration of its own. If no spec has been uploaded for the
        deployment,

        the policy is a no-op and requests pass through unvalidated.
      example: {}
    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.
    EmptyResponse:
      type: object
      additionalProperties: false
      description: >-
        Empty response object by design. A successful response indicates this
        operation was successfully executed.
    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.
    PathMatch:
      type: object
      required:
        - path
      properties:
        path:
          $ref: '#/components/schemas/StringMatch'
      additionalProperties: false
      description: Matches on the request path.
    MethodMatch:
      type: object
      required:
        - methods
      properties:
        methods:
          type: array
          minItems: 1
          items:
            type: string
            enum:
              - GET
              - POST
              - PUT
              - PATCH
              - DELETE
              - HEAD
              - OPTIONS
      additionalProperties: false
      description: Matches when the request method is one of the listed methods.
    FieldMatch:
      type: object
      required:
        - name
      properties:
        name:
          type: string
          minLength: 1
          maxLength: 256
        present:
          type: boolean
          enum:
            - true
          description: Matches when the field is present, regardless of value.
        value:
          $ref: '#/components/schemas/StringMatch'
      additionalProperties: false
      description: >-
        Matches a named request field (header or query parameter). Exactly one
        of

        `present` or `value` must be set.
    KeyLocation:
      type: object
      properties:
        bearer:
          $ref: '#/components/schemas/BearerTokenLocation'
        header:
          $ref: '#/components/schemas/HeaderKeyLocation'
        queryParam:
          $ref: '#/components/schemas/QueryParamKeyLocation'
      additionalProperties: false
      description: |-
        Where to look for the API key on incoming requests. Exactly one of
        `bearer`, `header` or `queryParam` must be set.
      example:
        bearer: {}
    KeyRatelimit:
      type: object
      required:
        - name
      properties:
        name:
          type: string
          minLength: 1
          maxLength: 256
          description: >-
            Name of a rate limit configured on the key or its identity, or the
            name

            of the inline override defined by `limit` and `duration`.
        limit:
          type: integer
          format: int64
          minimum: 1
          description: >-
            Inline override: maximum number of operations per window. Must be
            set

            together with `duration`.
        duration:
          type: integer
          format: int64
          minimum: 1
          description: >-
            Inline override: window duration in milliseconds. Must be set
            together

            with `limit`.
        cost:
          type: integer
          format: int64
          minimum: 1
          description: Cost charged against the limit per request. Defaults to 1.
      additionalProperties: false
      description: |-
        A rate limit applied during key verification. `limit` and `duration`
        must be set together or both omitted; a partial pair is rejected.
      example:
        name: requests
        limit: 100
        duration: 60000
    RatelimitIdentifier:
      type: object
      properties:
        remoteIp:
          $ref: '#/components/schemas/RemoteIpKey'
        header:
          $ref: '#/components/schemas/HeaderKey'
        authenticatedSubject:
          $ref: '#/components/schemas/AuthenticatedSubjectKey'
        path:
          $ref: '#/components/schemas/PathKey'
        principalField:
          $ref: '#/components/schemas/PrincipalFieldKey'
      additionalProperties: false
      description: >-
        How requests are grouped for rate limiting. Exactly one of `remoteIp`,

        `header`, `authenticatedSubject`, `path` or `principalField` must be
        set.
      example:
        remoteIp: {}
    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.
    StringMatch:
      type: object
      properties:
        exact:
          type: string
          minLength: 1
          maxLength: 1024
          description: Matches when the input equals this value.
        prefix:
          type: string
          minLength: 1
          maxLength: 1024
          description: Matches when the input starts with this value.
        regex:
          type: string
          minLength: 1
          maxLength: 1024
          description: >-
            Matches when the input satisfies this RE2 regular expression.
            Invalid

            patterns are rejected when the policy is created.
        ignoreCase:
          type: boolean
          description: Compare case-insensitively. May accompany any match mode.
      additionalProperties: false
      description: String matcher. Exactly one of `exact`, `prefix` or `regex` must be set.
      example:
        prefix: /api/
        ignoreCase: true
    BearerTokenLocation:
      type: object
      additionalProperties: false
      description: Extract the key from the `Authorization Bearer` header.
    HeaderKeyLocation:
      type: object
      required:
        - name
      properties:
        name:
          type: string
          minLength: 1
          maxLength: 256
        stripPrefix:
          type: string
          maxLength: 256
          description: Optional prefix removed from the header value before verification.
      additionalProperties: false
      description: Extract the key from a custom header.
    QueryParamKeyLocation:
      type: object
      required:
        - name
      properties:
        name:
          type: string
          minLength: 1
          maxLength: 256
      additionalProperties: false
      description: Extract the key from a query parameter.
    RemoteIpKey:
      type: object
      additionalProperties: false
      description: Rate limit by the client's IP address.
    HeaderKey:
      type: object
      required:
        - name
      properties:
        name:
          type: string
          minLength: 1
          maxLength: 256
      additionalProperties: false
      description: Rate limit by the value of a request header.
    AuthenticatedSubjectKey:
      type: object
      additionalProperties: false
      description: Rate limit by the authenticated subject (e.g. the verified key).
    PathKey:
      type: object
      additionalProperties: false
      description: Rate limit by the request path.
    PrincipalFieldKey:
      type: object
      required:
        - path
      properties:
        path:
          type: string
          minLength: 1
          maxLength: 512
      additionalProperties: false
      description: Rate limit by a field extracted from the authenticated principal.
  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. Legacy permissions use tuple strings like
        `api.*.create_key`; resource permissions use Unkey Resource Names plus
        actions, like `unkey:v1:ws_123:keyspaces/*#create_key`.

        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

````