---
title: "Generate Ai Run Condition"
method: POST
path: "/enrichment/ai-formula/generate-condition"
tags: ["Enrichment"]
---

# Generate Ai Run Condition

`POST /enrichment/ai-formula/generate-condition`

## Request

- Base URL: `https://be.graph8.com/api/v1`
- URL: `https://be.graph8.com/api/v1/enrichment/ai-formula/generate-condition`
- Auth: HTTP bearer

Turn a rule in words into a run condition. SPENDS CREDITS, TOKEN-METERED.

"Only run for CEOs with no work email" becomes an expression you can put in
a config's `run_condition`, so the enrichment skips rows it should not
touch - which is how this pays for itself.

The charge is METERED ON TOKENS rather than flat: a long rule with a large
sample record costs more than a short one. Keep `sampleData` to a single
representative record.

## Headers

- `Authorization` string, nullable
- `X-Target-Org-Id` string, nullable

## Request body

- AIRunConditionRequest: Describe in words when an enrichment should run; get back an expression. The app takes a FREE DICT here, so this model takes one too rather than narrowing below it - every field is optional and unknown keys are forwarded untouched. Narrowing would refuse a body the browser accepts, which is the mirror image of the bug the strict models elsewhere in this file prevent.
  - `prompt` string, nullable: The rule in plain words.
  - `fields` string[], nullable: Fields the expression may use.
  - `sampleData` object, nullable: One sample record.
  - `entityType` string, nullable: 'contacts' or 'companies'.

## Response `200`

Successful Response

- ApiResponseEnrichmentPayload
  - `data` EnrichmentPayload, required: One enrichment object, open-shaped. Open on purpose: a workbench column set is defined by the CUSTOMER at runtime, and the enrichment result shapes grow with every provider added. Pinning them would drop whatever a provider returned that this contract had not caught up on, which on an enrichment surface is the data the customer paid for.
  - `pagination` PaginationMeta
    - `page` integer, required: Current page number (1-indexed)
    - `limit` integer, required: Items per page
    - `total` integer, required: Total number of items
    - `has_next` boolean, required: Whether there are more pages
    - `next_cursor` string, nullable: Opaque cursor for the next page; null when there are no more items. Pass it back as the `cursor` query param to fetch the following page without computing page numbers.
    - `total_available` integer, nullable: Search endpoints only: how many records really match, when known. Can be larger than `total`, which is capped at the 10,000 results that can be paged. For company search this is a distinct-company estimate. Null when unknown; absent outside search.
    - `total_is_lower_bound` boolean, nullable: Search endpoints only: true when more records match than `total` shows (the result set is larger than the 10,000 results that can be paged). Absent outside search.
    - `notes` string[], nullable: Search endpoints only: plain-language notes about the result, e.g. that more records match than can be paged, or that a reversed `between` range was put in order.

## Other responses

- `422`: Validation Error

---

[API](https://skmtc.dev/graph8/apis/graph8-developer-api.md) · [All operations](https://skmtc.dev/graph8/apis/graph8-developer-api/llms.txt) · [OpenAPI document](https://skmtc.dev/graph8/apis/graph8-developer-api/revisions/2e7cfa0ca921?raw)
