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

# Generate Text with AI

> Generate text content using AI language models for captions, scripts, and summaries

Generate text content using AI language models. Use the basic default, a mini, pro, or ultra built-in, or a self-hosted model name, and get results as plain text or JSON.

```python Python theme={null}
import json
import videodb

conn = videodb.connect(api_key="your_api_key")
coll = conn.get_collection()

# Generate plain text
script_response = coll.generate_text(
    prompt="Write a 30-second commercial script for a coffee brand",
    model_name="pro",
    response_type="text"
)
script = (
    script_response
    if isinstance(script_response, str)
    else script_response.get("output", script_response)
)

print(script)

# Generate JSON response
data_response = coll.generate_text(
    prompt="Extract key points from a video summary",
    model_name="pro",
    response_type="json"
)
json_output = (
    data_response
    if isinstance(data_response, str)
    else data_response.get("output", data_response)
)
data = json.loads(json_output) if isinstance(json_output, str) else json_output

print(data)
```

```javascript Node.js theme={null}
import { connect } from 'videodb';

const conn = connect({ apiKey: 'your_api_key' });
const coll = await conn.getCollection();

// Generate plain text
const scriptResult = await coll.generateText(
    "Write a 30-second commercial script for a coffee brand",
    "pro",
    "text"
);
const script = typeof scriptResult === "string"
    ? scriptResult
    : scriptResult.output;

if (typeof script !== "string") {
    throw new Error("Expected a text response.");
}

console.log(script);

// Generate JSON response
const jsonResult = await coll.generateText(
    "Extract key points from a video summary",
    "pro",
    "json"
);

const jsonOutput = typeof jsonResult === "string"
    ? jsonResult
    : jsonResult.output;
const data = typeof jsonOutput === "string"
    ? JSON.parse(jsonOutput)
    : jsonOutput;
console.log(data);
```

> [!NOTE]
>
> * Model options: `basic` (default), `mini`, `pro`, and `ultra` built-ins, or a self-hosted model name
> * Response types: `text` for plain text or `json` for JSON-formatted output
> * `generate_text()` returns a string or object; some responses wrap the generated value in `output`. Parse JSON text when structured data is needed
> * Text generation supports `wait` and callback options
> * Useful for generating captions, scripts, summaries, and extracted data

> [card] [Generative Media Guide](https://docs.videodb.io/pages/act/generative-media/index.md)
>
> Learn about all AI generation capabilities

> [card] [Text Prompts Tutorial](https://docs.videodb.io/examples-and-tutorials/content-factory/text-prompts.md)
>
> Master text prompting strategies for generation


## OpenAPI

````yaml POST /collection/{collection_id}/generate/text/
openapi: 3.0.3
info:
  title: VideoDB Server API
  description: >
    VideoDB Server API for video, audio, and image processing with AI
    capabilities.

    This API provides comprehensive video management, search, indexing, and
    AI-powered features.
  version: 1.0.0
  contact:
    name: VideoDB Support
    url: https://videodb.io
  license:
    name: MIT
    url: https://opensource.org/licenses/MIT
servers:
  - url: https://api.videodb.io
    description: Production server
  - url: https://staging-api.videodb.io
    description: Staging server
security:
  - ApiKeyAuth: []
tags:
  - name: Authentication
    description: User authentication and API key management
  - name: Collections
    description: Collection management operations
  - name: Videos
    description: Video upload, processing, and management
  - name: Audio
    description: Audio management operations
  - name: Images
    description: Image management operations
  - name: Search
    description: Content search and indexing
  - name: AI Generation
    description: AI-powered content generation
  - name: Billing
    description: Billing and usage management
  - name: RTStream
    description: Real-time streaming operations
  - name: Utilities
    description: Utility endpoints
  - name: Meeting
    description: Meeting recording and management
  - name: Capture
    description: Capture session management for recording streams
  - name: Editor
    description: Timeline editor operations
  - name: Transcode
    description: Media transcoding operations
  - name: Assets
    description: Cross-collection asset listing
paths:
  /collection/{collection_id}/generate/text/:
    post:
      summary: Generate text using AI
      parameters:
        - name: collection_id
          in: path
          required: true
          schema:
            type: string
            example: default
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - prompt
              properties:
                prompt:
                  type: string
                  example: Summarize the content of this video
                video_id:
                  type: string
                  example: m-12345
                model_name:
                  type: string
                  example: gpt-4
                max_tokens:
                  type: integer
                  example: 500
                temperature:
                  type: number
                  example: 0.7
                callback_url:
                  type: string
                  example: https://webhook.example.com/callback
      responses:
        '200':
          description: Text generation started or completed
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/AsyncResponse'
                  - type: object
                    properties:
                      success:
                        type: boolean
                        example: true
                      data:
                        type: object
                        properties:
                          output:
                            type: string
                            example: Generated text content
      security:
        - ApiKeyAuth: []
components:
  schemas:
    AsyncResponse:
      type: object
      properties:
        success:
          type: boolean
          example: true
        status:
          type: string
          enum:
            - processing
            - done
            - failed
          example: processing
        data:
          type: object
          properties:
            id:
              type: string
              example: job-123
            output_url:
              type: string
              example: https://api.videodb.io/async-response/job-123
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-access-token
      description: API key for authentication (sk-xxx format)

````

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