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

# Generate a post (1–3 versions)

> Writes 1–3 versions of a post in your voice from a prompt, a URL, a knowledge-base item or an upload. Costs `post.generate` credits once per request; `Idempotency-Key` is required so a retry is never charged twice. When the request needs more detail, the answer is `{ status: "needs_input", question, attempt }` (free): send `answers` with the same key.

Send `Accept: text/event-stream` to stream the writing instead of waiting for the JSON answer (the request, the `Idempotency-Key` rules and the credits are the same).

Each server-sent event is unnamed; its `data` is a JSON object whose `type` is one of:
- `started` `{ generationGroupId, versions }`: writing began.
- `version_delta` `{ index, text, reset? }`: more text of version `index`; `reset: true` means that version is being rewritten, so drop what you have for it.
- `version_done` `{ index, postId, text, charCount }`: version `index` is finished and saved as post `postId`.
- `error` `{ index?, code, message }`: with `index`, that version failed and the others go on; without it, the whole request failed and was not charged.
- `done` `{ postIds, creditsLeft }`: all versions are finished.
- `result` `{ result }`: always the last event after a successful run; `result` is the same object the JSON answer returns.

A `: keep-alive` comment is sent every 15 seconds. Errors found before writing starts (validation, 402 `insufficient_credits`, 403, 409 …) are normal JSON error answers, not a stream. A `needs_input` answer, and a replay of a stored answer (`Idempotent-Replayed: true`), are a stream with only the `result` event. If you disconnect, versions already finished are kept and charged.



## OpenAPI

````yaml /api-reference/openapi.json post /api/v1/workspaces/{workspaceId}/posts/generate
openapi: 3.1.0
info:
  title: PostChamp API
  version: 1.0.0
  description: >-
    Write, schedule and manage LinkedIn posts, content styles, carousels and
    infographics from your own tools. Calls run as the key's creator with their
    current role and use the organization's credits. Lists are `{ items,
    nextCursor }`; errors are `{ error: { code, message, details } }`. Every
    response carries `X-Request-Id`, `RateLimit-Limit`, `RateLimit-Remaining`
    and `RateLimit-Reset`; a 429 adds `Retry-After`. Calls that spend credits
    require an `Idempotency-Key` header, and a replayed answer carries
    `Idempotent-Replayed: true`.
servers:
  - url: https://api.postchampai.com
security: []
tags:
  - name: Account
  - name: Posts
  - name: Scheduling
  - name: Content styles
  - name: Carousels
  - name: Infographics
  - name: Jobs
paths:
  /api/v1/workspaces/{workspaceId}/posts/generate:
    post:
      tags:
        - Posts
      summary: Generate a post (1–3 versions)
      description: >-
        Writes 1–3 versions of a post in your voice from a prompt, a URL, a
        knowledge-base item or an upload. Costs `post.generate` credits once per
        request; `Idempotency-Key` is required so a retry is never charged
        twice. When the request needs more detail, the answer is `{ status:
        "needs_input", question, attempt }` (free): send `answers` with the same
        key.


        Send `Accept: text/event-stream` to stream the writing instead of
        waiting for the JSON answer (the request, the `Idempotency-Key` rules
        and the credits are the same).


        Each server-sent event is unnamed; its `data` is a JSON object whose
        `type` is one of:

        - `started` `{ generationGroupId, versions }`: writing began.

        - `version_delta` `{ index, text, reset? }`: more text of version
        `index`; `reset: true` means that version is being rewritten, so drop
        what you have for it.

        - `version_done` `{ index, postId, text, charCount }`: version `index`
        is finished and saved as post `postId`.

        - `error` `{ index?, code, message }`: with `index`, that version failed
        and the others go on; without it, the whole request failed and was not
        charged.

        - `done` `{ postIds, creditsLeft }`: all versions are finished.

        - `result` `{ result }`: always the last event after a successful run;
        `result` is the same object the JSON answer returns.


        A `: keep-alive` comment is sent every 15 seconds. Errors found before
        writing starts (validation, 402 `insufficient_credits`, 403, 409 …) are
        normal JSON error answers, not a stream. A `needs_input` answer, and a
        replay of a stored answer (`Idempotent-Replayed: true`), are a stream
        with only the `result` event. If you disconnect, versions already
        finished are kept and charged.
      operationId: generatePost
      parameters:
        - schema:
            type: string
            format: uuid
            example: 7d2c3f4e-9a0b-4c5d-8e6f-1a2b3c4d5e6f
          required: true
          name: workspaceId
          in: path
        - schema:
            type: string
            description: >-
              Required. ≤ 100 printable characters. A retry with the same key
              and body returns the first answer and is never charged twice; the
              same key with another body → 409 `idempotency_conflict`. Answers
              are kept 24 h.
            example: order-8812-post-1
          required: true
          description: >-
            Required. ≤ 100 printable characters. A retry with the same key and
            body returns the first answer and is never charged twice; the same
            key with another body → 409 `idempotency_conflict`. Answers are kept
            24 h.
          name: idempotency-key
          in: header
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                prompt:
                  type: string
                  maxLength: 8000
                  default: ''
                contentStyleId:
                  type:
                    - string
                    - 'null'
                  minLength: 1
                  maxLength: 100
                kbItemIds:
                  type: array
                  items:
                    type: string
                    format: uuid
                  maxItems: 10
                url:
                  type: string
                  maxLength: 2048
                  format: uri
                uploadObjectId:
                  type: string
                  format: uuid
                plannedDate:
                  type: string
                  pattern: ^\d{4}-\d{2}-\d{2}$
                theme:
                  type: string
                  maxLength: 200
                answers:
                  type: array
                  items:
                    type: object
                    properties:
                      question:
                        type: string
                        maxLength: 500
                      answer:
                        type: string
                        maxLength: 2000
                    required:
                      - question
                      - answer
                  maxItems: 3
                sourceRefs:
                  type: array
                  items:
                    type: object
                    properties:
                      type:
                        type: string
                        enum:
                          - corpus_post
                          - trending_item
                          - lead_magnet
                      id:
                        type: string
                        minLength: 1
                        maxLength: 64
                    required:
                      - type
                      - id
                  maxItems: 3
                versions:
                  type: integer
                  minimum: 1
                  maximum: 3
                  default: 3
      responses:
        '200':
          description: >-
            The drafts (or a question). With `Accept: text/event-stream` the
            answer is an event stream (`text/event-stream`).
          headers:
            X-Request-Id:
              description: >-
                Id of this request. Quote it when you contact support; 5xx
                bodies repeat it as `details.requestId`.
              schema:
                type: string
                example: req_8f3a2c1e9b7d4a60
            RateLimit-Limit:
              description: >-
                Calls allowed in the current per-minute window (the window with
                the fewest calls left).
              schema:
                type: integer
                example: 120
            RateLimit-Remaining:
              description: Calls left in the current window.
              schema:
                type: integer
                example: 117
            RateLimit-Reset:
              description: Seconds until the window resets.
              schema:
                type: integer
                example: 42
            Idempotent-Replayed:
              description: >-
                Present with the value `true` when this answer is the stored
                result of an earlier request with the same `Idempotency-Key`
                (nothing was run or charged again). Absent on a first answer.
              schema:
                type: string
                enum:
                  - 'true'
          content:
            application/json:
              example:
                status: done
                generationGroupId: c4a1b2d3-6e7f-4809-a1b2-c3d4e5f60718
                postIds:
                  - 3b8f1c2a-5d4e-4f60-9a7b-0c1d2e3f4a5b
                  - 9e1d7a44-2b3c-4d5e-8f60-71829304a5b6
                posts:
                  - id: 3b8f1c2a-5d4e-4f60-9a7b-0c1d2e3f4a5b
                    status: draft
                    content: |-
                      Most teams ship features. The best ones ship decisions.

                      Three questions we ask before every launch:
                      1. Who is this for?
                      2. What will they stop doing?
                      3. How will we know it worked?
                    contentDoc:
                      type: doc
                      content:
                        - type: paragraph
                          content:
                            - type: text
                              text: >-
                                Most teams ship features. The best ones ship
                                decisions.
                        - type: paragraph
                          content:
                            - type: text
                              text: 'Three questions we ask before every launch:'
                            - type: hardBreak
                            - type: text
                              text: 1. Who is this for?
                    linkedInText: |-
                      Most teams ship features. The best ones ship decisions.

                      Three questions we ask before every launch:
                      1. Who is this for?
                      2. What will they stop doing?
                      3. How will we know it worked?
                    charCount: 181
                    origin: api
                    contentStyleId: preset:lesson_learned
                    theme: Product launches
                    plannedDate: '2026-03-12'
                    documentTitle: null
                    mediaType: text
                    scheduledAt: null
                    publishedAt: null
                    linkedinPostUrl: null
                    lastErrorCode: null
                    lastErrorMessage: null
                    lockedReason: null
                    editable: true
                    lock: null
                    generationGroupId: c4a1b2d3-6e7f-4809-a1b2-c3d4e5f60718
                    currentVersionId: f0e1d2c3-b4a5-4968-8776-5544332211ff
                    sourceRefs: []
                    createdByUserId: 0f1e2d3c-4b5a-4697-8877-665544332211
                    createdAt: '2026-03-10T09:15:30.000Z'
                    updatedAt: '2026-03-10T09:15:30.000Z'
                  - id: 9e1d7a44-2b3c-4d5e-8f60-71829304a5b6
                    status: draft
                    content: |-
                      Most teams ship features. The best ones ship decisions.

                      Three questions we ask before every launch:
                      1. Who is this for?
                      2. What will they stop doing?
                      3. How will we know it worked?
                    contentDoc:
                      type: doc
                      content:
                        - type: paragraph
                          content:
                            - type: text
                              text: >-
                                Most teams ship features. The best ones ship
                                decisions.
                        - type: paragraph
                          content:
                            - type: text
                              text: 'Three questions we ask before every launch:'
                            - type: hardBreak
                            - type: text
                              text: 1. Who is this for?
                    linkedInText: |-
                      Most teams ship features. The best ones ship decisions.

                      Three questions we ask before every launch:
                      1. Who is this for?
                      2. What will they stop doing?
                      3. How will we know it worked?
                    charCount: 181
                    origin: api
                    contentStyleId: preset:lesson_learned
                    theme: Product launches
                    plannedDate: '2026-03-12'
                    documentTitle: null
                    mediaType: text
                    scheduledAt: null
                    publishedAt: null
                    linkedinPostUrl: null
                    lastErrorCode: null
                    lastErrorMessage: null
                    lockedReason: null
                    editable: true
                    lock: null
                    generationGroupId: c4a1b2d3-6e7f-4809-a1b2-c3d4e5f60718
                    currentVersionId: f0e1d2c3-b4a5-4968-8776-5544332211ff
                    sourceRefs: []
                    createdByUserId: 0f1e2d3c-4b5a-4697-8877-665544332211
                    createdAt: '2026-03-10T09:15:30.000Z'
                    updatedAt: '2026-03-10T09:15:30.000Z'
                failed: 0
                suggestedFirstComment: https://example.com/launch-checklist
                creditsLeft: 482
                replayed: false
              schema:
                $ref: '#/components/schemas/GenerateResult'
            text/event-stream:
              example: >+
                data:
                {"type":"started","generationGroupId":"c4a1b2d3-6e7f-4809-a1b2-c3d4e5f60718","versions":2}


                data: {"type":"version_delta","index":0,"text":"Most teams ship
                features."}


                data:
                {"type":"version_done","index":0,"postId":"3b8f1c2a-5d4e-4f60-9a7b-0c1d2e3f4a5b","text":"Most
                teams ship features. The best ones ship
                decisions.","charCount":56}


                data:
                {"type":"done","postIds":["3b8f1c2a-5d4e-4f60-9a7b-0c1d2e3f4a5b","9e1d7a44-2b3c-4d5e-8f60-71829304a5b6"],"creditsLeft":482}


                data:
                {"type":"result","result":{"status":"done","generationGroupId":"c4a1b2d3-6e7f-4809-a1b2-c3d4e5f60718","postIds":["…"],"posts":["…"],"failed":0,"suggestedFirstComment":null,"creditsLeft":482,"replayed":false}}

              schema:
                type: string
                description: >-
                  Server-sent events; see the operation description for the
                  event types.
        '400':
          description: >-
            Invalid input (`validation_error`, `idempotency_key_required`,
            `linkedin_not_connected`, …).
          headers:
            X-Request-Id:
              description: >-
                Id of this request. Quote it when you contact support; 5xx
                bodies repeat it as `details.requestId`.
              schema:
                type: string
                example: req_8f3a2c1e9b7d4a60
            RateLimit-Limit:
              description: >-
                Calls allowed in the current per-minute window (the window with
                the fewest calls left).
              schema:
                type: integer
                example: 120
            RateLimit-Remaining:
              description: Calls left in the current window.
              schema:
                type: integer
                example: 117
            RateLimit-Reset:
              description: Seconds until the window resets.
              schema:
                type: integer
                example: 42
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: >-
            `api_key_required` (no `x-api-key`) or `api_key_invalid` (unknown,
            revoked or expired key, or its creator left the organization).
          headers:
            X-Request-Id:
              description: >-
                Id of this request. Quote it when you contact support; 5xx
                bodies repeat it as `details.requestId`.
              schema:
                type: string
                example: req_8f3a2c1e9b7d4a60
            RateLimit-Limit:
              description: >-
                Calls allowed in the current per-minute window (the window with
                the fewest calls left).
              schema:
                type: integer
                example: 120
            RateLimit-Remaining:
              description: Calls left in the current window.
              schema:
                type: integer
                example: 117
            RateLimit-Reset:
              description: Seconds until the window resets.
              schema:
                type: integer
                example: 42
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '402':
          description: >-
            `subscription_required` (trial ended or no live subscription) or
            `insufficient_credits`.
          headers:
            X-Request-Id:
              description: >-
                Id of this request. Quote it when you contact support; 5xx
                bodies repeat it as `details.requestId`.
              schema:
                type: string
                example: req_8f3a2c1e9b7d4a60
            RateLimit-Limit:
              description: >-
                Calls allowed in the current per-minute window (the window with
                the fewest calls left).
              schema:
                type: integer
                example: 120
            RateLimit-Remaining:
              description: Calls left in the current window.
              schema:
                type: integer
                example: 117
            RateLimit-Reset:
              description: Seconds until the window resets.
              schema:
                type: integer
                example: 42
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: >-
            `plan_limit` (the plan lacks `api_access`, or a daily cap was
            reached) or `forbidden` (the key's role can't do this).
          headers:
            X-Request-Id:
              description: >-
                Id of this request. Quote it when you contact support; 5xx
                bodies repeat it as `details.requestId`.
              schema:
                type: string
                example: req_8f3a2c1e9b7d4a60
            RateLimit-Limit:
              description: >-
                Calls allowed in the current per-minute window (the window with
                the fewest calls left).
              schema:
                type: integer
                example: 120
            RateLimit-Remaining:
              description: Calls left in the current window.
              schema:
                type: integer
                example: 117
            RateLimit-Reset:
              description: Seconds until the window resets.
              schema:
                type: integer
                example: 42
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: '`not_found`: the id does not exist or the key can''t reach it.'
          headers:
            X-Request-Id:
              description: >-
                Id of this request. Quote it when you contact support; 5xx
                bodies repeat it as `details.requestId`.
              schema:
                type: string
                example: req_8f3a2c1e9b7d4a60
            RateLimit-Limit:
              description: >-
                Calls allowed in the current per-minute window (the window with
                the fewest calls left).
              schema:
                type: integer
                example: 120
            RateLimit-Remaining:
              description: Calls left in the current window.
              schema:
                type: integer
                example: 117
            RateLimit-Reset:
              description: Seconds until the window resets.
              schema:
                type: integer
                example: 42
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: >-
            Conflict: `post_locked`, `idempotency_conflict`, or `conflict` with
            `details.reason` (`request_in_progress`, `already_done`,
            `item_moved`, …).
          headers:
            X-Request-Id:
              description: >-
                Id of this request. Quote it when you contact support; 5xx
                bodies repeat it as `details.requestId`.
              schema:
                type: string
                example: req_8f3a2c1e9b7d4a60
            RateLimit-Limit:
              description: >-
                Calls allowed in the current per-minute window (the window with
                the fewest calls left).
              schema:
                type: integer
                example: 120
            RateLimit-Remaining:
              description: Calls left in the current window.
              schema:
                type: integer
                example: 117
            RateLimit-Reset:
              description: Seconds until the window resets.
              schema:
                type: integer
                example: 42
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: >-
            `rate_limited`; see `Retry-After`. The body's `error.details` is `{
            retryAfterSeconds, scope? }`: `retryAfterSeconds` is the wait in
            seconds (same as the `Retry-After` header) and `scope` names the
            limit that tripped (`api_global`, `api_apiKey`,
            `api_apiKeyGenerate`, …).
          headers:
            X-Request-Id:
              description: >-
                Id of this request. Quote it when you contact support; 5xx
                bodies repeat it as `details.requestId`.
              schema:
                type: string
                example: req_8f3a2c1e9b7d4a60
            RateLimit-Limit:
              description: >-
                Calls allowed in the current per-minute window (the window with
                the fewest calls left).
              schema:
                type: integer
                example: 120
            RateLimit-Remaining:
              description: Calls left in the current window.
              schema:
                type: integer
                example: 117
            RateLimit-Reset:
              description: Seconds until the window resets.
              schema:
                type: integer
                example: 42
            Retry-After:
              description: >-
                Seconds to wait before retrying (same value as
                `error.details.retryAfterSeconds`).
              schema:
                type: integer
                example: 12
          content:
            application/json:
              example:
                error:
                  code: rate_limited
                  message: Too many requests. Try again soon.
                  details:
                    retryAfterSeconds: 12
                    scope: api_apiKey
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - apiKey: []
components:
  schemas:
    GenerateResult:
      oneOf:
        - $ref: '#/components/schemas/GenerateNeedsInput'
        - $ref: '#/components/schemas/GenerateDone'
      discriminator:
        propertyName: status
        mapping:
          needs_input: '#/components/schemas/GenerateNeedsInput'
          done: '#/components/schemas/GenerateDone'
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              example: not_found
            message:
              type: string
              example: Workspace not found.
            details: {}
          required:
            - code
            - message
      required:
        - error
      description: >-
        Every error has this shape. 5xx answers carry `details.requestId`; every
        answer has an `X-Request-Id` header.
    GenerateNeedsInput:
      type: object
      properties:
        status:
          type: string
          enum:
            - needs_input
        question:
          type: string
        attempt:
          type: integer
      required:
        - status
        - question
        - attempt
      description: >-
        Free: answer the question by sending `answers` with the same
        Idempotency-Key.
    GenerateDone:
      type: object
      properties:
        status:
          type: string
          enum:
            - done
        generationGroupId:
          type: string
        postIds:
          type: array
          items:
            type: string
        posts:
          type: array
          items:
            $ref: '#/components/schemas/Post'
        failed:
          type: integer
          description: Versions that failed (charged once when at least one succeeded).
        suggestedFirstComment:
          type:
            - string
            - 'null'
        creditsLeft:
          type:
            - number
            - 'null'
        replayed:
          type: boolean
          description: An earlier, already charged request with this key was replayed.
      required:
        - status
        - generationGroupId
        - postIds
        - posts
        - failed
        - suggestedFirstComment
        - creditsLeft
        - replayed
    Post:
      type: object
      properties:
        id:
          type: string
        status:
          type: string
          enum:
            - draft
            - pending_approval
            - approved
            - scheduled
            - publishing
            - published
            - failed
            - cancelled
        content:
          type: string
          description: Plain text (no styling).
        contentDoc:
          type: object
          properties:
            type:
              type: string
              enum:
                - doc
            content:
              type: array
              items:
                type: object
                properties:
                  type:
                    type: string
                    enum:
                      - paragraph
                  content:
                    type: array
                    items:
                      anyOf:
                        - type: object
                          properties:
                            type:
                              type: string
                              enum:
                                - text
                            text:
                              type: string
                              minLength: 1
                              maxLength: 20000
                            marks:
                              type: array
                              items:
                                type: object
                                properties:
                                  type:
                                    type: string
                                    enum:
                                      - bold
                                      - italic
                                required:
                                  - type
                              maxItems: 2
                          required:
                            - type
                            - text
                        - type: object
                          properties:
                            type:
                              type: string
                              enum:
                                - hardBreak
                          required:
                            - type
                    maxItems: 3000
                required:
                  - type
              maxItems: 3000
          required:
            - type
            - content
        linkedInText:
          type: string
          description: What LinkedIn will show (styled Unicode).
        charCount:
          type: integer
        origin:
          type: string
        contentStyleId:
          type:
            - string
            - 'null'
        theme:
          type:
            - string
            - 'null'
        plannedDate:
          type:
            - string
            - 'null'
        documentTitle:
          type:
            - string
            - 'null'
        mediaType:
          type: string
        scheduledAt:
          type:
            - string
            - 'null'
          format: date-time
        publishedAt:
          type:
            - string
            - 'null'
          format: date-time
        linkedinPostUrl:
          type:
            - string
            - 'null'
        lastErrorCode:
          type:
            - string
            - 'null'
        lastErrorMessage:
          type:
            - string
            - 'null'
        lockedReason:
          type:
            - string
            - 'null'
        editable:
          type: boolean
          description: False when the post lock rule refuses edits; `lock` says why.
        lock:
          type:
            - string
            - 'null'
        generationGroupId:
          type:
            - string
            - 'null'
        currentVersionId:
          type:
            - string
            - 'null'
        sourceRefs:
          type: array
          items:
            type: object
            properties:
              type:
                type: string
              id:
                type: string
              url:
                type: string
            required:
              - type
        createdByUserId:
          type:
            - string
            - 'null'
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
      required:
        - id
        - status
        - content
        - contentDoc
        - linkedInText
        - charCount
        - origin
        - contentStyleId
        - theme
        - plannedDate
        - documentTitle
        - mediaType
        - scheduledAt
        - publishedAt
        - linkedinPostUrl
        - lastErrorCode
        - lastErrorMessage
        - lockedReason
        - editable
        - lock
        - generationGroupId
        - currentVersionId
        - sourceRefs
        - createdByUserId
        - createdAt
        - updatedAt
  securitySchemes:
    apiKey:
      type: apiKey
      in: header
      name: x-api-key
      description: >-
        Send your API key in the `x-api-key` header on every request.


        - Create a key in PostChamp under **Settings → API keys**. API access
        needs the Studio plan.

        - Keys start with `pc_live_`. The full key is shown **once**, when you
        create it: copy it then. Afterwards only its prefix is shown; lost keys
        are revoked and replaced.

        - Calls run as the person who created the key, with their current role,
        and spend the organization's credits.

        - Limits per key: 120 requests per minute, 20 generation calls per
        minute. Keep the key on your server, never in a browser or app.

````