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

# Ask before acting

> The coordination decision for an intent: `allow`, `defer`, `deny` or `handoff_to`, with who holds the customer, the effect's state, the channel, the contact budget and, when the purpose needs it, the contact token. The `coordinate` scope; the `coordination` feature.



## OpenAPI

````yaml openapi/en/cell.json POST /v1/coordination/check
openapi: 3.1.0
info:
  title: Niadra data API
  version: '1'
  description: >-
    Writing, context, history, objects, identity, privacy and governance of one
    space. Every space has a stable address, with the space and the region in
    its name.
servers:
  - url: https://{space}.{region}.api.niadra.com
    variables:
      space:
        default: acme-prod
        description: The space, which comes in the source key.
      region:
        default: us-east-2
        description: The region of the space, which also comes in the key.
security: []
paths:
  /v1/coordination/check:
    post:
      tags:
        - coordination
      summary: Ask before acting
      description: >-
        Asks whether the agent may act now, before it acts. The producer
        evaluates in order and stops at the first that decides: the effect key
        (done, in flight or ambiguous denies), a suppression of the purpose, a
        holder whose claim does not allow the intent, another holder's lock on
        the task, an exhausted or paced budget, the quiet hours. Only then the
        budget is spent and, for a purpose that needs one, the contact token is
        issued. A message the customer sent is never denied. With `effect_key`,
        an `allow` whose `effect.state` is `none` also reserved the effect: act,
        then declare how it ended.


        **Authentication.** Source key: `Authorization: Bearer nia_sk_...`.
        Required scope: `coordinate`. It answers only in a space with the
        `coordination` feature on (the `features` document); in a space without
        it, 404.
      operationId: check_v1_coordination_check_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CheckRequest'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CheckResult'
          description: >-
            The decision, valid for `valid_for_s` seconds; a caller that acts
            later asks again.
        '422':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
          description: The request does not match the contract.
      security:
        - sourceKey: []
      x-codeSamples:
        - lang: python
          label: Python
          source: >-
            # Ask before an outbound contact; with Niadra out of reach the
            purpose decides (marketing waits)

            decision = conversation.check("proposal_followup",
            purpose="marketing", channel="whatsapp")

            if decision.decision == "allow":
                gateway.send(message, token=decision.contact_token)
                conversation.declare.contact_made(decision, purpose="marketing", channel="whatsapp")
        - lang: typescript
          label: TypeScript
          source: >-
            // Ask before an outbound contact; with Niadra out of reach the
            purpose decides (marketing waits)

            const decision = await convo.check("proposal_followup", { purpose:
            "marketing", channel: "whatsapp" });

            if (decision.decision === "allow") {
              await gateway.send(message, { token: decision.contact_token });
              convo.declare.contactMade(decision, { purpose: "marketing", channel: "whatsapp" });
            }
components:
  schemas:
    CheckRequest:
      additionalProperties: false
      description: >-
        What an agent is about to do. Without a subject there is no budget,
        suppression or owner to consult:

        such a check only asks about the effect key.
      properties:
        agent:
          maxLength: 256
          minLength: 1
          title: Agent
          type: string
        channel:
          anyOf:
            - pattern: ^[a-z][a-z0-9_]{0,39}$
              type: string
            - type: 'null'
          title: Channel
        destination_hash:
          anyOf:
            - pattern: ^[A-Za-z0-9_-]{43}$
              type: string
            - type: 'null'
          description: >-
            The token's `rcpt`, computed by a caller that holds the gateway's
            key, when the destination is not the subject's handle.
          title: Destination Hash
        direction:
          enum:
            - inbound
            - outbound
          title: Direction
          type: string
        effect_key:
          anyOf:
            - maxLength: 512
              minLength: 1
              type: string
            - type: 'null'
          description: The business fact's key; reserved atomically when nothing holds it.
          title: Effect Key
        effect_kind:
          $ref: '#/components/schemas/EffectKind'
          default: delivery
        gateway_id:
          anyOf:
            - pattern: ^[a-z][a-z0-9_]{0,39}$
              type: string
            - type: 'null'
          title: Gateway Id
        intent:
          pattern: ^[a-z][a-z0-9_]{0,39}$
          title: Intent
          type: string
        object:
          anyOf:
            - $ref: '#/components/schemas/ObjectRef'
            - type: 'null'
        purpose:
          pattern: ^[a-z][a-z0-9_]{0,39}$
          title: Purpose
          type: string
        subject:
          anyOf:
            - $ref: '#/components/schemas/Handle'
            - type: 'null'
        task:
          anyOf:
            - pattern: ^[a-z][a-z0-9_]{0,39}$
              type: string
            - type: 'null'
          title: Task
      required:
        - agent
        - intent
        - direction
        - purpose
      title: CheckRequest
      type: object
    CheckResult:
      additionalProperties: false
      description: >-
        The coordination decision. `reasons` are codes (the coordination spec,
        4); `holder` is who to hand

        off to with `handoff_to`. `contact_token` comes only with an allowed
        outbound contact of a purpose that

        needs one.
      properties:
        channel:
          anyOf:
            - $ref: '#/components/schemas/ChannelState'
            - type: 'null'
        commitments_active:
          items:
            $ref: '#/components/schemas/CommitmentRef'
          title: Commitments Active
          type: array
        contact_budget:
          additionalProperties:
            $ref: '#/components/schemas/ContactBudget'
          title: Contact Budget
          type: object
        contact_token:
          anyOf:
            - maxLength: 1024
              pattern: ^nct1\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]{86}$
              type: string
            - type: 'null'
          title: Contact Token
        decision:
          enum:
            - allow
            - defer
            - deny
            - handoff_to
          title: Decision
          type: string
        decision_id:
          format: uuid
          title: Decision Id
          type: string
        effect:
          anyOf:
            - $ref: '#/components/schemas/EffectStatus'
            - type: 'null'
        holder:
          anyOf:
            - maxLength: 256
              minLength: 1
              type: string
            - type: 'null'
          title: Holder
        locks:
          items:
            $ref: '#/components/schemas/Lock'
          title: Locks
          type: array
        owner:
          anyOf:
            - $ref: '#/components/schemas/Owner'
            - type: 'null'
        promises_open:
          items:
            $ref: '#/components/schemas/PromiseRef'
          title: Promises Open
          type: array
        reasons:
          items:
            maxLength: 256
            minLength: 1
            type: string
          title: Reasons
          type: array
        suppressions:
          items:
            pattern: ^[a-z][a-z0-9_]{0,39}$
            type: string
          title: Suppressions
          type: array
        valid_for_s:
          minimum: 0
          title: Valid For S
          type: integer
      required:
        - decision
        - decision_id
        - valid_for_s
      title: CheckResult
      type: object
    Problem:
      additionalProperties: false
      description: RFC 9457 problem details; `code` comes from the versioned error catalog.
      properties:
        code:
          title: Code
          type: string
        detail:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          title: Detail
        request_id:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          title: Request Id
        status:
          title: Status
          type: integer
        title:
          title: Title
          type: string
        type:
          default: about:blank
          title: Type
          type: string
      required:
        - title
        - status
        - code
      title: Problem
      type: object
    EffectKind:
      enum:
        - delivery
        - document
        - notice
        - filing
        - paid_call
        - external_action
      title: EffectKind
      type: string
    ObjectRef:
      additionalProperties: false
      description: >-
        A business object in a system of record, e.g. `invoice` / `erp` /
        `0823`.
      properties:
        id:
          maxLength: 512
          minLength: 1
          title: Id
          type: string
          description: The id in that system.
        namespace:
          maxLength: 256
          minLength: 1
          title: Namespace
          type: string
          description: The system it lives in, such as `erp`.
        type:
          maxLength: 256
          minLength: 1
          title: Type
          type: string
          description: Object type, such as `invoice`, `order` or `ticket`.
      required:
        - type
        - namespace
        - id
      title: ObjectRef
      type: object
    Handle:
      additionalProperties: false
      description: >-
        An identifier of a subject in some channel or system: a phone, an
        e-mail, a CRM id.
      properties:
        scope:
          anyOf:
            - maxLength: 256
              minLength: 1
              type: string
            - type: 'null'
          description: >-
            Namespace for scoped identifiers: the WhatsApp Business account for
            `wa_bsuid`, the system for `system_id`, the country for
            `gov_id_hmac`.
          title: Scope
        subject_kind:
          anyOf:
            - $ref: '#/components/schemas/SubjectKind'
            - type: 'null'
          description: Defaults to `person`, except for organization-only handle types.
        type:
          $ref: '#/components/schemas/HandleType'
        value:
          maxLength: 320
          minLength: 1
          title: Value
          type: string
          description: >-
            The identifier. Normalized on the server: E.164 for phones,
            lowercase for e-mail.
      required:
        - type
        - value
      title: Handle
      type: object
    ChannelState:
      additionalProperties: false
      properties:
        free_form_until:
          anyOf:
            - format: date-time
              type: string
            - type: 'null'
          title: Free Form Until
        quiet_until:
          anyOf:
            - format: date-time
              type: string
            - type: 'null'
          title: Quiet Until
        template_required:
          default: false
          title: Template Required
          type: boolean
      title: ChannelState
      type: object
    CommitmentRef:
      additionalProperties: false
      properties:
        id:
          maxLength: 512
          minLength: 1
          title: Id
          type: string
        type:
          pattern: ^[a-z][a-z0-9_]{0,39}$
          title: Type
          type: string
        valid_until:
          anyOf:
            - format: date-time
              type: string
            - type: 'null'
          title: Valid Until
      required:
        - id
        - type
      title: CommitmentRef
      type: object
    ContactBudget:
      additionalProperties: false
      properties:
        next_allowed_at:
          anyOf:
            - format: date-time
              type: string
            - type: 'null'
          title: Next Allowed At
        remaining:
          title: Remaining
          type: integer
      required:
        - remaining
      title: ContactBudget
      type: object
    EffectStatus:
      additionalProperties: false
      description: >-
        `none` means nothing held the key and this check reserved it: the caller
        acts and then declares.
      properties:
        attempt:
          anyOf:
            - type: integer
            - type: 'null'
          title: Attempt
        state:
          enum:
            - none
            - in_flight
            - done
            - unknown_outcome
          title: State
          type: string
      required:
        - state
      title: EffectStatus
      type: object
    Lock:
      additionalProperties: false
      properties:
        holder:
          maxLength: 256
          minLength: 1
          title: Holder
          type: string
        kind:
          maxLength: 256
          minLength: 1
          title: Kind
          type: string
        task:
          anyOf:
            - maxLength: 256
              minLength: 1
              type: string
            - type: 'null'
          title: Task
        until:
          format: date-time
          title: Until
          type: string
      required:
        - kind
        - holder
        - until
      title: Lock
      type: object
    Owner:
      additionalProperties: false
      description: >-
        Who holds the subject or the object now: the most restrictive valid
        claim, where it came from and

        until when. `epoch` fences a release.
      properties:
        epoch:
          title: Epoch
          type: integer
        holder:
          maxLength: 256
          minLength: 1
          title: Holder
          type: string
        kind:
          $ref: '#/components/schemas/ClaimKind'
        level:
          pattern: ^[a-z][a-z0-9_]{0,39}$
          title: Level
          type: string
        since:
          format: date-time
          title: Since
          type: string
        source:
          maxLength: 256
          minLength: 1
          title: Source
          type: string
        valid_until:
          format: date-time
          title: Valid Until
          type: string
        via:
          $ref: '#/components/schemas/ClaimVia'
      required:
        - holder
        - kind
        - level
        - source
        - via
        - since
        - valid_until
        - epoch
      title: Owner
      type: object
    PromiseRef:
      additionalProperties: false
      properties:
        due:
          anyOf:
            - format: date-time
              type: string
            - type: 'null'
          title: Due
        id:
          maxLength: 512
          minLength: 1
          title: Id
          type: string
        owner:
          maxLength: 256
          minLength: 1
          title: Owner
          type: string
      required:
        - id
        - owner
      title: PromiseRef
      type: object
    SubjectKind:
      enum:
        - person
        - account
        - partner
      title: SubjectKind
      type: string
      description: >-
        A person, a customer organization (`account`) or an organization that
        takes part without being a customer (`partner`).
    HandleType:
      enum:
        - phone_e164
        - wa_id
        - wa_jid
        - wa_lid
        - wa_bsuid
        - email
        - gov_id_hmac
        - app_user_id
        - system_id
        - org_registry_hmac
        - email_domain
        - anon_id
      title: HandleType
      type: string
      description: >-
        The kind of identifier. The value is classified by its format, never by
        the field it came from.
    ClaimKind:
      enum:
        - owner
        - case
        - task_lock
      title: ClaimKind
      type: string
    ClaimVia:
      description: >-
        The three ways in: a declaration through the API, an observation mapped
        from a webhook, an observation

        the company's worker read and sent.
      enum:
        - declaration
        - mapping
        - worker
      title: ClaimVia
      type: string
  securitySchemes:
    sourceKey:
      type: http
      scheme: bearer
      description: nia_sk_...

````