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

# Create a network policy.

> Create an S2 network policy that restricts access tokens to CIDR blocks or AWS VPC endpoints.

> [card] [Network policy concepts](https://s2.dev/docs/concepts/network-policies.md)
>
> Review how rules are evaluated, how tokens are bound, and how to debug denied requests.

> [!NOTE]
>
> Policies are immutable. To allow different networks, create a new policy and issue tokens with it.


## OpenAPI

````yaml post /network-policies
openapi: 3.1.0
info:
  title: S2, the durable streams API
  description: Streams as a cloud storage primitive.
  termsOfService: https://s2.dev/terms
  contact:
    email: support@s2.dev
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://a.s2.dev/v1
security:
  - access_token: []
tags:
  - name: metrics
    description: Usage metrics and data.
  - name: basins
    description: Manage basins
  - name: access-tokens
    description: Manage access tokens
  - name: network-policies
    description: Manage network policies
  - name: locations
    description: Manage locations
  - name: streams
    description: Manage streams
  - name: records
    description: Manage records
paths:
  /network-policies:
    post:
      tags:
        - network-policies
      summary: Create a network policy.
      operationId: create_network_policy
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateNetworkPolicyRequest'
        required: true
      responses:
        '201':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NetworkPolicyInfo'
        '400':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorInfo'
        '403':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorInfo'
        '408':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorInfo'
        '409':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorInfo'
components:
  schemas:
    CreateNetworkPolicyRequest:
      type: object
      required:
        - slug
        - policy
      properties:
        policy:
          $ref: '#/components/schemas/NetworkPolicy'
          description: >-
            The restriction. Policies are immutable; create a new one to change
            it.
        slug:
          $ref: '#/components/schemas/NetworkPolicySlugStr'
          description: >-
            Slug, unique to the account. Up to 96 characters of letters, digits,
            `-` and `_`.
    NetworkPolicyInfo:
      type: object
      required:
        - id
        - slug
        - created_at
        - policy
      properties:
        created_at:
          type: string
          format: date-time
          description: Creation time in RFC 3339 format.
        id:
          $ref: '#/components/schemas/NetworkPolicyRef'
          description: Full reference, `<slug>.<nonce>`, which access tokens are bound to.
        policy:
          $ref: '#/components/schemas/NetworkPolicy'
          description: The restriction.
        slug:
          $ref: '#/components/schemas/NetworkPolicySlugStr'
          description: Slug chosen at creation.
    ErrorInfo:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: string
        message:
          type: string
    NetworkPolicy:
      type: object
      description: >-
        What a token may be used from, per path. At least one of `public_net`
        and `private_net` must

        be set.
      properties:
        private_net:
          oneOf:
            - type: 'null'
            - $ref: '#/components/schemas/PrivateNetPolicy'
              description: >-
                Governs requests arriving through a private network.

                When omitted, the token cannot be used through a private
                network.
        public_net:
          oneOf:
            - type: 'null'
            - $ref: '#/components/schemas/PublicNetPolicy'
              description: |-
                Governs requests arriving over the public path.
                When omitted, the token cannot be used over the public path.
    NetworkPolicySlugStr:
      type: string
      maxLength: 96
      minLength: 1
    NetworkPolicyRef:
      type: string
      description: Network policy reference, `<slug>.<nonce>`.
    PrivateNetPolicy:
      oneOf:
        - type: object
          description: AWS PrivateLink.
          required:
            - aws
          properties:
            aws:
              $ref: '#/components/schemas/AwsPrivateNetPolicy'
              description: AWS PrivateLink.
      description: Private networks a token may be used through. Exactly one kind applies.
    PublicNetPolicy:
      oneOf:
        - type: object
          description: Source addresses that may use the token. Between 1 and 32.
          required:
            - cidrs
          properties:
            cidrs:
              type: array
              items:
                $ref: '#/components/schemas/Cidr'
              description: Source addresses that may use the token. Between 1 and 32.
      description: >-
        What a token may be used from over the public path. Exactly one kind
        applies.
    AwsPrivateNetPolicy:
      type: object
      required:
        - vpce_ids
      properties:
        vpce_ids:
          type: array
          items:
            $ref: '#/components/schemas/VpcEndpointId'
          description: AWS VPC endpoint IDs through which the token may be used.
          maxItems: 32
          minItems: 1
    Cidr:
      type: string
      description: IP network in CIDR notation, e.g. `203.0.113.0/24`.
    VpcEndpointId:
      type: string
      description: AWS VPC endpoint ID, e.g. `vpce-0a1b2c3d4e5f67890`.
  securitySchemes:
    access_token:
      type: http
      scheme: bearer
      description: >-
        Bearer authentication header of the form `Bearer <token>`, where
        `<token>` is your access token.

````

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