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

# Generate a campaign

> Runs the configured language model over a saved segment and returns a drafted campaign. Generation is a server concern: the browser never talks to the model provider. Send an `Idempotency-Key` header to make the call safe to retry: the first response is recorded against the key, a repeat returns it with `Idempotency-Replayed: true` instead of generating a second campaign, and reusing a key for a different body is rejected with `conflict`.



## OpenAPI

````yaml /reference/openapi.json post /v1/campaigns/generate
openapi: 3.1.0
info:
  title: Campaign Assistant API
  version: v1
  summary: Campaign drafting over a shared, runtime-validated contract.
  description: >-
    Every endpoint below is described by the shared contract package: the
    request and response schemas served here are the ones the web app validates
    against at runtime.


    Authentication is a bearer access token obtained from `auth.signIn`. Errors
    are always an RFC 9457 problem document. Chat replies can be streamed as
    server-sent events; see `chat.messages.stream`.
  license:
    name: UNLICENSED
    identifier: UNLICENSED
servers:
  - url: http://localhost:4000/api/v1
    description: This deployment
security:
  - bearerAuth: []
tags:
  - name: Authentication
    description: Sign-in, token rotation and sign-out.
  - name: Customers
    description: 'The customer base: records, aggregates and bulk import.'
  - name: Segments
    description: Saved audience definitions and live audience counts.
  - name: Campaigns
    description: Model-assisted campaign drafting and its review workflow.
  - name: Chat
    description: Assistant threads, including server-sent streaming of replies.
paths:
  /v1/campaigns/generate:
    post:
      tags:
        - Campaigns
      summary: Generate a campaign
      description: >-
        Runs the configured language model over a saved segment and returns a
        drafted campaign. Generation is a server concern: the browser never
        talks to the model provider. Send an `Idempotency-Key` header to make
        the call safe to retry: the first response is recorded against the key,
        a repeat returns it with `Idempotency-Replayed: true` instead of
        generating a second campaign, and reusing a key for a different body is
        rejected with `conflict`.
      operationId: campaigns.generate
      parameters:
        - name: Idempotency-Key
          in: header
          required: false
          schema:
            type: string
            minLength: 1
            maxLength: 255
            pattern: ^[\x21-\x7e]+$
          description: >-
            Makes this call safe to retry. The first response is recorded
            against the key; a repeat of the same request returns it with
            `Idempotency-Replayed: true` instead of repeating the side effect.
            Reusing a key for a different request body is rejected with
            `conflict`. Only a successful response is recorded, so a failed
            attempt stays retryable with the same key.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                objective:
                  type: string
                  minLength: 10
                  maxLength: 600
                segmentId:
                  type: string
                  minLength: 1
                channel:
                  type: string
                  enum:
                    - sms
                    - email
                    - push
                tone:
                  type: string
                  enum:
                    - professional
                    - friendly
                    - urgent
                    - promotional
                language:
                  default: en
                  type: string
                  enum:
                    - en
                    - fr
                includeDiscount:
                  default: false
                  type: boolean
              required:
                - objective
                - segmentId
                - channel
                - tone
      responses:
        '200':
          description: OK
          headers:
            x-api-version:
              $ref: '#/components/headers/ApiVersion'
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    minLength: 1
                  title:
                    type: string
                    minLength: 1
                  message:
                    type: string
                    minLength: 1
                  callToAction:
                    type: string
                    minLength: 1
                  segmentId:
                    type: string
                    minLength: 1
                  segmentName:
                    type: string
                    minLength: 1
                  channel:
                    type: string
                    enum:
                      - sms
                      - email
                      - push
                  tone:
                    type: string
                    enum:
                      - professional
                      - friendly
                      - urgent
                      - promotional
                  status:
                    type: string
                    enum:
                      - draft
                      - ready
                      - sent
                  objective:
                    type: string
                    minLength: 1
                  generatedAt:
                    type: string
                    minLength: 1
                required:
                  - id
                  - title
                  - message
                  - callToAction
                  - segmentId
                  - segmentName
                  - channel
                  - tone
                  - status
                  - objective
                  - generatedAt
                additionalProperties: false
        '400':
          description: Bad Request
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '401':
          description: Unauthorized
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '404':
          description: Not Found
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '409':
          description: Conflict
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '500':
          description: Internal Server Error
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '502':
          description: Bad Gateway
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
        '503':
          description: Service Unavailable
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
      security:
        - bearerAuth: []
components:
  headers:
    ApiVersion:
      description: The API version that answered this request.
      schema:
        type: string
        const: v1
        examples:
          - v1
  schemas:
    Problem:
      type: object
      properties:
        type:
          type: string
        title:
          type: string
        status:
          type: integer
          minimum: -9007199254740991
          maximum: 9007199254740991
        detail:
          type: string
        code:
          type: string
          enum:
            - validation_failed
            - invalid_credentials
            - unauthenticated
            - session_expired
            - forbidden
            - not_found
            - conflict
            - rate_limited
            - llm_unavailable
            - llm_error
            - internal_error
        errors:
          type: object
          propertyNames:
            type: string
          additionalProperties:
            type: array
            items:
              type: string
        traceId:
          type: string
      required:
        - type
        - title
        - status
        - detail
        - code
      additionalProperties: false
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        Access token issued by `auth.signIn`. Expires; refresh it with
        `auth.refresh`.

````

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