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

# Post email rules



## OpenAPI

````yaml /openapi.json post /email-rules
openapi: 3.1.1
info:
  title: Anima API
  version: 0.1.0
  description: >-
    The Anima API provides programmatic access to unified infrastructure for AI
    agents: create and manage agents; send and receive email; place phone calls
    and send/receive SMS and voice; store and retrieve vault credentials; manage
    agent identity; and configure webhooks for real-time events. Authenticate
    using a Bearer token or an API key passed via the X-API-Key header.
  contact:
    name: Anima Labs
    url: https://useanima.sh
    email: support@useanima.sh
  license:
    name: MIT
    url: https://opensource.org/licenses/MIT
servers:
  - url: https://api.useanima.sh/v1
    description: Production
security:
  - BearerAuth: []
  - ApiKeyAuth: []
paths:
  /email-rules:
    post:
      operationId: emailRule.create
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                direction:
                  enum:
                    - SEND
                    - RECEIVE
                  type: string
                  description: >-
                    SEND governs who this org's agents may email (enforced when
                    a send is attempted); RECEIVE governs whose mail is accepted
                    for them (enforced at ingest, before the message is stored
                    or any webhook fires). Reply-scope is not implemented.
                action:
                  enum:
                    - ALLOW
                    - BLOCK
                  type: string
                  description: >-
                    BLOCK refuses the matching address. ALLOW does two things:
                    it carves an exception out of a broader BLOCK, AND it
                    switches that scope+direction into allow-list mode — once
                    any ALLOW rule exists, addresses it does not cover are
                    refused. Adding one ALLOW rule therefore restricts far more
                    than it permits.
                patternType:
                  enum:
                    - ADDRESS
                    - DOMAIN
                  type: string
                  description: >-
                    ADDRESS matches one exact address. DOMAIN matches the domain
                    and its subdomains ('example.com' covers
                    'a@mail.example.com' but never 'a@notexample.com'). ADDRESS
                    beats DOMAIN when both match.
                pattern:
                  type: string
                  minLength: 1
                  maxLength: 320
                  description: >-
                    The address or domain this rule matches. Normalized to
                    lowercase. Validated against patternType.
                agentId:
                  anyOf:
                    - type: string
                      pattern: ^[cC][^\s-]{8,}$
                    - type: 'null'
                  description: >-
                    Scope the rule to one agent. Omit or null for an org-wide
                    rule. An agent's own rules take precedence over org-wide
                    rules — including its allow-list, which does NOT inherit the
                    org's.
                note:
                  anyOf:
                    - type: string
                      maxLength: 500
                    - type: 'null'
                  description: >-
                    Optional operator note ('known phisher', 'competitor').
                    Surfaced in the error a blocked send returns and in the
                    security event, so a refusal is diagnosable without opening
                    the console.
              required:
                - direction
                - action
                - patternType
                - pattern
              description: Request body for creating an email allow/block rule
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: ^[cC][^\s-]{8,}$
                    description: Unique identifier of the rule
                  direction:
                    enum:
                      - SEND
                      - RECEIVE
                    type: string
                    description: >-
                      SEND governs who this org's agents may email (enforced
                      when a send is attempted); RECEIVE governs whose mail is
                      accepted for them (enforced at ingest, before the message
                      is stored or any webhook fires). Reply-scope is not
                      implemented.
                  action:
                    enum:
                      - ALLOW
                      - BLOCK
                    type: string
                    description: >-
                      BLOCK refuses the matching address. ALLOW does two things:
                      it carves an exception out of a broader BLOCK, AND it
                      switches that scope+direction into allow-list mode — once
                      any ALLOW rule exists, addresses it does not cover are
                      refused. Adding one ALLOW rule therefore restricts far
                      more than it permits.
                  patternType:
                    enum:
                      - ADDRESS
                      - DOMAIN
                    type: string
                    description: >-
                      ADDRESS matches one exact address. DOMAIN matches the
                      domain and its subdomains ('example.com' covers
                      'a@mail.example.com' but never 'a@notexample.com').
                      ADDRESS beats DOMAIN when both match.
                  pattern:
                    type: string
                    description: >-
                      The normalized (lowercase) address or domain this rule
                      matches
                  agentId:
                    anyOf:
                      - type: string
                        pattern: ^[cC][^\s-]{8,}$
                      - type: 'null'
                    description: >-
                      The agent this rule is scoped to, or null for an org-wide
                      rule
                  note:
                    anyOf:
                      - type: string
                      - type: 'null'
                    description: Operator note, or null if not set
                  createdAt:
                    type: string
                    format: date-time
                    description: Timestamp when the rule was created
                  updatedAt:
                    type: string
                    format: date-time
                    description: Timestamp when the rule was last modified
                required:
                  - id
                  - direction
                  - action
                  - patternType
                  - pattern
                  - agentId
                  - note
                  - createdAt
                  - updatedAt
                description: An email allow/block rule
components:
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        JWT Bearer token obtained from authentication. Pass as: Authorization:
        Bearer <token>
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key
      description: 'API key for programmatic access. Pass as: X-API-Key: <your-key>'

````