---
title: "Create a survey draft payload with AI"
method: POST
path: "/api/v3/surveys/generate"
tags: ["V3 Surveys"]
---

# Create a survey draft payload with AI

`POST /api/v3/surveys/generate`

Creates a strict v3 `POST /api/v3/surveys` create payload from a creator prompt and returns
validation metadata. This endpoint is single-purpose: it does **not** persist the survey.
Clients should validate the returned payload with `/api/v3/surveys/validate` or use the
embedded validation metadata, then create the draft through `POST /api/v3/surveys`.

The generated payload always sets `status: draft`. Both `type: link` and `type: app` are
supported; for `app`, the payload includes a default `distribution` (display once, no triggers,
no targeting) that you finish configuring in the editor or via the create request.

Prompt privacy: prompt text is sent to the configured AI provider to create the payload, but
this endpoint does not store prompts and server logs should use request ids and failure
categories instead of raw prompt content.

## Request body

- GenerateSurveyRequest — AI survey creation request. `prompt` is used only to create a draft payload; it is not persisted by this endpoint. The generated payload is validated and returned to the caller for a separate create request.
  - `workspaceId` string, cuid2, required — Workspace where the AI-created survey draft would be created. Requires read/write access.
  - `prompt` string, required — Natural-language survey goal and audience. Prompts with fewer than 24 characters or fewer than four whitespace-separated words return prompt feedback before any AI provider call.
  - `type` 'link' | 'app' — Survey type to generate. The AI generates the survey content (blocks/questions) for both types; for `app` it additionally seeds a default `distribution` (display once, no triggers, no targeting) that you finish configuring before publishing.
  - `language` 'de-DE' | 'en-US' | 'es-ES' | 'fr-FR' | 'hu-HU' | 'ja-JP' | 'nl-NL' | 'pt-BR' | 'pt-PT' | 'ro-RO' | 'ru-RU' | 'sv-SE' | 'tr-TR' | 'zh-Hans-CN' | 'zh-Hant-TW' — Supported app locale code that AI survey creation can return.

## Response `200`

Survey create payload generated successfully. The survey has not been created yet.

- object
  - `data` GenerateSurveyResult, required
    - `language` 'de-DE' | 'en-US' | 'es-ES' | 'fr-FR' | 'hu-HU' | 'ja-JP' | 'nl-NL' | 'pt-BR' | 'pt-PT' | 'ro-RO' | 'ru-RU' | 'sv-SE' | 'tr-TR' | 'zh-Hans-CN' | 'zh-Hant-TW', required — Supported app locale code that AI survey creation can return.
    - `payload` CreateSurveyRequest, required — Strict v3 survey creation document. This endpoint accepts survey structure only: name, metadata, languages, welcome card, blocks/elements/logic, endings, hidden fields, and variables. App surveys (`type: app`) additionally accept the `distribution` (display options + triggers) and `targeting` (contact segment filters) objects; these are rejected for `link` surveys. It rejects legacy `questions` and out-of-scope settings such as styling, follow-ups, recaptcha, single-use/email verification, slug, custom scripts, analytics fields, timestamps, and `createdBy`. Translatable fields use real locale-code maps. The map must include the canonical `defaultLanguage` key, such as `en-US`, so the server can persist the internal default translation. Locale keys must be canonical BCP 47 codes such as `de-DE`, `pt-PT`, or `zh-Hans-CN`. Non-default locale keys must be declared in `languages`; undeclared locale keys in metadata, welcome cards, blocks, or endings are rejected with `unsupported_locale`. `blocks[].id` and `variables[].id` may be omitted on create and will be generated by the server. Provide explicit cuid2 ids when other fields in the same request reference them. For normal sequential flow, omit `logicFallback`. It is only valid together with a non-empty `logic` array on the same block.
      - `workspaceId` string, cuid2, required — Workspace where the survey will be created. Requires read/write access.
      - `name` string, required
      - `type` 'link' | 'app' — Survey type. `link` surveys are distributed by URL; `app` surveys are shown in-app and configure their runtime behavior via the `distribution` and `targeting` objects. `type` is immutable after creation (it cannot be changed via PATCH).
      - `status` 'draft' | 'inProgress' | 'paused' | 'completed'
      - `metadata` SurveyMetadata — Arbitrary JSON survey context for customer- or operation-specific metadata. v3 preserves arbitrary metadata values as-is. If present, `title` and `description` are treated as translatable text maps and returned with real locale-code keys.
        - `title` TranslatableText — Multilingual text map keyed by the emitted `languages[].code` values for this survey.
        - `description` TranslatableText — Multilingual text map keyed by the emitted `languages[].code` values for this survey.
      - `defaultLanguage` string — Canonical locale code accepted by v3 survey APIs, for example `en-US`, `de-DE`, or `zh-Hans-CN`.
      - `languages` CreateSurveyLanguage[] — Optional survey language configuration. Every non-default locale used by translatable maps must be declared here; omitted languages are not inferred from map keys.
        - `code` string, required — Canonical locale code accepted by v3 survey APIs, for example `en-US`, `de-DE`, or `zh-Hans-CN`.
        - `default` boolean — Optional marker for readability; only the `defaultLanguage` entry may set this to true.
        - `enabled` boolean — Whether this language is enabled for respondent-facing delivery.
      - `welcomeCard` SurveyWelcomeCard — Optional card shown before the first survey block.
        - `enabled` boolean, required
        - `headline` TranslatableText — Multilingual text map keyed by the emitted `languages[].code` values for this survey.
        - `subheader` TranslatableText — Multilingual text map keyed by the emitted `languages[].code` values for this survey.
        - `buttonLabel` TranslatableText — Multilingual text map keyed by the emitted `languages[].code` values for this survey.
        - `fileUrl` string
        - `videoUrl` string
        - `timeToFinish` boolean
        - `showResponseCount` boolean
      - `blocks` CreateSurveyBlock[], required
        - `id` string, cuid2 — Optional stable block id. Generated when omitted.
        - `name` string, required
        - `elements` SurveyElement[], required
          - union — Survey element/question inside a block. Element ids are stable public identifiers used by logic, recall strings, response data, quotas, integrations, and analysis. `type` selects the allowed shape; unsupported fields are rejected instead of ignored.
            - SurveyOpenTextElement
              - …
            - SurveyConsentElement
              - …
            - SurveyMultipleChoiceSingleElement
              - …
            - SurveyMultipleChoiceMultiElement
              - …
            - SurveyNpsElement
              - …
            - SurveyCtaElement — If `buttonExternal` is true, `buttonUrl` and `ctaButtonLabel` are required.
              - …
            - SurveyRatingElement
              - …
            - SurveyPictureSelectionElement
              - …
            - SurveyDateElement
              - …
            - SurveyFileUploadElement
              - …
            - SurveyCalElement
              - …
            - SurveyMatrixElement
              - …
            - SurveyAddressElement
              - …
            - SurveyRankingElement
              - …
            - SurveyContactInfoElement
              - …
            - SurveyCsatElement
              - …
            - SurveyCesElement
              - …
        - `logic` SurveyBlockLogic[]
          - `id` string, cuid2, required
          - `conditions` SurveyConditionGroup, required
            - `id` string, cuid2, required
            - `connector` 'and' | 'or', required
            - `conditions` union[], required
              - …
          - `actions` SurveyLogicAction[], required
            - union — Logic action. Keep referenced ids stable: `calculate.variableId` points to a variable id, `requireAnswer.target` points to an element id, and `jumpToBlock.target` points to a block id or ending id.
              - …
        - `logicFallback` string, cuid2 — Block or ending id used when no logic condition matches. Only valid when this same block has at least one `logic` rule; omit it for normal sequential flow.
        - `buttonLabel` TranslatableText — Multilingual text map keyed by the emitted `languages[].code` values for this survey.
        - `backButtonLabel` TranslatableText — Multilingual text map keyed by the emitted `languages[].code` values for this survey.
      - `endings` SurveyEnding[]
        - union — Ending reached after the last block or a jump action. `type` selects the allowed shape; unsupported fields are rejected instead of ignored.
          - SurveyEndScreenEnding — Visual end screen displayed after survey completion.
            - `id` string, cuid2, required — Stable ending id. `jumpToBlock.target` may point to this id.
            - `type` 'endScreen', required
            - `headline` TranslatableText — Multilingual text map keyed by the emitted `languages[].code` values for this survey.
            - `subheader` TranslatableText — Multilingual text map keyed by the emitted `languages[].code` values for this survey.
            - `buttonLabel` TranslatableText — Multilingual text map keyed by the emitted `languages[].code` values for this survey.
            - `buttonLink` string
            - `imageUrl` string
            - `videoUrl` string
          - SurveyRedirectEnding — Redirects the respondent to a URL after survey completion. External redirects require the organization's external URL permission; otherwise write endpoints return `403 Forbidden`.
            - `id` string, cuid2, required — Stable ending id. `jumpToBlock.target` may point to this id.
            - `type` 'redirectToUrl', required
            - `url` string, uri, required — External redirect URL. Requires the organization's external URL permission.
            - `label` string — Optional internal label for redirect endings.
      - `hiddenFields` SurveyHiddenFields — Hidden fields, sometimes called embedded data in other survey products. Field ids are stable public identifiers and may be referenced by logic, recall, quotas, integrations, and response data. Use only letters, numbers, underscores, and hyphens; avoid spaces and reserved ids.
        - `enabled` boolean, required
        - `fieldIds` string[]
      - `variables` CreateSurveyVariable[]
        - union — Survey variable accepted by `POST /api/v3/surveys`. `id` may be omitted and will be generated by the server. Provide an explicit cuid2 id when logic in the same request needs to reference this variable.
          - CreateSurveyNumberVariable
            - `id` string, cuid2 — Optional stable variable id. Generated when omitted.
            - `name` string, required — Unique variable name. Lowercase letters, numbers, and underscores only.
            - `type` 'number', required
            - `value` number, required — Default numeric value.
          - CreateSurveyTextVariable
            - `id` string, cuid2 — Optional stable variable id. Generated when omitted.
            - `name` string, required — Unique variable name. Lowercase letters, numbers, and underscores only.
            - `type` 'text', required
            - `value` string, required — Default text value.
      - `distribution` SurveyDistribution — App-survey runtime/display settings. Only valid for `type: app`; rejected for link surveys. **Replacement semantics (destructive):** when `distribution` is provided on PATCH it fully replaces the stored object — any sub-field you omit is reset to its default, NOT preserved. In particular, omitting `triggers` removes ALL existing triggers, and omitting `displayOption` resets it to `displayOnce`. To change one setting, send the complete desired distribution. To leave distribution untouched, omit the whole `distribution` key.
        - `displayOption` 'displayOnce' | 'displayMultiple' | 'respondMultiple' | 'displaySome' — How often the survey may be shown to a contact. `displaySome` shows it up to `displayLimit` times (or until the contact responds, whichever comes first).
        - `displayPercentage` number, nullable — Independent throttle: show the survey to only this percentage of triggered contacts. Optional and valid with any `displayOption`; null/omitted means no throttle (shown to everyone).
        - `displayLimit` integer, nullable — Maximum number of times the survey is shown to a single contact. Required (must be >= 1) when `displayOption` is `displaySome`; otherwise optional.
        - `recontactDays` integer, nullable — Days to wait before showing this survey again to the same contact. Null uses the workspace default.
        - `autoClose` integer, nullable — Seconds of inactivity after which the survey widget auto-closes. Null disables auto-close.
        - `autoComplete` integer, nullable — Automatically stop collecting responses after this many completed responses. Null disables it.
        - `delay` integer — Seconds to wait after a trigger fires before showing the survey.
        - `triggers` SurveyTrigger[] — Action classes that trigger the survey. Every id must reference an existing workspace action class. On PATCH this list fully replaces the survey's triggers — omitting it (or sending `[]`) removes all existing triggers.
          - `actionClassId` string, cuid2, required — Id of an action class in the same workspace.
      - `targeting` SurveyTargeting — App-survey contact targeting. Only valid for `type: app`. `filters: []` targets everyone. Setting or changing non-empty filters requires the Contacts entitlement; otherwise create/patch returns 403. `attribute` filters reference workspace contact-attribute keys (discover them via `GET /api/v3/contact-attribute-keys`) and `segment` filters reference other segment ids — both are workspace-scoped resources you must obtain before constructing filters (an invalid key/id targets no one rather than erroring). See `SegmentFilter` for the per-`root.type` operator sets.
        - `filters` object[], required — Contact targeting filter tree. An empty array targets everyone. Each node joins the previous one via its `connector` (`and`/`or`; the first node's connector is null). A node's `resource` is either a single filter condition or a nested filter group (enabling parenthesized `and`/`or` logic).
          - `id` string, cuid2, required
          - `connector` 'and' | 'or' | 'null', nullable, required — Logical connector joining this node to the previous one. Null for the first node.
          - `resource` union, required — A single filter condition, or a nested filter group for grouped logic.
            - union — A single targeting condition. `root.type` selects the subject and determines the valid `qualifier.operator` set: `attribute` (a workspace contact-attribute key), `person` (a built-in person identifier such as `userId`/`email`), `segment` (membership in another segment), or `device`. Each variant is one member of this union; the matching member is chosen by `root.type`.
              - …
            - SegmentFilters — recursive
    - `validation` GeneratedSurveyValidationResult, required
      - `valid` boolean, required — Whether the generated create payload passed the same v3 create preparation pipeline.
      - `invalid_params` InvalidParam[], required — Repairable validation errors. Successful generate responses return an empty array.
        - `name` string, required — Dot-path to the invalid request field.
        - `reason` string, required — Human-readable repair guidance.
        - `code` 'dangling_reference' | 'duplicate_identifier' | 'duplicate_locale' | 'forbidden_identifier' | 'immutable_identifier' | 'invalid_graph' | 'invalid_locale' | 'invalid_reference' | 'missing_required_field' | 'missing_translation' | 'unsupported_field' | 'unsupported_locale' — Machine-readable validation category, when available. `invalid_graph` covers workflow graph-structure violations such as a duplicated trigger edge, an unreachable node, or a cycle.
        - `identifier` string — Identifier involved in the validation failure, when available. For language errors, this can be the normalized language code.
        - `referenceType` 'block' | 'element' | 'ending' | 'hiddenField' | 'language' | 'variable' | 'variableName' | 'recall' | 'node' | 'edge' | 'survey' | 'endingCard' — Identifier namespace involved in the validation failure. `node`, `edge`, `survey`, and `endingCard` are used by workflow validation.
        - `missingId` string — Referenced id that does not exist in the submitted survey document.
        - `firstUsedAt` string — Dot-path where a duplicate identifier was first used.
        - `conflictsWith` string — Dot-path to the existing identifier that conflicts with this field.
      - `languages` GeneratedSurveyValidationLanguage[], required — Languages that the generated create payload would connect or create.
        - `code` 'de-DE' | 'en-US' | 'es-ES' | 'fr-FR' | 'hu-HU' | 'ja-JP' | 'nl-NL' | 'pt-BR' | 'pt-PT' | 'ro-RO' | 'ru-RU' | 'sv-SE' | 'tr-TR' | 'zh-Hans-CN' | 'zh-Hant-TW', required — Supported app locale code that AI survey creation can return.
        - `default` boolean, required
        - `enabled` boolean, required

## Other responses

- `400` — Malformed body or a prompt that is too short or underspecified
- `401` — Not authenticated (no valid session or API key).
- `403` — Forbidden — no write access, workspace does not exist, AI is not in plan, or AI smart tools are disabled
- `422` — AI generated an invalid payload after schema and v3 create validation, or the generation stopped because the output token limit was reached
- `429` — Rate limit exceeded.
- `500` — Internal Server Error.
- `502` — The configured AI provider failed or could not produce a valid draft
- `503` — AI is not configured on this Formbricks instance

---

[API](https://skmtc.dev/formbricks/apis/formbricks-api-v3.md) · [All operations](https://skmtc.dev/formbricks/apis/formbricks-api-v3/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/formbricks/formbricks-api-v3/revisions/3c2c022e49d2/schema)
