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

# Generate speech

> <Info>This API is in beta. Endpoints, fields, and behavior may still change, so avoid depending on it in production.</Info>

Turns text into spoken audio, stores the file in the app's files and returns its URL. Billed to the app's credits at the same price as an AI gateway call.

For an estimate that generates and charges nothing, send the body you plan to generate with and add `dry_run: true`. The price depends on the model and the length, so an estimate for a different body can be off. Send an `Idempotency-Key` with each generation, and the same key when you retry it, so a retry isn't charged twice.

When the model provider fails, the same request usually fails the same way again, so try another model rather than resending it unchanged.



## OpenAPI

````yaml /developers/references/app-management/app-management-openapi.json post /api/apps/{app_id}/media/speech
openapi: 3.1.0
info:
  title: Base44 App Management API
  version: 1.0.0
servers:
  - url: https://app.base44.com
security:
  - PersonalAccessTokenAuth: []
paths:
  /api/apps/{app_id}/media/speech:
    post:
      summary: Generate speech
      description: >-
        <Info>This API is in beta. Endpoints, fields, and behavior may still
        change, so avoid depending on it in production.</Info>


        Turns text into spoken audio, stores the file in the app's files and
        returns its URL. Billed to the app's credits at the same price as an AI
        gateway call.


        For an estimate that generates and charges nothing, send the body you
        plan to generate with and add `dry_run: true`. The price depends on the
        model and the length, so an estimate for a different body can be off.
        Send an `Idempotency-Key` with each generation, and the same key when
        you retry it, so a retry isn't charged twice.


        When the model provider fails, the same request usually fails the same
        way again, so try another model rather than resending it unchanged.
      operationId: create_speech_api_apps__app_id__media_speech_post
      parameters:
        - name: app_id
          in: path
          required: true
          schema:
            type: string
            description: ID of the app to generate media for.
            title: App Id
          description: ID of the app to generate media for.
          example: 6820f3a4e7b91d003c45a1f2
        - name: Idempotency-Key
          in: header
          required: false
          schema:
            type: string
            description: >-
              One key per operation, 1 to 128 characters. A retry with the same
              key and request within 24 hours returns the first response.
            examples:
              - 7f3c9a2e-retry-1
            title: Idempotency-Key
          description: >-
            One key per operation, 1 to 128 characters. A retry with the same
            key and request within 24 hours returns the first response.
        - name: X-Active-Branch-Id
          in: header
          required: false
          schema:
            type: string
            description: >-
              ID of the branch the editor shows. Used when `branch_id` is
              omitted, for users who work on protected-main branches.
            title: X-Active-Branch-Id
          description: >-
            ID of the branch the editor shows. Used when `branch_id` is omitted,
            for users who work on protected-main branches.
          example: 68f1a2b3c4d5e6f708192a3b
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateSpeechRequest'
      responses:
        '200':
          description: The stored audio file, or an estimate for a dry run.
          content:
            application/json:
              schema:
                anyOf:
                  - $ref: '#/components/schemas/SpeechResponse'
                  - $ref: '#/components/schemas/Estimate'
                title: Response Create Speech Api Apps  App Id  Media Speech Post
              example:
                url: https://media.base44.com/files/public/6820f3a4/speech.mp3
                media_type: audio/mpeg
                usage:
                  credits: 1.5
        '400':
          description: >-
            The request can't be served (`invalid_request_error`,
            `model_not_found`), for example an option the model doesn't support.
            `details.param` names the field.
          content:
            application/json:
              examples:
                invalid_request_error:
                  summary: invalid_request_error
                  value:
                    error:
                      code: invalid_request_error
                      message: '`n` must be between 1 and 4.'
                      details:
                        param: 'n'
              schema:
                $ref: '#/components/schemas/StandardErrorEnvelope'
        '402':
          description: >-
            The app's workspace doesn't have enough credits
            (`insufficient_quota`).
          content:
            application/json:
              examples:
                insufficient_quota:
                  summary: insufficient_quota
                  value:
                    error:
                      code: insufficient_quota
                      message: Not enough credits.
                      details: {}
              schema:
                $ref: '#/components/schemas/StandardErrorEnvelope'
        '403':
          description: >-
            The workspace's AI policy turns off media generation for this app
            (`forbidden`).
          content:
            application/json:
              examples:
                forbidden:
                  summary: forbidden
                  value:
                    error:
                      code: forbidden
                      message: AI media generation is turned off for this app.
                      details: {}
              schema:
                $ref: '#/components/schemas/StandardErrorEnvelope'
        '404':
          description: >-
            The API isn't enabled for you, or the app doesn't exist or you can't
            edit it (`not_found`).
          content:
            application/json:
              examples:
                not_found:
                  summary: not_found
                  value:
                    error:
                      code: not_found
                      message: Not found.
                      details: {}
              schema:
                $ref: '#/components/schemas/StandardErrorEnvelope'
        '409':
          description: >-
            `idempotency_in_progress`: A request with this `Idempotency-Key` is
            still running, or its outcome isn't known yet.
          content:
            application/json:
              examples:
                idempotency_in_progress:
                  summary: idempotency_in_progress
                  value:
                    error:
                      code: idempotency_in_progress
                      message: >-
                        A request with this Idempotency-Key is still running.
                        Retry shortly.
                      details: {}
              schema:
                $ref: '#/components/schemas/StandardErrorEnvelope'
        '422':
          description: >-
            The request body is invalid (`detail`). `idempotency_key_reused`:
            The `Idempotency-Key` was already used with a different request.
            `invalid_request`: The `Idempotency-Key` header is empty or longer
            than 128 characters.
          content:
            application/json:
              examples:
                idempotency_key_reused:
                  summary: idempotency_key_reused
                  value:
                    error:
                      code: idempotency_key_reused
                      message: >-
                        This Idempotency-Key was already used with a different
                        request.
                      details: {}
                invalid_request:
                  summary: invalid_request
                  value:
                    error:
                      code: invalid_request
                      message: Idempotency-Key must be 1 to 128 characters.
                      details: {}
              schema:
                anyOf:
                  - $ref: '#/components/schemas/HTTPValidationError'
                  - $ref: '#/components/schemas/StandardErrorEnvelope'
        '429':
          description: >-
            Too many requests (`rate_limited`). The base limit is 30 requests
            per 60 seconds for each caller, raised by your plan's multiplier.
            Retry after the `Retry-After` seconds.
          content:
            application/json:
              examples:
                rate_limited:
                  summary: rate_limited
                  value:
                    error:
                      code: rate_limited
                      message: Rate limit exceeded.
                      details: {}
              schema:
                $ref: '#/components/schemas/StandardErrorEnvelope'
        '502':
          description: >-
            The model provider or file storage couldn't complete the request
            (`internal_error`).
          content:
            application/json:
              examples:
                internal_error:
                  summary: internal_error
                  value:
                    error:
                      code: internal_error
                      message: Internal server error
                      details: {}
              schema:
                $ref: '#/components/schemas/StandardErrorEnvelope'
        '503':
          description: >-
            Database temporarily unavailable (`database_unavailable`): the data
            cluster did not answer in time. Retry after the `Retry-After`
            seconds.
          headers:
            Retry-After:
              description: Seconds to wait before retrying.
              schema:
                type: integer
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StandardErrorEnvelope'
              examples:
                database_unavailable:
                  summary: database_unavailable
                  value:
                    error:
                      code: database_unavailable
                      message: Database temporarily unavailable, please retry
                      details: {}
      security:
        - PersonalAccessTokenAuth:
            - full_access
        - WorkspaceApiKeyAuth:
            - full_access
        - WorkspaceApiKeyBearerAuth:
            - full_access
components:
  schemas:
    CreateSpeechRequest:
      properties:
        dry_run:
          type: boolean
          title: Dry Run
          description: >-
            `true` returns a credit estimate without generating or charging;
            omit or `false` to generate
          default: false
        model:
          anyOf:
            - type: string
              maxLength: 100
            - type: 'null'
          title: Model
          description: >-
            model alias or vendor ID; omitted or `"automatic"` selects a fixed
            default, not a model chosen to satisfy requested controls
        input:
          type: string
          maxLength: 10000
          minLength: 1
          title: Input
          description: required; the spoken text, not `text` or `prompt`
          examples:
            - Welcome to the shop.
        voice:
          anyOf:
            - type: string
              maxLength: 100
            - type: 'null'
          title: Voice
          description: >-
            model-specific, case-sensitive name; omitted uses the model's
            default
        response_format:
          anyOf:
            - type: string
              maxLength: 20
            - type: 'null'
          title: Response Format
          description: >-
            audio encoding, not `"url"` or `"b64_json"`; omitted uses the
            model's default
        speed:
          anyOf:
            - type: number
            - type: 'null'
          title: Speed
          description: model-specific range; omit or use 1 for normal speed
        instructions:
          anyOf:
            - type: string
              maxLength: 4000
            - type: 'null'
          title: Instructions
          description: >-
            delivery and style guidance, supporting models only; keep it out of
            the spoken `input`
        language:
          anyOf:
            - type: string
              maxLength: 20
            - type: 'null'
          title: Language
          description: model-specific ISO-639 code; omit for automatic language handling
      additionalProperties: false
      type: object
      required:
        - input
      title: CreateSpeechRequest
    SpeechResponse:
      properties:
        url:
          type: string
          title: Url
          description: >-
            Public URL of the stored audio file. Anyone with the link can open
            it, and the link doesn't expire.
        media_type:
          type: string
          title: Media Type
          description: The audio file's media type.
          examples:
            - audio/mpeg
        usage:
          $ref: '#/components/schemas/MediaUsage'
      type: object
      required:
        - url
        - media_type
        - usage
      title: SpeechResponse
    Estimate:
      properties:
        dry_run:
          type: boolean
          const: true
          title: Dry Run
          description: 'Always `true`: nothing was generated or charged.'
        model:
          type: string
          title: Model
          description: The model that would serve the request.
          examples:
            - gpt_image_2
        usage:
          $ref: '#/components/schemas/MediaUsage'
      type: object
      required:
        - dry_run
        - model
        - usage
      title: Estimate
    StandardErrorEnvelope:
      properties:
        error:
          $ref: '#/components/schemas/StandardError'
          description: What went wrong.
      type: object
      required:
        - error
      title: StandardErrorEnvelope
      description: The error body returned in the standard envelope.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    MediaUsage:
      properties:
        credits:
          type: number
          title: Credits
          description: Credits charged to the app, or the estimate for a dry run.
          examples:
            - 4
      type: object
      required:
        - credits
      title: MediaUsage
    StandardError:
      properties:
        code:
          type: string
          title: Code
          description: >-
            Stable machine-readable cause of the failure. Match on this, not on
            `message`.
          example: not_found
        message:
          type: string
          title: Message
          description: Human-readable explanation. It isn't a stable contract.
          example: App not found
        details:
          additionalProperties: true
          type: object
          title: Details
          description: >-
            Structured context for the failure, or an empty object when there's
            none.
          example: {}
      type: object
      required:
        - code
        - message
      title: StandardError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    PersonalAccessTokenAuth:
      type: http
      scheme: bearer
      description: >-
        Personal access token, sent as `Authorization: Bearer <token>`. Each
        operation lists the permission it needs: `read_only` or `full_access`. A
        full-access token can call every operation. A read-only token can call
        only the operations that list `read_only`; anything else returns 403
        `read_only_credential_route_not_allowed`.
    WorkspaceApiKeyAuth:
      type: apiKey
      in: header
      name: api_key
      description: >-
        Workspace API key, sent as `api_key: <key>`. Each operation that accepts
        one lists what the key needs: a permission, `read_only` or
        `full_access`, like a personal access token, or a scope. A key without
        the scope gets 403 `workspace_api_key_scope_required`.
    WorkspaceApiKeyBearerAuth:
      type: http
      scheme: bearer
      description: >-
        Workspace API key, sent as `Authorization: Bearer <key>`. Accepted
        wherever `api_key` is, with the same permission.

````

## Related topics

- [Using Base44 built-in integrations](https://docs.base44.com/Integrations/built-in-integrations.md)
- [Credits](https://docs.base44.com/Account-and-billing/Credits.md)
- [Using integrations](https://docs.base44.com/Integrations/Using-integrations.md)
- [Generate music with the AI Gateway](https://docs.base44.com/developers/references/sdk/getting-started/ai-gateway-music.md)
- [Generate images with the AI Gateway](https://docs.base44.com/developers/references/sdk/getting-started/ai-gateway-images.md)


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