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

# Create Text Generator task

> High-performance text generation endpoint on the async Starlette service. Authenticates via API token (X-API-KEY + X-API-ID).

Supports two modes:
- **Sync** (`sync: true`): blocks until generation completes, returns the result directly.
- **Async** (default): returns immediately with `pending` status. Poll `GET /api/text_generator/{id}/` or use a webhook.



## OpenAPI

````yaml post /sse/text_generator/
openapi: 3.0.3
info:
  title: creatify.ai API
  version: 1.0.0
  description: API for creatify.ai
servers: []
security: []
paths:
  /sse/text_generator/:
    post:
      tags:
        - text_generator
      summary: Create Text Generator task
      description: >-
        High-performance text generation endpoint on the async Starlette
        service. Authenticates via API token (X-API-KEY + X-API-ID).


        Supports two modes:

        - **Sync** (`sync: true`): blocks until generation completes, returns
        the result directly.

        - **Async** (default): returns immediately with `pending` status. Poll
        `GET /api/text_generator/{id}/` or use a webhook.
      operationId: sse_text_generator_create
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TextGenRequest'
      responses:
        '201':
          description: Text generation result or pending task.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TextGenResponse'
        '400':
          description: Invalid request body or model not found.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
        '401':
          description: Missing or invalid API credentials.
        '402':
          description: Not enough credits.
        '429':
          description: Rate limit exceeded.
      security:
        - X-API-ID: []
          X-API-KEY: []
components:
  schemas:
    TextGenRequest:
      type: object
      properties:
        model_name:
          type: string
          description: Name of the Gemini model (e.g. gemini-2.5-flash).
          maxLength: 255
        messages:
          type: array
          items:
            $ref: '#/components/schemas/Message'
          description: List of messages with 'role' (user/model) and 'content'.
        system_instruction:
          type: string
          default: ''
          description: Optional system instruction for the model.
        config:
          allOf:
            - $ref: '#/components/schemas/TextGenConfig'
          description: Generation config parameters.
        tools:
          type: array
          items:
            $ref: '#/components/schemas/Tool'
          description: List of tools (function declarations) the model may call.
        tool_config:
          allOf:
            - $ref: '#/components/schemas/ToolConfig'
          description: Controls how the model uses the provided tools.
        webhook_url:
          type: string
          format: uri
          description: Webhook URL for async status updates.
        sync:
          type: boolean
          default: false
          description: >-
            If true, the request blocks until generation completes and returns
            the result directly. Default is false (async).
      required:
        - messages
        - model_name
    TextGenResponse:
      type: object
      properties:
        id:
          type: string
          format: uuid
          readOnly: true
        model_name:
          type: string
          readOnly: true
        messages:
          type: array
          items:
            $ref: '#/components/schemas/Message'
          readOnly: true
        system_instruction:
          type: string
          description: Optional system instruction for the model.
        config:
          allOf:
            - $ref: '#/components/schemas/TextGenConfig'
          readOnly: true
        status:
          $ref: '#/components/schemas/TextGenResponseStatusEnum'
        response_text:
          type: string
          description: Generated text response from the model.
        response_function_calls:
          type: array
          items:
            $ref: '#/components/schemas/FunctionCallPart'
          readOnly: true
        failed_reason:
          type: string
          description: Reason for failure if status is failed.
        credits_used:
          type: number
          format: double
          description: Credits consumed for this generation.
        created_at:
          type: string
          format: date-time
          readOnly: true
          title: Created date
        updated_at:
          type: string
          format: date-time
          readOnly: true
          title: Updated date
      required:
        - config
        - created_at
        - id
        - messages
        - model_name
        - response_function_calls
        - updated_at
    Message:
      type: object
      properties:
        role:
          allOf:
            - $ref: '#/components/schemas/RoleEnum'
          description: |-
            Role of the message sender: 'user' or 'model'.

            * `user` - user
            * `model` - model
        content:
          default: ''
          description: >-
            Message content. Either a plain text string, or a list of content
            parts for multimodal input. Each part is an object with 'type'
            ('text', 'image', or 'video'), and either 'text' (for text parts) or
            'data' (base64) + 'mime_type' (for image/video parts).
        function_call:
          allOf:
            - $ref: '#/components/schemas/FunctionCallPart'
          description: A function call part (role must be 'model').
        function_response:
          allOf:
            - $ref: '#/components/schemas/FunctionResponsePart'
          description: A function response part (role must be 'user').
      required:
        - role
    TextGenConfig:
      type: object
      description: Structured config serializer for OpenAPI documentation.
      properties:
        temperature:
          type: number
          format: double
          description: 'Controls randomness. Range: 0.0 - 2.0. Lower = more deterministic.'
        max_output_tokens:
          type: integer
          description: Maximum number of tokens to generate.
        top_p:
          type: number
          format: double
          description: 'Nucleus sampling threshold. Range: 0.0 - 1.0.'
        top_k:
          type: integer
          description: Top-k sampling. Only sample from top k tokens.
        presence_penalty:
          type: number
          format: double
          description: 'Penalize tokens already present in the text. Range: -2.0 - 2.0.'
        frequency_penalty:
          type: number
          format: double
          description: 'Penalize tokens by frequency. Range: -2.0 - 2.0.'
        seed:
          type: integer
          description: Random seed for deterministic generation.
        stop_sequences:
          type: array
          items:
            type: string
          description: List of strings that stop generation when encountered.
        response_mime_type:
          allOf:
            - $ref: '#/components/schemas/ResponseMimeTypeEnum'
          description: |-
            Output format: 'text/plain' or 'application/json'.

            * `text/plain` - text/plain
            * `application/json` - application/json
        response_json_schema:
          description: >-
            JSON Schema for structured output. Automatically sets
            response_mime_type to 'application/json'.
    Tool:
      type: object
      description: A tool containing one or more function declarations.
      properties:
        function_declarations:
          type: array
          items:
            $ref: '#/components/schemas/FunctionDeclaration'
          description: List of function declarations available to the model.
      required:
        - function_declarations
    ToolConfig:
      type: object
      description: Controls how the model uses the provided tools.
      properties:
        function_calling_config:
          allOf:
            - $ref: '#/components/schemas/FunctionCallingConfig'
          description: Function calling configuration.
    TextGenResponseStatusEnum:
      enum:
        - pending
        - running
        - done
        - failed
      type: string
      description: |-
        * `pending` - pending
        * `running` - running
        * `done` - done
        * `failed` - failed
    FunctionCallPart:
      type: object
      description: A function call issued by the model.
      properties:
        name:
          type: string
          description: Name of the function to call.
        args:
          type: object
          additionalProperties: {}
          description: Arguments for the function call as a JSON object.
      required:
        - name
    RoleEnum:
      enum:
        - user
        - model
      type: string
      description: |-
        * `user` - user
        * `model` - model
    FunctionResponsePart:
      type: object
      description: A function response supplied by the caller.
      properties:
        name:
          type: string
          description: Name of the function that was called.
        response:
          type: object
          additionalProperties: {}
          description: The function's return value as a JSON object.
      required:
        - name
        - response
    ResponseMimeTypeEnum:
      enum:
        - text/plain
        - application/json
      type: string
      description: |-
        * `text/plain` - text/plain
        * `application/json` - application/json
    FunctionDeclaration:
      type: object
      description: Declares a function the model may call.
      properties:
        name:
          type: string
          description: Function name.
        description:
          type: string
          default: ''
          description: Description of what the function does.
        parameters:
          description: JSON Schema describing the function's parameters.
      required:
        - name
    FunctionCallingConfig:
      type: object
      description: Controls how the model selects and calls functions.
      properties:
        mode:
          allOf:
            - $ref: '#/components/schemas/ModeEnum'
          description: |-
            Function calling mode: AUTO (default), ANY, NONE, or VALIDATED.

            * `AUTO` - AUTO
            * `ANY` - ANY
            * `NONE` - NONE
            * `VALIDATED` - VALIDATED
        allowed_function_names:
          type: array
          items:
            type: string
          description: >-
            Restrict the model to only call these functions (used with
            mode=ANY).
    ModeEnum:
      enum:
        - AUTO
        - ANY
        - NONE
        - VALIDATED
      type: string
      description: |-
        * `AUTO` - AUTO
        * `ANY` - ANY
        * `NONE` - NONE
        * `VALIDATED` - VALIDATED
  securitySchemes:
    X-API-ID:
      type: apiKey
      in: header
      name: X-API-ID
      description: API ID, from your settings page.
    X-API-KEY:
      type: apiKey
      in: header
      name: X-API-KEY
      description: API Key, from your settings page.

````