---
title: "Text Generator (Streaming)"
method: POST
path: "/sse/text_generator/stream/"
tags: ["text_generator"]
---

# Text Generator (Streaming)

`POST /sse/text_generator/stream/`

Streaming text generation endpoint. Authenticates via API token (X-API-KEY + X-API-ID), validates the request, checks credits, calls the Gemini streaming API, and returns an SSE stream of Gemini-native response chunks on the same connection.

The final SSE chunk includes a `creatify` object with the generation `id` and `credits_used`.

## Request body

- TextGenRequest
  - `model_name` string, required — Name of the Gemini model (e.g. gemini-2.5-flash).
  - `messages` Message[], required — List of messages with 'role' (user/model) and 'content'.
    - `role` 'user' | 'model', required — * `user` - user * `model` - model
    - `content` string — 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` FunctionCallPart — A function call issued by the model.
      - `name` string, required — Name of the function to call.
      - `args` object — Arguments for the function call as a JSON object.
    - `function_response` FunctionResponsePart — A function response supplied by the caller.
      - `name` string, required — Name of the function that was called.
      - `response` object, required — The function's return value as a JSON object.
  - `system_instruction` string — Optional system instruction for the model.
  - `config` TextGenConfig — Structured config serializer for OpenAPI documentation.
    - `temperature` number, double — Controls randomness. Range: 0.0 - 2.0. Lower = more deterministic.
    - `max_output_tokens` integer — Maximum number of tokens to generate.
    - `top_p` number, double — Nucleus sampling threshold. Range: 0.0 - 1.0.
    - `top_k` integer — Top-k sampling. Only sample from top k tokens.
    - `presence_penalty` number, double — Penalize tokens already present in the text. Range: -2.0 - 2.0.
    - `frequency_penalty` number, double — Penalize tokens by frequency. Range: -2.0 - 2.0.
    - `seed` integer — Random seed for deterministic generation.
    - `stop_sequences` string[] — List of strings that stop generation when encountered.
    - `response_mime_type` 'text/plain' | 'application/json' — * `text/plain` - text/plain * `application/json` - application/json
    - `response_json_schema` unknown
  - `tools` Tool[] — List of tools (function declarations) the model may call.
    - `function_declarations` FunctionDeclaration[], required — List of function declarations available to the model.
      - `name` string, required — Function name.
      - `description` string — Description of what the function does.
      - `parameters` unknown
  - `tool_config` ToolConfig — Controls how the model uses the provided tools.
    - `function_calling_config` FunctionCallingConfig — Controls how the model selects and calls functions.
      - `mode` 'AUTO' | 'ANY' | 'NONE' | 'VALIDATED' — * `AUTO` - AUTO * `ANY` - ANY * `NONE` - NONE * `VALIDATED` - VALIDATED
      - `allowed_function_names` string[] — Restrict the model to only call these functions (used with mode=ANY).
  - `webhook_url` string, uri — Webhook URL for async status updates.
  - `sync` boolean — If true, the request blocks until generation completes and returns the result directly. Default is false (async).

## Response `200`

SSE stream of Gemini response chunks. Content-Type: text/event-stream.

## Other responses

- `400` — Invalid request body or model not found.
- `401` — Missing or invalid API credentials.
- `402` — Not enough credits.
- `429` — Rate limit exceeded.

---

[API](https://skmtc.dev/creatify/apis/creatify-ai-api.md) · [All operations](https://skmtc.dev/creatify/apis/creatify-ai-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/creatify/creatify-ai-api/revisions/7ca3bf8077ba/schema)
