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

# Generate a rule document

> Writes a rule document from a description in plain words. The route returns text
only. It does not stage, commit or sign anything. Show the document to the owner,
who reviews it and signs the commit as for a document typed by hand.

- Who may call: a caller with an EIP-4361 sign-in. The signer address counts
  against daily limits on generations. The SDK function is `generateDsl`, and
  `siweSessionMessage` builds the sign-in.
- Before: sign the session message once with `personal_sign`. You can send the
  same `siweMessage` and `signature` again until the session window of the
  deployment ends. Then the route answers `401`, and you sign again.
- Sign-in checks: the signature must recover to the address in the message. The
  message `Chain ID` must be the chain of this host. The `Issued At` must not be
  in the future and must be inside the session window. The domain must be the
  domain of the Anafi web app.
- Guarantee: a `200` body holds a document that parses and passes the type check
  of the rule language. The same request can return the same document again.

Served on `polygon`, `xlayer` and `polygon-amoy`.




## OpenAPI

````yaml /api/openapi.yaml post /api/dsl/generate
openapi: 3.1.0
info:
  title: Anafi API
  version: 0.3.0
  summary: The public HTTP API of one Anafi network.
  description: >
    The Anafi API is the HTTP surface of one Anafi network. Each network has its
    own host.

    The public TypeScript SDK `@anafi-cc/anafi-sdk` calls these routes for you,
    and it also

    builds and checks the signed and sealed payloads. You can call the routes
    directly.


    - No API key is necessary today.

    - Request and response bodies are JSON, except where an operation says
    otherwise.

    - A route that carries a confidential payload takes an HPKE-sealed envelope.
    Read
      [Sealed requests](/api-reference/sealed-requests) before you call it without the SDK.
    - Read [Introduction](/api-reference/introduction) for formats and
      [Errors](/api-reference/errors) for the error bodies.

    Browser origin: the API hosts answer CORS only for `https://app.ana.fi`
    today. A browser

    page on another origin cannot call the API directly. A server, a script, or
    your own

    same-origin proxy can call it.
servers:
  - url: https://api.polygon.ana.fi
    description: Polygon PoS (chain id 137)
  - url: https://api.xlayer.ana.fi
    description: X Layer (chain id 196)
  - url: https://api.polygon-amoy.ana.fi
    description: Polygon Amoy testnet (chain id 80002)
security: []
tags:
  - name: Accounts
    description: >-
      Find the accounts of an owner address, and deploy the 1-of-1 Safe of an
      owner.
  - name: Safe relay
    description: Submit an owner-signed Safe transaction. Anafi pays the gas.
  - name: Rules
    description: >-
      Stage a sealed rule document. The engine returns the attestation for the
      on-chain commit.
  - name: Confidential channel
    description: >-
      Read back the rule document and the account state of an account through a
      sealed channel.
  - name: Notification email
    description: Verify the email address that rule notifications go to.
  - name: Activity
    description: Read the payments that the engine made for an account.
  - name: Fees
    description: Read the fee terms of the network and the sponsorship of an account.
  - name: Payments
    description: Ask for the email receipt of a payment made on the pay page.
  - name: Rule language
    description: >-
      Read the rule language reference, and write a rule document from a
      description.
  - name: Bank payouts
    description: >
      Connect a Safe to Monerium for bank payouts in euro, and read the state of
      the

      connection and of the orders. These routes are served only on
      `polygon-amoy`

      (Monerium sandbox). The `polygon` and `xlayer` hosts answer `404`.
  - name: Status
    description: Check that the Anafi API answers.
paths:
  /api/dsl/generate:
    post:
      tags:
        - Rule language
      summary: Generate a rule document
      description: >
        Writes a rule document from a description in plain words. The route
        returns text

        only. It does not stage, commit or sign anything. Show the document to
        the owner,

        who reviews it and signs the commit as for a document typed by hand.


        - Who may call: a caller with an EIP-4361 sign-in. The signer address
        counts
          against daily limits on generations. The SDK function is `generateDsl`, and
          `siweSessionMessage` builds the sign-in.
        - Before: sign the session message once with `personal_sign`. You can
        send the
          same `siweMessage` and `signature` again until the session window of the
          deployment ends. Then the route answers `401`, and you sign again.
        - Sign-in checks: the signature must recover to the address in the
        message. The
          message `Chain ID` must be the chain of this host. The `Issued At` must not be
          in the future and must be inside the session window. The domain must be the
          domain of the Anafi web app.
        - Guarantee: a `200` body holds a document that parses and passes the
        type check
          of the rule language. The same request can return the same document again.

        Served on `polygon`, `xlayer` and `polygon-amoy`.
      operationId: generateDsl
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GenerateDslRequest'
            example:
              prompt: Buy ETH with 50 USDC every Friday at 9:00.
              aa: '0xf9836de53d455019ed985896fce8af80be66b7f9'
              now: '2026-12-03T14:05:00+01:00'
              timezone: Europe/Berlin
              siweMessage: |-
                app.ana.fi wants you to sign in with your Ethereum account:
                0x000000000000000000000000000000000000dEaD

                Sign in to Anafi to write rules from a description.

                URI: https://app.ana.fi
                Version: 1
                Chain ID: 137
                Nonce: 4f1c2a9e0b7d4c3a
                Issued At: 2026-12-03T13:05:00.000Z
              signature: >-
                0x3b6a765ede676559e0f261b5b9e339c9f36819c74a67568eb417ff4b379dbfbd4f1d2c8e7a90b3c5d6e7f8091a2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d1b
      responses:
        '200':
          description: The generated document.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GenerateDslResponse'
              example:
                yaml: |
                  rules:
                    ai_weekly_buy_eth_3f9a1c:
                      ...
        '400':
          description: >
            The input is not valid. A JSON body with `error` comes from the
            route: an empty

            `prompt`, a `prompt` longer than 500 characters, a `currentYaml`
            larger than

            8 KiB, only one of `now` and `timezone`, a `now` that is not RFC
            3339 with an

            offset, or an unknown timezone name. A plain-text body means that
            the body is

            not valid JSON.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GenerateDslErrorResponse'
              example:
                error: That description is longer than 500 characters. Shorten it.
            text/plain:
              schema:
                $ref: '#/components/schemas/PlainTextError'
        '401':
          description: >-
            The sign-in does not verify, or its session window ended. Sign a new
            session message.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GenerateDslErrorResponse'
              example:
                error: Sign in with your wallet to generate a rule.
        '413':
          $ref: '#/components/responses/BodyTooLarge'
        '415':
          $ref: '#/components/responses/MissingJsonContentType'
        '422':
          description: >
            No document came out. A JSON body with `error` comes from the route:
            the rule

            language cannot express the request (`Not supported yet: ...`), the
            document was

            too long to finish, or the document did not validate. Show `error`
            to the user.

            A plain-text body means that a JSON field has the wrong type or is
            missing.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GenerateDslErrorResponse'
              example:
                error: 'Not supported yet: limit orders on a price chart'
            text/plain:
              schema:
                $ref: '#/components/schemas/PlainTextError'
        '429':
          description: >-
            A daily limit on generations is reached. The `error` text names the
            limit. Try again the next day, or write the document by hand.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GenerateDslErrorResponse'
        '500':
          description: The route could not read its limit records. Try again later.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GenerateDslErrorResponse'
              example:
                error: Something went wrong. Try again shortly.
        '502':
          description: The model call failed. Try again later.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GenerateDslErrorResponse'
              example:
                error: Could not write that one just now. Try again shortly.
components:
  schemas:
    GenerateDslRequest:
      type: object
      required:
        - prompt
        - siweMessage
        - signature
      properties:
        prompt:
          type: string
          minLength: 1
          maxLength: 500
          description: >-
            The description of the rule, in the words of the user. At most 500
            characters after the trim of white space.
        aa:
          type: string
          description: >-
            The account that the rule is for, so that "my wallet" in the
            description resolves. Optional.
        currentYaml:
          type: string
          description: >-
            The document that the user edits now, at most 8 KiB. A document with
            text asks for an edit. An absent or blank value asks for a new
            document.
        now:
          type: string
          description: >-
            The clock of the user as RFC 3339 with an offset. Send it together
            with `timezone`. Without both, a description that needs a date is
            refused.
        timezone:
          type: string
          maxLength: 64
          description: >-
            The IANA timezone of the user, for example `Europe/Berlin`. Send it
            together with `now`.
        siweMessage:
          type: string
          description: >-
            The EIP-4361 message that the user signed, byte for byte. The route
            verifies these exact bytes.
        signature:
          type: string
          description: >-
            The 65-byte `personal_sign` signature over `siweMessage`, as `0x`
            hex.
    GenerateDslResponse:
      type: object
      required:
        - yaml
      properties:
        yaml:
          type: string
          description: The generated rule document. Nothing is committed.
    GenerateDslErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          type: string
          description: A sentence for the user. Show it as it is.
    PlainTextError:
      type: string
      description: >-
        A short English sentence. Show it or log it. Do not parse it; branch on
        the status code.
  responses:
    BodyTooLarge:
      description: >-
        The body is larger than the limit of the route. The limit is 2 MB for
        `POST /api/dsl/generate` and the bank payout routes, and 512 KiB for all
        other routes.
      content:
        text/plain:
          schema:
            $ref: '#/components/schemas/PlainTextError'
    MissingJsonContentType:
      description: 'The request has no `Content-Type: application/json` header.'
      content:
        text/plain:
          schema:
            $ref: '#/components/schemas/PlainTextError'
          example: 'Expected request with `Content-Type: application/json`'

````

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