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

# Generate intent-rule draft with AI

> Generate or refine intent-rule draft content with natural-language instructions and an LLM.

Generates intent-rule draft content from natural-language instructions and the workspace's current fields context. The LLM returns a draft name, description, and rule tree.

<Info>
  This endpoint supports intent rules only. It generates against the intent-rule fields context.
</Info>

<Note>
  The generated draft is not saved automatically. Persist the returned content with [Create intent rule](/en/api-reference/create-intent-rule) or [Update intent rule](/en/api-reference/update-intent-rule), using `status: "DRAFT"`.
</Note>

## Headers

<ParamField header="Authorization" type="string" required>
  Bearer token containing your Fini workspace API key. Format: `Bearer fini_...` The key needs `write` scope.
</ParamField>

<ParamField header="Content-Type" type="string" required>
  `application/json`
</ParamField>

## Body parameters

<ParamField body="instructions" type="string" required>
  Natural-language instructions describing the rule to create or the changes to make. The value cannot be empty.
</ParamField>

<ParamField body="name" type="string">
  Current rule name. Used as context when refining `currentFlowConfig`.
</ParamField>

<ParamField body="description" type="string">
  Current rule description. Used as context when refining `currentFlowConfig`.
</ParamField>

<ParamField body="currentFlowConfig" type="RuleNodeConfig">
  Existing rule tree to refine. Omit it to generate a new draft from scratch.
</ParamField>

## Response

<ResponseField name="preview" type="object">
  Generated draft content with `name`, `description`, and `flowConfig`.
</ResponseField>

## Errors

<AccordionGroup>
  <Accordion title="400 Bad Request" icon="circle-exclamation">
    `instructions` is empty, or `currentFlowConfig` is invalid.
  </Accordion>

  <Accordion title="401 Unauthorized" icon="lock">
    The API key is missing, malformed, revoked, or invalid.
  </Accordion>

  <Accordion title="403 Forbidden" icon="shield-halved">
    The API key does not include the `write` scope required for this route.
  </Accordion>

  <Accordion title="500 Internal Server Error" icon="triangle-exclamation">
    Fini could not generate the draft content.
  </Accordion>
</AccordionGroup>
